Did some reorganizing

This commit is contained in:
2018-03-20 15:11:00 -05:00
parent a3c92f9de3
commit 46f533f83e
9 changed files with 157 additions and 53 deletions

View File

@@ -6,9 +6,9 @@ class IMICFPS
attr_reader :texture
def initialize(name)
@name = name
@ambient = Wavefront::Model::Color.new(1, 1, 1, 1)
@diffuse = Wavefront::Model::Color.new(1, 1, 1, 1)
@specular= Wavefront::Model::Color.new(1, 1, 1, 1)
@ambient = Color.new(1, 1, 1, 1)
@diffuse = Color.new(1, 1, 1, 1)
@specular= Color.new(1, 1, 1, 1)
@texture = nil
@texture_id = nil
end

View File

@@ -1,3 +1,7 @@
require_relative "parser"
require_relative "object"
require_relative "material"
class IMICFPS
class Wavefront
class Model
@@ -47,25 +51,7 @@ class IMICFPS
end
end
def handleGlError
e = glGetError()
if e != GL_NO_ERROR
$stderr.puts "OpenGL error in: #{gluErrorString(e)} (#{e})\n"
exit
end
end
def draw(x, y, z, scale = MODEL_METER_SCALE, back_face_culling = true)
handleGlError
render(x,y,z, scale, back_face_culling)
handleGlError
end
def render(x,y,z, scale, back_face_culling)
glEnable(GL_NORMALIZE)
glPushMatrix
glTranslatef(x,y,z)
glScalef(scale, scale, scale)
def draw(x,y,z, scale, back_face_culling)
@objects.each_with_index do |o, i|
glEnable(GL_CULL_FACE) if back_face_culling
glEnable(GL_COLOR_MATERIAL)
@@ -95,12 +81,11 @@ class IMICFPS
# glBindTexture(GL_TEXTURE_2D, 0)
glDisable(GL_TEXTURE_2D)
end
render_bounding_box(o.bounding_box, o.debug_color) if $debug
glDisable(GL_CULL_FACE) if back_face_culling
glDisable(GL_COLOR_MATERIAL)
render_bounding_box(o.bounding_box, o.debug_color) if $debug
end
render_bounding_box(@bounding_box) if $debug
glPopMatrix
$window.number_of_faces+=self.faces.size

View File

@@ -11,7 +11,7 @@ class IMICFPS
@normals = []
@faces = []
@bounding_box = BoundingBox.new(nil,nil,nil, nil,nil,nil)
@debug_color = Parser::Color.new(1.0,0.0,0.0)
@debug_color = Color.new(1.0,0.0,0.0)
# Faces array packs everything:
# vertex = index[0]

View File

@@ -1,10 +1,6 @@
class IMICFPS
class Wavefront
module Parser
TextureCoordinate = Struct.new(:u, :v, :weight)
Vertex = Struct.new(:x, :y, :z, :weight)
Color = Struct.new(:red, :green, :blue, :alpha)
def parse
lines = 0
@file.each_line do |line|