mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
AABB are now functional!
This commit is contained in:
@@ -65,16 +65,17 @@ class IMICFPS
|
|||||||
def update
|
def update
|
||||||
model.update
|
model.update
|
||||||
end
|
end
|
||||||
|
|
||||||
# Do two Axis Aligned Bounding Boxes intersect?
|
# Do two Axis Aligned Bounding Boxes intersect?
|
||||||
def intersect(a, b)
|
def intersect(a, b)
|
||||||
a = normalize_bounding_box(a)
|
a = a.normalize_bounding_box(a.model.bounding_box)
|
||||||
b = normalize_bounding_box(b)
|
b = b.normalize_bounding_box(b.model.bounding_box)
|
||||||
|
|
||||||
puts "bounding boxes match!" if a == b
|
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)) &&
|
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_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)))
|
((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.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
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
@@ -100,12 +101,6 @@ class IMICFPS
|
|||||||
box = normalize_bounding_box(box)
|
box = normalize_bounding_box(box)
|
||||||
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
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)
|
glBegin(GL_TRIANGLES)
|
||||||
# TOP
|
# TOP
|
||||||
glNormal3f(0,1,0)
|
glNormal3f(0,1,0)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class IMICFPS
|
|||||||
Tree.new(x: 1, y: 0, z: -5)
|
Tree.new(x: 1, y: 0, z: -5)
|
||||||
Tree.new(x: 5, y: 0, z: 5)
|
Tree.new(x: 5, y: 0, z: 5)
|
||||||
Tree.new(x: -5, y: 0, z: 1)
|
Tree.new(x: -5, y: 0, z: 1)
|
||||||
TestObject.new(scale: 1)
|
# TestObject.new(scale: 1)
|
||||||
p ObjectManager.objects.map {|o| o.name}
|
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", z: -5)
|
||||||
# Model.new(type: :obj, file_path: "objects/tree.obj", x: -2, z: -6)
|
# Model.new(type: :obj, file_path: "objects/tree.obj", x: -2, z: -6)
|
||||||
@@ -97,10 +97,17 @@ Debug mode: <c=992200>#{$debug}</c>
|
|||||||
eos
|
eos
|
||||||
@text.text = string
|
@text.text = string
|
||||||
|
|
||||||
# ObjectManager.objects.each do |object|
|
ObjectManager.objects.each do |object|
|
||||||
# object.update
|
ObjectManager.objects.each do |b|
|
||||||
# end
|
next if b == object
|
||||||
ObjectManager.objects.each(&:update)
|
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
|
@skydome.update if @skydome.renderable
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user