mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Fixed bounding box rendering! fixed AABB collision detection (was a bit weird), misc. tweaks and fixes.
This commit is contained in:
@@ -13,6 +13,7 @@ class IMICFPS
|
||||
attr_accessor :objects, :materials, :vertices, :texures, :normals, :faces
|
||||
attr_accessor :x, :y, :z, :scale, :game_object
|
||||
attr_reader :bounding_box, :model_has_texture, :textured_material
|
||||
attr_reader :normals_buffer, :colors_buffer, :vertices_buffer
|
||||
|
||||
def initialize(file_path:, game_object: nil)
|
||||
@game_object = game_object
|
||||
@@ -31,11 +32,27 @@ class IMICFPS
|
||||
@faces = []
|
||||
@smoothing= 0
|
||||
|
||||
# Allocate buffers for future use
|
||||
@normals_buffer, @colors_buffer, @vertices_buffer = nil
|
||||
buffer = " " * 4
|
||||
glGenBuffers(1, buffer)
|
||||
@normals_buffer = buffer.unpack('L2').first
|
||||
|
||||
buffer = " " * 4
|
||||
glGenBuffers(1, buffer)
|
||||
@colors_buffer = buffer.unpack('L2').first
|
||||
|
||||
buffer = " " * 4
|
||||
glGenBuffers(1, buffer)
|
||||
@vertices_buffer = buffer.unpack('L2').first
|
||||
|
||||
@bounding_box = BoundingBox.new(0,0,0, 0,0,0)
|
||||
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
||||
parse
|
||||
puts "#{@file_path.split('/').last} took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)-start_time)/1000.0).round(2)} seconds to parse"
|
||||
|
||||
# populate_buffers
|
||||
|
||||
face_count = 0
|
||||
@objects.each {|o| face_count+=o.faces.size}
|
||||
@objects.each_with_index do |o, i|
|
||||
@@ -51,6 +68,15 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
|
||||
def populate_buffers
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer)
|
||||
glBufferData(GL_ARRAY_BUFFER, @vertices.size, @vertices.flatten.pack("f*"), GL_STATIC_DRAW)
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @vertices_buffer)
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@x, @y, @z = @game_object.x, @game_object.y, @game_object.z
|
||||
@scale = @game_object.scale
|
||||
|
||||
@@ -38,7 +38,7 @@ class IMICFPS
|
||||
|
||||
def at_same_position?
|
||||
if @x == @parent.x
|
||||
if @x == @parent.x
|
||||
if @y == @parent.y
|
||||
if @z == @parent.z
|
||||
true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user