AABB are now functional!

This commit is contained in:
2018-07-01 12:10:48 -05:00
parent 6a14c5e9be
commit 5b16d9b4c3
2 changed files with 19 additions and 17 deletions

View File

@@ -65,16 +65,17 @@ class IMICFPS
def update
model.update
end
# Do two Axis Aligned Bounding Boxes intersect?
def intersect(a, b)
a = normalize_bounding_box(a)
b = normalize_bounding_box(b)
a = a.normalize_bounding_box(a.model.bounding_box)
b = b.normalize_bounding_box(b.model.bounding_box)
puts "bounding boxes match!" if a == b
# if (((a.min_x <= b.min_x && b.max_x <= a.max_x) || (b.min_x <= a.min_x && a.min_x <= b.max_x)) &&
# ((a.min_y <= b.min_y && b.max_y <= a.max_y) || (b.min_y <= a.min_y && a.min_y <= b.max_y)) &&
# ((a.min_z <= b.min_z && b.max_z <= a.max_z) || (b.min_z <= a.min_z && a.min_z <= b.max_z)))
if (a.max_x >= b.max_x && a.min_x <= b.max_x) && (a.max_y >= b.min_y && a.min_y <= b.max_y) && (a.max_z >= b.min_z && a.min_z <= b.max_z)
if (((a.min_x <= b.min_x && b.max_x <= a.max_x) || (b.min_x <= a.min_x && a.min_x <= b.max_x)) &&
((a.min_y <= b.min_y && b.max_y <= a.max_y) || (b.min_y <= a.min_y && a.min_y <= b.max_y)) &&
((a.min_z <= b.min_z && b.max_z <= a.max_z) || (b.min_z <= a.min_z && a.min_z <= b.max_z)))
# if (a.max_x >= b.max_x && a.min_x <= b.max_x) && (a.max_y >= b.min_y && a.min_y <= b.max_y) && (a.max_z >= b.min_z && a.min_z <= b.max_z)
return true
else
return false
@@ -100,12 +101,6 @@ class IMICFPS
box = normalize_bounding_box(box)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
# glBegin(GL_LINES)
# glColor3f(0,0,1.0)
# glVertex3f(box.min_x, box.min_y, box.min_z)
# glColor3f(1.0,0,0)
# glVertex3f(box.max_x, box.max_y, box.max_z)
# glEnd
glBegin(GL_TRIANGLES)
# TOP
glNormal3f(0,1,0)

View File

@@ -24,7 +24,7 @@ class IMICFPS
Tree.new(x: 1, y: 0, z: -5)
Tree.new(x: 5, y: 0, z: 5)
Tree.new(x: -5, y: 0, z: 1)
TestObject.new(scale: 1)
# TestObject.new(scale: 1)
p ObjectManager.objects.map {|o| o.name}
# Model.new(type: :obj, file_path: "objects/tree.obj", z: -5)
# Model.new(type: :obj, file_path: "objects/tree.obj", x: -2, z: -6)
@@ -97,10 +97,17 @@ Debug mode: <c=992200>#{$debug}</c>
eos
@text.text = string
# ObjectManager.objects.each do |object|
# object.update
# end
ObjectManager.objects.each(&:update)
ObjectManager.objects.each do |object|
ObjectManager.objects.each do |b|
next if b == object
if object.intersect(object, b)
puts "#{object} is intersecting #{b}"
puts "#{object.x}, #{object.y} | #{b.x}, #{b.y}"
end
end
object.update
end
# ObjectManager.objects.each(&:update)
@skydome.update if @skydome.renderable