diff --git a/lib/objects/game_object.rb b/lib/objects/game_object.rb index 568f265..1beb0ab 100644 --- a/lib/objects/game_object.rb +++ b/lib/objects/game_object.rb @@ -27,7 +27,7 @@ class IMICFPS if @bound_model @bound_model.model.game_object = self - @bound_model.model.objects.each {|o| o.parent = self} + @bound_model.model.objects.each {|o| o.scale = self.scale} box = normalize_bounding_box(@bound_model.model.bounding_box) @width = box.max_x-box.min_x @@ -42,7 +42,7 @@ class IMICFPS raise "model isn't a model!" unless model.is_a?(ModelLoader) @bound_model = model @bound_model.model.game_object = self - @bound_model.model.objects.each {|o| o.parent = self} + @bound_model.model.objects.each {|o| o.scale = self.scale} box = normalize_bounding_box(@bound_model.model.bounding_box) @width = box.max_x-box.min_x @height = box.max_y-box.min_y diff --git a/lib/wavefront/object.rb b/lib/wavefront/object.rb index 2d46b74..6837377 100644 --- a/lib/wavefront/object.rb +++ b/lib/wavefront/object.rb @@ -1,11 +1,10 @@ class IMICFPS class Wavefront class Object - attr_reader :parent, :name, :vertices, :textures, :normals, :bounding_box, :debug_color - attr_accessor :faces + attr_reader :name, :vertices, :textures, :normals, :bounding_box, :debug_color + attr_accessor :faces, :scale - def initialize(parent, name) - @parent = parent + def initialize(name) @name = name @vertices = [] @textures = [] @@ -13,7 +12,8 @@ class IMICFPS @faces = [] @bounding_box = BoundingBox.new(0,0,0, 0,0,0) @debug_color = Color.new(1.0,1.0,1.0) - @x,@y,@z = 0,0,0 + + @scale = 1.0 # Faces array packs everything: # vertex = index[0] @@ -22,10 +22,6 @@ class IMICFPS # material = index[3] end - def parent=(game_object) - @parent = game_object - end - def reflatten @vertices_list = nil @textures_list = nil @@ -36,28 +32,17 @@ class IMICFPS flattened_normals end - def at_same_position? - if @x == @parent.x - if @y == @parent.y - if @z == @parent.z - true - end - end - end - end - def flattened_vertices - unless @vertices_list && at_same_position? + unless @vertices_list @debug_color = @faces.first[3].diffuse - @x,@y,@z = @parent.x,@parent.y,@parent.z list = [] @faces.each do |face| [face[0]].each do |v| next unless v - list << v.x*@parent.scale#+@parent.x - list << v.y*@parent.scale#+@parent.y - list << v.z*@parent.scale#+@parent.z + list << v.x*@scale + list << v.y*@scale + list << v.z*@scale list << v.weight end end diff --git a/lib/wavefront/parser.rb b/lib/wavefront/parser.rb index ee6a9ac..8cd728a 100644 --- a/lib/wavefront/parser.rb +++ b/lib/wavefront/parser.rb @@ -84,7 +84,7 @@ class IMICFPS end def change_object(name) - @objects << Object.new(self, name) + @objects << Object.new(name) @current_object = @objects.last end