Class: Teien::ViewObject
- Inherits:
-
Object
- Object
- Teien::ViewObject
- Defined in:
- lib/teien/ui/view_object.rb
Instance Attribute Summary collapse
-
#animation_operators ⇒ Object
Returns the value of attribute animation_operators.
-
#entity ⇒ Object
Returns the value of attribute entity.
-
#object ⇒ Object
Returns the value of attribute object.
-
#pivot_scene_node ⇒ Object
Ogre3D accessor center of view objects(sceneNode) and kept to equal with the rigid_body position.
-
#scene_node ⇒ Object
Returns the value of attribute scene_node.
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(view) ⇒ ViewObject
constructor
A new instance of ViewObject.
-
#set_position(aPos) ⇒ Object
handlers of BaseObject.
- #set_rotation(rot) ⇒ Object
-
#set_scene_node(entity, offset = Vector3D.new(0, 0, 0), rotate = Quaternion.new(0, 0, 0, 1.0)) ⇒ Object
The offset changes the local position of the created scene_node in Object.
- #set_world_transform(transform) ⇒ Object
- #update_animation(delta, animation) ⇒ Object
- #update_attached_objects(view) ⇒ Object
Constructor Details
#initialize(view) ⇒ ViewObject
Returns a new instance of ViewObject.
15 16 17 18 19 20 21 22 23 |
# File 'lib/teien/ui/view_object.rb', line 15 def initialize(view) @view = view @pivot_scene_node = nil @scene_node = nil @entity = nil @animation_operators = Hash.new @attached_objects = Hash.new @base_object_manager = Teien::get_component("base_object_manager") end |
Instance Attribute Details
#animation_operators ⇒ Object
Returns the value of attribute animation_operators.
11 12 13 |
# File 'lib/teien/ui/view_object.rb', line 11 def animation_operators @animation_operators end |
#entity ⇒ Object
Returns the value of attribute entity.
10 11 12 |
# File 'lib/teien/ui/view_object.rb', line 10 def entity @entity end |
#object ⇒ Object
Returns the value of attribute object.
13 14 15 |
# File 'lib/teien/ui/view_object.rb', line 13 def object @object end |
#pivot_scene_node ⇒ Object
Ogre3D accessor center of view objects(sceneNode) and kept to equal with the rigid_body position.
8 9 10 |
# File 'lib/teien/ui/view_object.rb', line 8 def pivot_scene_node @pivot_scene_node end |
#scene_node ⇒ Object
Returns the value of attribute scene_node.
9 10 11 |
# File 'lib/teien/ui/view_object.rb', line 9 def scene_node @scene_node end |
Instance Method Details
#finalize ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/teien/ui/view_object.rb', line 25 def finalize() @pivot_scene_node.remove_child(@scene_node) @view.scene_mgr.destroySceneNode(@scene_node) @view.scene_mgr.get_root_scene_node.remove_child(@pivot_scene_node) @view.scene_mgr.destroySceneNode(@pivot_scene_node) @view.scene_mgr.destroyEntity(@entity) end |
#set_position(aPos) ⇒ Object
handlers of BaseObject
116 117 118 119 120 121 122 123 |
# File 'lib/teien/ui/view_object.rb', line 116 def set_position(aPos) if @pivot_scene_node @pivot_scene_node.set_position(aPos.x, aPos.y, aPos.z) else # object_info.class == LightObjectInfo @entity.set_position(Vector3D.to_ogre(aPos)) end end |
#set_rotation(rot) ⇒ Object
137 138 139 |
# File 'lib/teien/ui/view_object.rb', line 137 def set_rotation(rot) @pivot_scene_node.set_orientation(Quaternion.to_ogre(rot)) end |
#set_scene_node(entity, offset = Vector3D.new(0, 0, 0), rotate = Quaternion.new(0, 0, 0, 1.0)) ⇒ Object
The offset changes the local position of the created scene_node in Object.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/teien/ui/view_object.rb', line 97 def set_scene_node(entity, offset = Vector3D.new(0, 0, 0), rotate = Quaternion.new(0, 0, 0, 1.0)) if (@pivot_scene_node == nil) @pivot_scene_node = @view.scene_mgr.get_root_scene_node().create_child_scene_node() end @scene_node = @pivot_scene_node.create_child_scene_node(Vector3D.to_ogre(offset), Quaternion.to_ogre(rotate)) @pivot_scene_node.instance_variable_set(:@child, @scene_node) # prevent this from GC. if entity @scene_node.attach_object(entity) @entity = entity end return @scene_node end |
#set_world_transform(transform) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/teien/ui/view_object.rb', line 125 def set_world_transform(transform) newPos = transform.get_origin() newRot = transform.get_rotation() # puts "newRot(#{id}: #{newRot.x}, #{newRot.y}, #{newRot.z}, #{newRot.w})" # puts "newPos(#{id}: #{newPos.x}, #{newPos.y}, #{newPos.z})" return if (newRot.x.nan?) @pivot_scene_node.set_position(newPos.x, newPos.y, newPos.z) @pivot_scene_node.set_orientation(newRot.w, newRot.x, newRot.y, newRot.z) end |
#update_animation(delta, animation) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/teien/ui/view_object.rb', line 77 def update_animation(delta, animation) animation.operators.each_pair{|key, value| unless @animation_operators[key] @entity.get_skeleton().set_blend_mode(animation.blend_mode) ani_ope = AnimationOperator.new(@entity) ani_ope.init(value.name, value.loop) @animation_operators[key] = ani_ope end if (value.name != @animation_operators[key].name || value.loop != @animation_operators[key].loop) @animation_operators[key].play(value.name, value.loop) end @animation_operators[key].add_time(delta * value.speed) } end |
#update_attached_objects(view) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/teien/ui/view_object.rb', line 33 def update_attached_objects(view) # attached @object.attached_objects.each_pair {|key, info| unless @attached_objects[key] attached_object = @base_object_manager.objects[info.object_name] attached_entity = view.objects[attached_object.name].entity attached_scene_node = view.objects[attached_object.name].scene_node puts "attached: #{info.bone_name}, #{attached_entity}" attached_scene_node.detach_object(attached_entity) tag = @entity.attach_object_to_bone(info.bone_name, attached_entity) # @manager.physics.dynamics_world.remove_rigid_body(obj.rigid_body) attached_object.mode = Teien::BaseObject::MODE_ATTACHED @attached_objects[key] = info end } # detached @attached_objects.each_pair {|key, info| unless @object.attached_objects[key] detached_object = @base_object_manager.objects[info.object_name] detached_entity = view.objects[detached_object.name] detached_scene_node = view.objects[detached_object.name].scene_node @entity.detach_object_from_bone(detached_entity) detached_scene_node.attach_object(obj.entity) =begin if obj.physics_info.collision_filter @manager.physics.dynamics_world.add_rigid_body(obj.rigid_body, obj.physics_info.collision_filter.group, obj.physics_info.collision_filter.mask) else @manager.physics.dynamics_world.add_rigid_body(obj.rigid_body) end =end detached_object.mode = Teien::BaseObject::MODE_FREE @attached_objects.delete(key) end } end |