|
@@ -1,6 +1,46 @@
|
|
|
|
|
|
Namespace mojo3d.physics
|
|
Namespace mojo3d.physics
|
|
|
|
|
|
|
|
+#Import "native/objecthandle.h"
|
|
|
|
+
|
|
|
|
+Extern
|
|
|
|
+
|
|
|
|
+Function object_to_handle:Void Ptr( obj:Object )="bb_object_to_handle"
|
|
|
|
+
|
|
|
|
+Function handle_to_object:Object( handle:Void Ptr )="bb_handle_to_object"
|
|
|
|
+
|
|
|
|
+Public
|
|
|
|
+
|
|
|
|
+Class RaycastResult
|
|
|
|
+
|
|
|
|
+ Field time:Float
|
|
|
|
+ Field body:RigidBody
|
|
|
|
+ Field point:Vec3f
|
|
|
|
+ Field normal:Vec3f
|
|
|
|
+
|
|
|
|
+ Method New()
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Method New( btresult:btCollisionWorld.ClosestRayResultCallback )
|
|
|
|
+ time=btresult.m_closestHitFraction
|
|
|
|
+ body=Cast<RigidBody>( handle_to_object( btresult.m_collisionObject.getUserPointer() ) )
|
|
|
|
+ point=btresult.m_hitPointWorld
|
|
|
|
+ normal=btresult.m_hitNormalWorld
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Method New( btresult:btCollisionWorld.ClosestConvexResultCallback )
|
|
|
|
+
|
|
|
|
+ Local castFrom:=Cast<Vec3f>( btresult.m_convexFromWorld )
|
|
|
|
+ Local castTo:=Cast<Vec3f>( btresult.m_convexToWorld )
|
|
|
|
+
|
|
|
|
+ time=btresult.m_closestHitFraction
|
|
|
|
+ body=Cast<RigidBody>( handle_to_object( btresult.m_hitCollisionObject.getUserPointer() ) )
|
|
|
|
+ point=(castTo-castFrom) * btresult.m_closestHitFraction + castFrom
|
|
|
|
+ normal=btresult.m_hitNormalWorld
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+End
|
|
|
|
+
|
|
Class World
|
|
Class World
|
|
|
|
|
|
Method New()
|
|
Method New()
|
|
@@ -14,7 +54,7 @@ Class World
|
|
Local solver:=New btSequentialImpulseConstraintSolver()
|
|
Local solver:=New btSequentialImpulseConstraintSolver()
|
|
|
|
|
|
_btworld=New btDiscreteDynamicsWorld( dispatcher,broadphase,solver,config )
|
|
_btworld=New btDiscreteDynamicsWorld( dispatcher,broadphase,solver,config )
|
|
-
|
|
|
|
|
|
+
|
|
Gravity=New Vec3f( 0,-9.81,0 )
|
|
Gravity=New Vec3f( 0,-9.81,0 )
|
|
|
|
|
|
End
|
|
End
|
|
@@ -44,6 +84,35 @@ Class World
|
|
|
|
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method RayCast:RaycastResult( rayFrom:Vec3f,rayTo:Vec3f )
|
|
|
|
+
|
|
|
|
+ Local btresult:=New btCollisionWorld.ClosestRayResultCallback( rayFrom,rayTo )
|
|
|
|
+
|
|
|
|
+ _btworld.rayTest( rayFrom,rayTo,Cast<btCollisionWorld.RayResultCallback Ptr>( Varptr btresult ) )
|
|
|
|
+
|
|
|
|
+ If Not btresult.hasHit() Return Null
|
|
|
|
+
|
|
|
|
+ Return New RaycastResult( btresult )
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Method ConvexSweep:RaycastResult( collider:ConvexCollider,castFrom:AffineMat4f,castTo:AffineMat4f )
|
|
|
|
+
|
|
|
|
+ Local btresult:=New btCollisionWorld.ClosestConvexResultCallback( castFrom.t,castTo.t )
|
|
|
|
+
|
|
|
|
+ _btworld.convexSweepTest( Cast<btConvexShape>( collider.btShape ),castFrom,castTo,Cast<btCollisionWorld.ConvexResultCallback Ptr>( Varptr btresult ),0 )
|
|
|
|
+
|
|
|
|
+ If Not btresult.hasHit() Return Null
|
|
|
|
+
|
|
|
|
+ Return New RaycastResult( btresult )
|
|
|
|
+
|
|
|
|
+ End
|
|
|
|
+
|
|
|
|
+ Method ConvexSweep:RaycastResult( collider:ConvexCollider,castFrom:Vec3f,castTo:Vec3f )
|
|
|
|
+
|
|
|
|
+ Return ConvexSweep( collider,AffineMat4f.Translation( castFrom ),AffineMat4f.Translation( castTo ) )
|
|
|
|
+
|
|
|
|
+ End
|
|
|
|
+
|
|
Function GetDefault:World()
|
|
Function GetDefault:World()
|
|
|
|
|
|
Global _default:=New World
|
|
Global _default:=New World
|
|
@@ -51,13 +120,15 @@ Class World
|
|
Return _default
|
|
Return _default
|
|
End
|
|
End
|
|
|
|
|
|
- '***** INTERNAL *****
|
|
|
|
-
|
|
|
|
|
|
+ Internal
|
|
|
|
+
|
|
Method Add( body:RigidBody )
|
|
Method Add( body:RigidBody )
|
|
|
|
|
|
_bodies.Add( body )
|
|
_bodies.Add( body )
|
|
|
|
|
|
- _btworld.addRigidBody( body.btBody )
|
|
|
|
|
|
+ _btworld.addRigidBody( body.btBody,body.CollisionGroup,body.CollisionMask )
|
|
|
|
+
|
|
|
|
+ body.btBody.setUserPointer( object_to_handle( body ) )
|
|
End
|
|
End
|
|
|
|
|
|
Method Remove( body:RigidBody )
|
|
Method Remove( body:RigidBody )
|
|
@@ -65,8 +136,10 @@ Class World
|
|
_bodies.Remove( body )
|
|
_bodies.Remove( body )
|
|
|
|
|
|
_btworld.removeRigidBody( body.btBody )
|
|
_btworld.removeRigidBody( body.btBody )
|
|
|
|
+
|
|
|
|
+ body.btBody.setUserPointer( Null )
|
|
End
|
|
End
|
|
-
|
|
|
|
|
|
+
|
|
Private
|
|
Private
|
|
|
|
|
|
Field _btworld:btDynamicsWorld
|
|
Field _btworld:btDynamicsWorld
|