Class: Teien::PhysicsObject
- Inherits:
-
Object
- Object
- Teien::PhysicsObject
- Defined in:
- lib/teien/base_object/physics_object.rb
Instance Attribute Summary collapse
-
#acceleration ⇒ Object
Returns the value of attribute acceleration.
-
#maxHorizontalVelocity ⇒ Object
Returns the value of attribute maxHorizontalVelocity.
-
#maxVerticalVelocity ⇒ Object
Returns the value of attribute maxVerticalVelocity.
-
#pivot_shape ⇒ Object
Returns the value of attribute pivot_shape.
-
#rigid_body ⇒ Object
Bullet accessor.
-
#shape ⇒ Object
Returns the value of attribute shape.
-
#transform ⇒ Object
Returns the value of attribute transform.
Instance Method Summary collapse
- #create_rigid_body(mass, motionState, colObj, inertia) ⇒ Object
- #finalize ⇒ Object
-
#initialize(physics) ⇒ PhysicsObject
constructor
A new instance of PhysicsObject.
-
#set_rigid_body(obj, shape, inertia, offset = Vector3D.new(0, 0, 0)) ⇒ Object
The offset changes the local position of the shape(collision shape) in Object.
Constructor Details
#initialize(physics) ⇒ PhysicsObject
Returns a new instance of PhysicsObject.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/teien/base_object/physics_object.rb', line 13 def initialize(physics) @physics = physics @rigid_body = nil @transform = Bullet::BtTransform.new() @transform.set_identity() @acceleration = Vector3D.new(0, 0, 0) @maxHorizontalVelocity = 0 @maxVerticalVelocity = 0 end |
Instance Attribute Details
#acceleration ⇒ Object
Returns the value of attribute acceleration.
9 10 11 |
# File 'lib/teien/base_object/physics_object.rb', line 9 def acceleration @acceleration end |
#maxHorizontalVelocity ⇒ Object
Returns the value of attribute maxHorizontalVelocity.
10 11 12 |
# File 'lib/teien/base_object/physics_object.rb', line 10 def maxHorizontalVelocity @maxHorizontalVelocity end |
#maxVerticalVelocity ⇒ Object
Returns the value of attribute maxVerticalVelocity.
11 12 13 |
# File 'lib/teien/base_object/physics_object.rb', line 11 def maxVerticalVelocity @maxVerticalVelocity end |
#pivot_shape ⇒ Object
Returns the value of attribute pivot_shape.
7 8 9 |
# File 'lib/teien/base_object/physics_object.rb', line 7 def pivot_shape @pivot_shape end |
#rigid_body ⇒ Object
Bullet accessor
5 6 7 |
# File 'lib/teien/base_object/physics_object.rb', line 5 def rigid_body @rigid_body end |
#shape ⇒ Object
Returns the value of attribute shape.
8 9 10 |
# File 'lib/teien/base_object/physics_object.rb', line 8 def shape @shape end |
#transform ⇒ Object
Returns the value of attribute transform.
6 7 8 |
# File 'lib/teien/base_object/physics_object.rb', line 6 def transform @transform end |
Instance Method Details
#create_rigid_body(mass, motionState, colObj, inertia) ⇒ Object
49 50 51 52 53 |
# File 'lib/teien/base_object/physics_object.rb', line 49 def create_rigid_body(mass, motionState, colObj, inertia) rigid_body = Bullet::BtRigidBody.new(mass, motionState, colObj, inertia) rigid_body.instance_variable_set(:@collision_shape, colObj) # prevent this colObj from GC. return rigid_body end |
#finalize ⇒ Object
24 25 26 |
# File 'lib/teien/base_object/physics_object.rb', line 24 def finalize() @physics.del_rigid_body(@rigid_body) end |
#set_rigid_body(obj, shape, inertia, offset = Vector3D.new(0, 0, 0)) ⇒ Object
The offset changes the local position of the shape(collision shape) in Object.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/teien/base_object/physics_object.rb', line 31 def set_rigid_body(obj, shape, inertia, offset = Vector3D.new(0, 0, 0)) # puts "offset(#{offset.x}, #{offset.y}, #{offset.z})" @pivot_shape = Bullet::BtCompoundShape.new localTrans = Bullet::BtTransform.new localTrans.set_identity() localTrans.set_origin(offset) @pivot_shape.add_child_shape(localTrans, shape) @shape = shape # @rigid_body = @physics.create_rigid_body(obj.physics_info.mass, obj, @pivot_shape, inertia) @rigid_body = create_rigid_body(obj.physics_info.mass, obj, @pivot_shape, inertia) @rigid_body.set_angular_factor(obj.physics_info.angular_factor) @rigid_body.set_restitution(obj.physics_info.restitution) @rigid_body.set_friction(obj.physics_info.friction) @rigid_body.set_damping(obj.physics_info.linear_damping, obj.physics_info.angular_damping) return @rigid_body end |