Replaced Vertex struct with Vector class

This commit is contained in:
2019-02-20 11:00:42 -06:00
parent 7b903fbdb9
commit a6e175d9e0
6 changed files with 59 additions and 10 deletions

View File

@@ -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
View 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

View File

@@ -1,3 +0,0 @@
class IMICFPS
Vector = Struct.new(:x, :y, :z, :weight)
end

View File

@@ -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

View File

@@ -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)}

View File

@@ -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