mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Replaced Vertex struct with Vector class
This commit is contained in:
@@ -62,7 +62,7 @@ $debug = ARGV.join.include?("--debug") ? true : false
|
||||
|
||||
require_relative "lib/common_methods"
|
||||
|
||||
require_relative "lib/math/vertex"
|
||||
require_relative "lib/math/vector"
|
||||
require_relative "lib/trees/aabb_tree"
|
||||
|
||||
require_relative "lib/managers/input_mapper"
|
||||
|
||||
52
lib/math/vector.rb
Normal file
52
lib/math/vector.rb
Normal file
@@ -0,0 +1,52 @@
|
||||
class IMICFPS
|
||||
class Vector
|
||||
|
||||
attr_accessor :x, :y, :z, :weight
|
||||
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
||||
@x, @y, @z, @weight = x, y, z, weight
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
@x == other.x &&
|
||||
@y == other.y &&
|
||||
@z == other.z &&
|
||||
@weight == other.weight
|
||||
end
|
||||
|
||||
def +(other)
|
||||
@x += other.x
|
||||
@y += other.y
|
||||
@z += other.z
|
||||
@weight += other.weight
|
||||
end
|
||||
|
||||
def -(other)
|
||||
@x -= other.x
|
||||
@y -= other.y
|
||||
@z -= other.z
|
||||
@weight -= other.weight
|
||||
end
|
||||
|
||||
def *(other)
|
||||
@x *= other.x
|
||||
@y *= other.y
|
||||
@z *= other.z
|
||||
@weight *= other.weight
|
||||
end
|
||||
|
||||
def /(other)
|
||||
@x /= other.x
|
||||
@y /= other.y
|
||||
@z /= other.z
|
||||
@weight /= other.weight
|
||||
end
|
||||
|
||||
def to_a
|
||||
[@x, @y, @z, @weight]
|
||||
end
|
||||
|
||||
def to_s
|
||||
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class IMICFPS
|
||||
Vector = Struct.new(:x, :y, :z, :weight)
|
||||
end
|
||||
@@ -94,8 +94,8 @@ class IMICFPS
|
||||
# if $debug && @entity
|
||||
# glBegin(GL_LINES)
|
||||
# glColor3f(1,0,0)
|
||||
# glVector3f(@x, @y, @z)
|
||||
# glVector3f(@entity.x, @entity.y, @entity.z)
|
||||
# glVertex3f(@x, @y, @z)
|
||||
# glVertex3f(@entity.x, @entity.y, @entity.z)
|
||||
# glEnd
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -211,7 +211,7 @@ class IMICFPS
|
||||
@bounding_boxes.each do |key, bounding_box|
|
||||
glPushMatrix
|
||||
|
||||
glTranslatef(bounding_box[:object].x, bounding_box[:object].y, bounding_box[:object].z)
|
||||
glTranslatef(bounding_box[:object].position.x, bounding_box[:object].position.y, bounding_box[:object].position.z)
|
||||
draw_bounding_box(bounding_box)
|
||||
@bounding_boxes[key][:objects].each {|o| draw_bounding_box(o)}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class IMICFPS
|
||||
# Allocate arrays for future use
|
||||
@vertex_array_id = nil
|
||||
buffer = " " * 4
|
||||
glGenVectorArrays(1, buffer)
|
||||
glGenVertexArrays(1, buffer)
|
||||
@vertex_array_id = buffer.unpack('L2').first
|
||||
|
||||
# Allocate buffers for future use
|
||||
@@ -101,9 +101,9 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def populate_arrays
|
||||
glBindVectorArray(@vertex_array_id)
|
||||
glBindVertexArray(@vertex_array_id)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, @vertices_buffer)
|
||||
glBindVectorArray(0)
|
||||
glBindVertexArray(0)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user