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 glPushMatrix
# Render bounding boxes before transformation is applied # Render bounding boxes before transformation is applied
render_bounding_box(@model.bounding_box) if $debug 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) # glTranslatef(@x, @y, @z)
glRotatef(@x_rotation,1.0, 0, 0) # glRotatef(@x_rotation,1.0, 0, 0)
glRotatef(@y_rotation,0, 1.0, 0) # glRotatef(@y_rotation,0, 1.0, 0)
glRotatef(@z_rotation,0, 0, 1.0) # glRotatef(@z_rotation,0, 0, 1.0)
handleGlError handleGlError
@model.draw(@x, @y, @z, @scale, @backface_culling) @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) if self.intersect(self.model.bounding_box, b.model.bounding_box)
self.y_rotation+=0.02 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 else
# puts "!=! No Collision" # puts "!=! No Collision"
end end
@@ -110,15 +115,46 @@ class IMICFPS
b = normalize_bounding_box(b) b = normalize_bounding_box(b)
puts "bounding boxes match!" if a == b puts "bounding boxes match!" if a == b
# maxx1 > minx2 && minx1 < maxx2 # && maxy1 > miny1 && miny1 < maxy2 # p to_abs(a),to_abs(b)
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 # 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)
return true 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
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) def normalize_bounding_box(box)
temp = BoundingBox.new temp = BoundingBox.new
temp.min_x = box.min_x.to_f*scale+x temp.min_x = box.min_x.to_f*scale+x
@@ -138,12 +174,12 @@ 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) # glBegin(GL_LINES)
glColor3f(0,0,1.0) # glColor3f(0,0,1.0)
glVertex3f(box.min_x, box.min_y, box.min_z) # glVertex3f(box.min_x, box.min_y, box.min_z)
glColor3f(1.0,0,0) # glColor3f(1.0,0,0)
glVertex3f(box.max_x, box.max_y, box.max_z) # glVertex3f(box.max_x, box.max_y, box.max_z)
glEnd # glEnd
glBegin(GL_TRIANGLES) glBegin(GL_TRIANGLES)
# TOP # TOP
glNormal3f(0,1,0) glNormal3f(0,1,0)

View File

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

View File

@@ -34,8 +34,11 @@ class IMICFPS
@bounding_box = BoundingBox.new(0,0,0, 0,0,0) @bounding_box = BoundingBox.new(0,0,0, 0,0,0)
start_time = Time.now start_time = Time.now
parse parse
# point = rand(1.0..10.0)
# @bounding_box = BoundingBox.new(point.to_f/2, point.to_f/2, point.to_f/2, point, point, point)
# puts "!!!!!!!!!!!!!!"
# puts @bounding_box
puts "#{@file_path.split('/').last} took #{(Time.now-start_time).round(2)} seconds to parse" puts "#{@file_path.split('/').last} took #{(Time.now-start_time).round(2)} seconds to parse"
p @bounding_box
face_count = 0 face_count = 0
@objects.each {|o| face_count+=o.faces.size} @objects.each {|o| face_count+=o.faces.size}

View File

@@ -13,6 +13,7 @@ class IMICFPS
@faces = [] @faces = []
@bounding_box = BoundingBox.new(0,0,0, 0,0,0) @bounding_box = BoundingBox.new(0,0,0, 0,0,0)
@debug_color = Color.new(1.0,0.0,0.0) @debug_color = Color.new(1.0,0.0,0.0)
@x,@y,@z = 0,0,0
# Faces array packs everything: # Faces array packs everything:
# vertex = index[0] # vertex = index[0]
@@ -21,17 +22,28 @@ class IMICFPS
# material = index[3] # material = index[3]
end end
def at_same_position?
if @x == @parent.x
if @x == @parent.x
if @x == @parent.x
true
end
end
end
end
def flattened_vertices def flattened_vertices
unless @vertices_list unless @vertices_list && at_same_position?
@debug_color = @faces.first[3].diffuse @debug_color = @faces.first[3].diffuse
@x,@y,@z = @parent.x,@parent.y,@parent.z
list = [] list = []
@faces.each do |face| @faces.each do |face|
[face[0]].each do |v| [face[0]].each do |v|
next unless v next unless v
list << v.x*@parent.scale#+@parent.x list << v.x*@parent.scale+@parent.x
list << v.y*@parent.scale#+@parent.y list << v.y*@parent.scale+@parent.y
list << v.z*@parent.scale#+@parent.z list << v.z*@parent.scale+@parent.z
list << v.weight list << v.weight
end end
end end

