Everything is broken and stuff.

This commit is contained in:
2018-03-22 15:15:20 -05:00
parent e7aa32b62d
commit 632830503b
6 changed files with 94 additions and 42 deletions

View File

@@ -56,12 +56,12 @@ class IMICFPS
glPushMatrix
# Render bounding boxes before transformation is applied
render_bounding_box(@model.bounding_box) if $debug
@model.objects.each {|o| render_bounding_box(o.bounding_box, o.debug_color)} if $debug
# @model.objects.each {|o| render_bounding_box(o.bounding_box, o.debug_color)} if $debug
glTranslatef(@x, @y, @z)
glRotatef(@x_rotation,1.0, 0, 0)
glRotatef(@y_rotation,0, 1.0, 0)
glRotatef(@z_rotation,0, 0, 1.0)
# glTranslatef(@x, @y, @z)
# glRotatef(@x_rotation,1.0, 0, 0)
# glRotatef(@y_rotation,0, 1.0, 0)
# glRotatef(@z_rotation,0, 0, 1.0)
handleGlError
@model.draw(@x, @y, @z, @scale, @backface_culling)
@@ -79,7 +79,12 @@ class IMICFPS
if self.intersect(self.model.bounding_box, b.model.bounding_box)
self.y_rotation+=0.02
puts "#{b.name} is touching me"
puts "#{b.name} is touching #{self.name}"
a_box = normalize_bounding_box(self.model.bounding_box).to_a.map {|q| q.round(2)}
puts "(#{self.name}): (#{a_box[0..2].join(',')}) and (#{a_box[3..5].join(',')})"
b_box = normalize_bounding_box(b.model.bounding_box).to_a.map {|q| q.round(2)}
puts "(#{b.name}): (#{b_box[0..2].join(',')}) and (#{b_box[3..5].join(',')})"
else
# puts "!=! No Collision"
end
@@ -110,15 +115,46 @@ class IMICFPS
b = normalize_bounding_box(b)
puts "bounding boxes match!" if a == b
# maxx1 > minx2 && minx1 < maxx2 # && maxy1 > miny1 && miny1 < maxy2
# p to_abs(a),to_abs(b)
# exit
# puts "MAX_X"
# return false if a.max_x <= b.min_x
# puts "MIN_X"
# return false if a.min_x >= b.max_x
#
# puts "MAX_Y"
# return false if a.max_y <= b.min_y
# puts "MIN_Y"
# return false if a.min_y >= b.max_y
#
# puts "MAX_Z"
# return false if a.max_z <= b.min_z
# puts "MIN_Z"
# return false if a.min_z >= b.max_z
# puts "END"
# return true
# 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)
# puts a
# puts b
# exit
return true
# elsif (b.max_x >= a.max_x && b.min_x <= a.max_x) && (b.max_y >= a.min_y && b.min_y <= a.max_y) && (b.max_z >= a.min_z && b.min_z <= a.max_z)
# return true
end
end
def to_abs(box)
temp = BoundingBox.new
temp.min_x = box.min_x.abs
temp.min_y = box.min_y.abs
temp.min_z = box.min_z.abs
temp.max_x = box.max_x.abs
temp.max_y = box.max_y.abs
temp.max_z = box.max_z.abs
return temp
end
def normalize_bounding_box(box)
temp = BoundingBox.new
temp.min_x = box.min_x.to_f*scale+x
@@ -138,12 +174,12 @@ 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_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

@@ -2,7 +2,7 @@ class IMICFPS
class Terrain
include OpenGL
def initialize(size:, heightmap: nil)
@size = size
@size = size.to_f
@heightmap = heightmap
end
@@ -13,14 +13,14 @@ class IMICFPS
glBegin(GL_TRIANGLES)
glNormal3f(0,1,0)
glColor3f(1, 0.5, 0.0)
glVertex3f(-@size,height,-@size)
glVertex3f(-@size,height,@size)
glVertex3f(@size,height,@size)
glVertex3f(-@size/2,height,-@size/2)
glVertex3f(-@size/2,height,@size/2)
glVertex3f(@size/2,height,@size/2)
glColor3f(0, 0.5, 0.0)
glVertex3f(@size,height,@size)
glVertex3f(@size,height,-@size)
glVertex3f(-@size,height,-@size)
glVertex3f(@size/2,height,@size/2)
glVertex3f(@size/2,height,-@size/2)
glVertex3f(-@size/2,height,-@size/2)
glEnd
glDisable(GL_COLOR_MATERIAL)