|
@@ -1,14 +1,4 @@
|
|
|
|
|
|
-#rem
|
|
|
-
|
|
|
-Notes:
|
|
|
-
|
|
|
-* Have to remove/add bodies from world if collision shape changes. http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=5194
|
|
|
-
|
|
|
-* default btCollsionObject activationState=ACTIVE_TAG (1)?
|
|
|
-
|
|
|
-#end
|
|
|
-
|
|
|
Namespace mojo3d
|
|
|
|
|
|
Private
|
|
@@ -22,7 +12,7 @@ Class MotionState Extends btMotionState
|
|
|
|
|
|
Method getWorldTransform( tform:btTransform Ptr ) Override
|
|
|
|
|
|
- If Not _entity.RigidBody.Kinematic Print "Dynamic getWorldTransform! Position="+_entity.Position
|
|
|
+' If Not _entity.RigidBody.Kinematic Print "Dynamic getWorldTransform! Position="+_entity.Position
|
|
|
|
|
|
tform->setOrigin( _entity.Position )
|
|
|
|
|
@@ -31,7 +21,7 @@ Class MotionState Extends btMotionState
|
|
|
|
|
|
Method setWorldTransform( tform:btTransform Ptr ) Override
|
|
|
|
|
|
- If _entity.RigidBody.Kinematic Print "Kinematic setWorldTransform!"
|
|
|
+' If _entity.RigidBody.Kinematic Print "Kinematic setWorldTransform!"
|
|
|
|
|
|
_entity.Position=tform->getOrigin()
|
|
|
|
|
@@ -56,24 +46,22 @@ End
|
|
|
|
|
|
Class RigidBody Extends Component
|
|
|
|
|
|
- Const Type:=New ComponentType( "RigidBody",1,ComponentTypeFlags.Singleton )
|
|
|
+ Const Type:=New ComponentType( "RigidBody",-10,ComponentTypeFlags.Singleton )
|
|
|
|
|
|
Method New( entity:Entity )
|
|
|
|
|
|
Super.New( entity,Type )
|
|
|
|
|
|
+ _btmotion=New MotionState( entity )
|
|
|
+
|
|
|
Local collider:=entity.Collider
|
|
|
Local inertia:btVector3=collider?.CalculateLocalInertia( _mass )
|
|
|
|
|
|
- _btmotion=New MotionState( entity )
|
|
|
-
|
|
|
- _btbody=New btRigidBody( _mass,_btmotion,collider.btShape,inertia )
|
|
|
+ _btbody=New btRigidBody( _mass,_btmotion,collider?.Validate(),inertia )
|
|
|
|
|
|
- Kinematic=False
|
|
|
- Mass=1
|
|
|
- Friction=1
|
|
|
- RollingFriction=1
|
|
|
Restitution=0
|
|
|
+ RollingFriction=0
|
|
|
+ Friction=1
|
|
|
CollisionGroup=1
|
|
|
CollisionMask=1
|
|
|
End
|
|
@@ -84,9 +72,9 @@ Class RigidBody Extends Component
|
|
|
|
|
|
Kinematic=body.Kinematic
|
|
|
Mass=body.Mass
|
|
|
+ Restitution=body.Restitution
|
|
|
Friction=body.Friction
|
|
|
RollingFriction=body.RollingFriction
|
|
|
- Restitution=body.Restitution
|
|
|
CollisionGroup=body.CollisionGroup
|
|
|
CollisionMask=body.CollisionMask
|
|
|
End
|
|
@@ -108,8 +96,6 @@ Class RigidBody Extends Component
|
|
|
_btbody.setCollisionFlags( _btbody.getCollisionFlags() & ~btCollisionObject.CF_KINEMATIC_OBJECT )
|
|
|
_btbody.forceActivationState( ACTIVE_TAG )
|
|
|
Endif
|
|
|
-
|
|
|
-' _dirty|=Dirty.Kinematic
|
|
|
End
|
|
|
|
|
|
Property Mass:Float()
|
|
@@ -124,11 +110,19 @@ Class RigidBody Extends Component
|
|
|
|
|
|
Local collider:=Entity.Collider
|
|
|
Local inertia:=collider?.CalculateLocalInertia( _mass )
|
|
|
- _btbody.setMassProps( _mass,inertia )
|
|
|
|
|
|
-' _dirty|=Dirty.Mass
|
|
|
+ _btbody.setMassProps( _mass,inertia )
|
|
|
End
|
|
|
|
|
|
+ Property Restitution:Float()
|
|
|
+
|
|
|
+ Return _btbody.getRestitution()
|
|
|
+
|
|
|
+ Setter( restitution:Float )
|
|
|
+
|
|
|
+ _btbody.setRestitution( restitution )
|
|
|
+ End
|
|
|
+
|
|
|
Property Friction:Float()
|
|
|
|
|
|
Return _btbody.getFriction()
|
|
@@ -147,15 +141,6 @@ Class RigidBody Extends Component
|
|
|
_btbody.setRollingFriction( friction )
|
|
|
End
|
|
|
|
|
|
- Property Restitution:Float()
|
|
|
-
|
|
|
- Return _btbody.getRestitution()
|
|
|
-
|
|
|
- Setter( restitution:Float )
|
|
|
-
|
|
|
- _btbody.setRestitution( restitution )
|
|
|
- End
|
|
|
-
|
|
|
Property LinearVelocity:Vec3f()
|
|
|
|
|
|
Return _btbody.getLinearVelocity()
|
|
@@ -181,6 +166,8 @@ Class RigidBody Extends Component
|
|
|
Setter( collGroup:Short )
|
|
|
|
|
|
_collGroup=collGroup
|
|
|
+
|
|
|
+ _dirty|=Dirty.Collisions
|
|
|
End
|
|
|
|
|
|
Property CollisionMask:Short()
|
|
@@ -190,6 +177,8 @@ Class RigidBody Extends Component
|
|
|
Setter( collMask:Short )
|
|
|
|
|
|
_collMask=collMask
|
|
|
+
|
|
|
+ _dirty|=Dirty.Collisions
|
|
|
End
|
|
|
|
|
|
Property btBody:btRigidBody()
|
|
@@ -202,6 +191,36 @@ Class RigidBody Extends Component
|
|
|
_btbody.clearForces()
|
|
|
End
|
|
|
|
|
|
+ Method ApplyForce( force:Vec3f )
|
|
|
+
|
|
|
+ _btbody.applyCentralForce( force )
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ApplyForce( force:Vec3f,offset:Vec3f )
|
|
|
+
|
|
|
+ _btbody.applyForce( force,offset )
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ApplyImpulse( impulse:Vec3f )
|
|
|
+
|
|
|
+ _btbody.applyCentralImpulse( impulse )
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ApplyImpulse( impulse:Vec3f,offset:Vec3f )
|
|
|
+
|
|
|
+ _btbody.applyForce( impulse,offset )
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ApplyTorque( torque:Vec3f )
|
|
|
+
|
|
|
+ _btbody.applyTorque( torque )
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ApplyTorqueImpulse( torque:Vec3f )
|
|
|
+
|
|
|
+ _btbody.applyTorqueImpulse( torque )
|
|
|
+ End
|
|
|
+
|
|
|
Protected
|
|
|
|
|
|
Method OnCopy:RigidBody( entity:Entity ) Override
|
|
@@ -211,41 +230,8 @@ Class RigidBody Extends Component
|
|
|
|
|
|
Method OnBeginUpdate() Override
|
|
|
|
|
|
-' Validate()
|
|
|
-
|
|
|
- Local collider:=Entity.Collider
|
|
|
+ Validate()
|
|
|
|
|
|
- Local seq:=collider?.Seq
|
|
|
-
|
|
|
- If seq<>_colliderseq
|
|
|
-
|
|
|
- If _rvisible
|
|
|
- If Entity.ReallyVisible
|
|
|
- World.btWorld.removeRigidBody( _btbody )
|
|
|
- Else
|
|
|
- _rvisible=False
|
|
|
- World.Remove( Self )
|
|
|
- Endif
|
|
|
- Endif
|
|
|
-
|
|
|
- _btbody.setCollisionShape( collider?.btShape )
|
|
|
- Local inertia:btVector3=collider?.CalculateLocalInertia( _mass )
|
|
|
- _btbody.setMassProps( _mass,inertia )
|
|
|
-
|
|
|
- If _rvisible World.btWorld.addRigidBody( _btbody )
|
|
|
-
|
|
|
- _colliderseq=seq
|
|
|
-
|
|
|
- Endif
|
|
|
-
|
|
|
- If Entity.ReallyVisible<>_rvisible
|
|
|
-
|
|
|
- _rvisible=Entity.ReallyVisible
|
|
|
-
|
|
|
- If _rvisible World.Add( Self ) Else World.Remove( Self )
|
|
|
-
|
|
|
- Endif
|
|
|
-
|
|
|
If Not _kinematic And Entity.Seq<>_seq
|
|
|
|
|
|
_btbody.setWorldTransform( Entity.Matrix )
|
|
@@ -255,14 +241,6 @@ Class RigidBody Extends Component
|
|
|
|
|
|
Method OnUpdate( elapsed:Float ) Override
|
|
|
|
|
|
-' If _kinematic Return
|
|
|
-
|
|
|
-' Local tform:=_btbody.getWorldTransform()
|
|
|
-
|
|
|
-' Entity.Position=tform.getOrigin()
|
|
|
-
|
|
|
-' Entity.Basis=tform.getBasis()
|
|
|
-
|
|
|
_seq=Entity.Seq
|
|
|
End
|
|
|
|
|
@@ -270,13 +248,18 @@ Class RigidBody Extends Component
|
|
|
|
|
|
If Not _rvisible Return
|
|
|
|
|
|
- _rvisible=False
|
|
|
-
|
|
|
World.Remove( Self )
|
|
|
+
|
|
|
+ _rvisible=False
|
|
|
End
|
|
|
|
|
|
Internal
|
|
|
|
|
|
+ Method ColliderInvalidated()
|
|
|
+
|
|
|
+ _dirty|=Dirty.Collider
|
|
|
+ End
|
|
|
+
|
|
|
Property World:World()
|
|
|
|
|
|
Return Entity.Scene.World
|
|
@@ -285,12 +268,12 @@ Class RigidBody Extends Component
|
|
|
Private
|
|
|
|
|
|
Enum Dirty
|
|
|
- Mass=1
|
|
|
- Kinematic=2
|
|
|
+ Collider=1
|
|
|
+ Collisions=2
|
|
|
End
|
|
|
|
|
|
- Field _kinematic:Bool=False
|
|
|
Field _mass:Float=1
|
|
|
+ Field _kinematic:Bool=False
|
|
|
Field _collGroup:Short=1
|
|
|
Field _collMask:Short=1
|
|
|
|
|
@@ -301,29 +284,43 @@ Class RigidBody Extends Component
|
|
|
Field _colliderseq:Int
|
|
|
Field _rvisible:Bool
|
|
|
Field _seq:Int
|
|
|
-
|
|
|
+
|
|
|
Method Validate()
|
|
|
|
|
|
- If Not _dirty Return
|
|
|
+ Local rvisible:=Entity.ReallyVisible
|
|
|
|
|
|
- If _dirty & Dirty.Mass
|
|
|
-
|
|
|
+ If rvisible=_rvisible And Not _dirty Return
|
|
|
+
|
|
|
+ If Not rvisible Return
|
|
|
+
|
|
|
+ 'Have to remove/add bodies from world if collision shape changes. http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=5194
|
|
|
+ '
|
|
|
+ If _rvisible
|
|
|
+
|
|
|
+ World.Remove( Self )
|
|
|
+
|
|
|
+ _rvisible=False
|
|
|
+ Endif
|
|
|
+
|
|
|
+ If _dirty & Dirty.Collider
|
|
|
+
|
|
|
Local collider:=Entity.Collider
|
|
|
+
|
|
|
+ _btbody.setCollisionShape( collider?.Validate() )
|
|
|
+
|
|
|
Local inertia:btVector3=collider?.CalculateLocalInertia( _mass )
|
|
|
+
|
|
|
_btbody.setMassProps( _mass,inertia )
|
|
|
Endif
|
|
|
-
|
|
|
- If _dirty & Dirty.Kinematic
|
|
|
+
|
|
|
+ If _rvisible<>rvisible
|
|
|
|
|
|
- If _kinematic
|
|
|
- _btbody.setCollisionFlags( _btbody.getCollisionFlags() | btCollisionObject.CF_KINEMATIC_OBJECT )
|
|
|
- _btbody.setActivationState( DISABLE_DEACTIVATION )
|
|
|
- Else
|
|
|
- _btbody.setCollisionFlags( _btbody.getCollisionFlags() & ~btCollisionObject.CF_KINEMATIC_OBJECT )
|
|
|
- _btbody.forceActivationState( ACTIVE_TAG )
|
|
|
- Endif
|
|
|
+ If rvisible World.Add( Self ) Else World.Remove( Self )
|
|
|
+
|
|
|
+ _rvisible=rvisible
|
|
|
Endif
|
|
|
-
|
|
|
+
|
|
|
_dirty=Null
|
|
|
End
|
|
|
+
|
|
|
End
|