View File

@@ -150,7 +150,7 @@ class IMICFPS
def calculate_bounding_box(vertices, bounding_box) def calculate_bounding_box(vertices, bounding_box)
unless bounding_box.min_x.is_a?(Float) unless bounding_box.min_x.is_a?(Float)
vertex = vertices.first vertex = vertices.last
bounding_box.min_x = vertex.x bounding_box.min_x = vertex.x
bounding_box.min_y = vertex.y bounding_box.min_y = vertex.y
bounding_box.min_z = vertex.z bounding_box.min_z = vertex.z
@@ -161,13 +161,13 @@ class IMICFPS
end end
vertices.each do |vertex| vertices.each do |vertex|
bounding_box.min_x = vertex.x if vertex.x < bounding_box.min_x bounding_box.min_x = vertex.x if vertex.x <= bounding_box.min_x
bounding_box.min_y = vertex.y if vertex.y < bounding_box.min_y bounding_box.min_y = vertex.y if vertex.y <= bounding_box.min_y
bounding_box.min_z = vertex.z if vertex.z < bounding_box.min_z bounding_box.min_z = vertex.z if vertex.z <= bounding_box.min_z
bounding_box.max_x = vertex.x if vertex.x > bounding_box.max_x bounding_box.max_x = vertex.x if vertex.x >= bounding_box.max_x
bounding_box.max_y = vertex.y if vertex.y > bounding_box.max_y bounding_box.max_y = vertex.y if vertex.y >= bounding_box.max_y
bounding_box.max_z = vertex.z if vertex.z > bounding_box.max_z bounding_box.max_z = vertex.z if vertex.z >= bounding_box.max_z
end end
end end
end end

View File

@@ -5,6 +5,7 @@ class IMICFPS
# include GLUT # include GLUT
attr_accessor :number_of_faces, :needs_cursor attr_accessor :number_of_faces, :needs_cursor
attr_reader :camera
def initialize(window_width = 1280, window_height = 800, fullscreen = false) def initialize(window_width = 1280, window_height = 800, fullscreen = false)
if ARGV.join.include?("--native") if ARGV.join.include?("--native")
@@ -17,17 +18,17 @@ class IMICFPS
@delta_time = Gosu.milliseconds @delta_time = Gosu.milliseconds
@number_of_faces = 0 @number_of_faces = 0
@draw_skydome = true @draw_skydome = false
@skydome = Model.new(type: :obj, file_path: "objects/skydome.obj", x: 0, y: 0,z: 0, scale: 1, backface_culling: false, auto_manage: false) @skydome = Model.new(type: :obj, file_path: "objects/skydome.obj", x: 0, y: 0,z: 0, scale: 0.8, backface_culling: false, auto_manage: false)
@actor = Model.new(type: :obj, file_path: "objects/biped.obj", x: 0, y: 0, z: -2) @actor = Model.new(type: :obj, file_path: "objects/biped.obj", x: 1, y: 0, z: 8)
Model.new(type: :obj, file_path: "objects/tree.obj", x: 0, y: 0, z: -10) Model.new(type: :obj, file_path: "objects/tree.obj", x: 10, y: 0, z: 10)
# 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)
# Model.new(type: :obj, file_path: "objects/sponza.obj", scale: 1, y: -0.2) # Model.new(type: :obj, file_path: "objects/sponza.obj", scale: 1, y: -0.2)
@terrain = Terrain.new(size: 100) # @terrain = Terrain.new(size: 20)
@camera = Camera.new(x: 0, y: -2, z: 1) @camera = Camera.new(x: 0, y: -2, z: 1)
@camera.bind_model(@actor) # @camera.bind_model(@actor)
@crosshair_size = 10 @crosshair_size = 10
@crosshair_thickness = 3 @crosshair_thickness = 3
@@ -59,7 +60,7 @@ class IMICFPS
ObjectManager.objects.each do |object| ObjectManager.objects.each do |object|
object.draw if object.visible && object.renderable object.draw if object.visible && object.renderable
end end
@terrain.draw @terrain.draw if @terrain
end end
# Draw crosshair # Draw crosshair