Physics.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /******************************************************************************
  2. Use 'Physics' to create and manage physical scene parameters and general manipulation.
  3. These include:
  4. -collision detection
  5. -ray testing
  6. -sweeping
  7. -setting physical material parameters
  8. -gravity
  9. -skin width
  10. -continuous collision detection
  11. -physics precision
  12. -timestep modes
  13. -other scene parameters
  14. /******************************************************************************/
  15. enum CONTROLLER_SLOPE_SLIDING_MODE : Byte // handling the character controller slope sliding issue
  16. {
  17. CSS_NONE , // nothing is done in this case
  18. CSS_MATERIALS, // Character Controllers will switch their actor material depending whether the character is moving or standing, between 'Physics.mtrl_ctrl' <-> 'Physics.mtrl_ctrl_stop', which have different frictions
  19. CSS_GRAVITY , // Character Controllers will disable their gravity when standing still on ground, not recommended when character weight should affect objects underneath
  20. CSS_FREEZE_XZ, // Character Controllers will disable their xz movement when standing still on ground, not recommended when character needs to be pushed by other objects
  21. };
  22. /******************************************************************************/
  23. enum PHYS_TIMESTEP_MODE : Byte // Physics timestep updating modes
  24. {
  25. PHYS_TIMESTEP_ROUND , // physics timesteps will be rounded to a constant value, this results in more stable and reproducible simulation
  26. PHYS_TIMESTEP_VARIABLE, // physics timesteps are taken from frame time deltas , this results in more smooth but less stable simulation
  27. PHYS_TIMESTEP_NUM , // number of physics timestep modes
  28. };
  29. /******************************************************************************/
  30. enum PHYS_ENGINE // Physics Engine
  31. {
  32. PHYS_ENGINE_PHYSX , // PhysX
  33. PHYS_ENGINE_BULLET, // Bullet
  34. };
  35. /******************************************************************************/
  36. enum PHYS_CONTACT // Physics Contact
  37. {
  38. CONTACT_NEW , // new contact was found
  39. CONTACT_KEEP, // contact persists
  40. CONTACT_LOST, // contact was lost
  41. };
  42. /******************************************************************************/
  43. struct ActorInfo // Actor Information
  44. {
  45. Bool collision, // if this actor should collide with other actors in the world
  46. dynamic ; // actor is dynamic (not static and not kinematic)
  47. Int group ; // actor collision group (ACTOR_GROUP)
  48. Ptr user, obj; // actor user data and object pointer
  49. #if EE_PRIVATE
  50. void set(PHYS_API(PxShape, RigidBody) *actor);
  51. #endif
  52. ActorInfo() {collision=dynamic=false; group=0; user=obj=null; _actor=null;}
  53. #if !EE_PRIVATE
  54. private:
  55. #endif
  56. #if EE_PRIVATE
  57. PHYS_API(PxRigidActor, RigidBody) *_actor;
  58. #else
  59. Ptr _actor;
  60. #endif
  61. };
  62. /******************************************************************************/
  63. struct PhysHitBasic // Physics Hit, contains information about physical collision
  64. {
  65. Int face ; // face index, this index will point to the original face of the source mesh only if the physical body was created with 'keep_face_indexes' parameter set to true, otherwise this will point to an internal face index of the physical body
  66. Flt frac , // fraction of the movement on which collision occurred (0..1)
  67. dist ; // distance travelled until collision occurred (0..move.length())
  68. Vec face_nrm; // face normal (if face index is known then it's set to face normal in world space, otherwise it's set to 'plane.normal')
  69. Plane plane ; // contact plane (position and normal)
  70. #if EE_PRIVATE
  71. #if PHYSX
  72. void set (C PxLocationHit &hit , Flt move_length);
  73. void updateFace(C PxTriangleMeshGeometry &mesh, C Matrix3 *orn );
  74. #endif
  75. #endif
  76. };
  77. struct PhysHit : PhysHitBasic, ActorInfo // Physics Hit, contains information about physical collision
  78. {
  79. #if EE_PRIVATE
  80. #if PHYSX
  81. void set(C PxLocationHit &hit, Flt move_length);
  82. #endif
  83. #endif
  84. };
  85. /******************************************************************************/
  86. struct PhysContact // Physics contact, contains information about physical contact
  87. {
  88. Vec pos , // world space position
  89. normal, // world space normal
  90. force ; // world space force
  91. };
  92. /******************************************************************************/
  93. struct PhysCutsCallback // Physical Cuts Test Callback interface
  94. {
  95. virtual Bool hit(ActorInfo &actor_info)=NULL; // you should override this method, it will receive information about the contacts, you should return false if you no longer want to check any more contacts, and true to continue checking, creating or deleting physical objects inside callbacks is forbidden, instead you should record information about contacts, and perform operations on them outside of the callback, contacts are not listed in any specific order
  96. };
  97. struct PhysHitCallback // Physical Ray/Sweep Test Callback interface
  98. {
  99. virtual Bool hit(PhysHit &phys_hit)=NULL; // you should override this method, it will receive information about the contacts, you should return false if you no longer want to check any more contacts, and true to continue checking, creating or deleting physical objects inside callbacks is forbidden, instead you should record information about contacts, and perform operations on them outside of the callback, contacts are not listed in any specific order (do not assume that they are sorted from nearest to furthest)
  100. };
  101. /******************************************************************************/
  102. struct PhysicsClass
  103. {
  104. UInt ctrl_ground_group_force , // controller force ground group (ACTOR_GROUP) bit combination, this is a bit combination of all actor groups that will always be walkable by character controllers even with high slope angles, default="0" (none)
  105. ctrl_ground_group_allow , // controller allowed ground group (ACTOR_GROUP) bit combination, this is a bit combination of all actor groups that will be walkable by character controllers with correct slope angles, default="~IndexToFlag(AG_CONTROLLER)" (everything except Controllers)
  106. ctrl_slide_group_horizontal; // controller horizontal slide group (ACTOR_GROUP) bit combination, this is a bit combination of all actor groups that will be slided against only in horizontal mode , default=" IndexToFlag(AG_CONTROLLER)" ( Controllers)
  107. Flt ctrl_ground_slope ; // controller ground slope (0..1) , this factor determines what slope angles are still walkable by character controllers, default=0.65
  108. PhysMtrl mtrl_default , // default material for all 'Actor' objects
  109. mtrl_ctrl , // default material for all 'Controller' objects
  110. mtrl_ctrl_stop; // default material for all 'Controller' objects when they are not moving and 'Physics' was initialized with 'CSS_MATERIALS' parameter
  111. void (*simulation_step_completed)(); // pointer to a custom callback (can be null) called each time a single simulation step has completed, this can be called 0, 1 or multiple times between a call to 'startSimulation' and 'stopSimulation', each call will be made on the main thread, amount of calls depends on 'dt' parameter used in 'startSimulation', 'precision' and 'timestep'.
  112. // manage
  113. PhysicsClass& create (C Str &physx_dll_path=S, CONTROLLER_SLOPE_SLIDING_MODE css=CSS_MATERIALS, Bool hardware=false); // create, 'physx_dll_path'=path to look for physx DLL files (if empty then DLL's will be searched in 'CurDir', this parameter is needed only for Windows platform, on Linux platform Physx Shared Libraries are always expected to be in the "Bin" folder relative to app file, on other platforms it's ignored), 'hardware'=if use hardware physics simulations (on GPU), if it's not available or 'hardware' is set to false then CPU will be used, Exit on fail
  114. Bool createTry(C Str &physx_dll_path=S, CONTROLLER_SLOPE_SLIDING_MODE css=CSS_MATERIALS, Bool hardware=false); // create, 'physx_dll_path'=path to look for physx DLL files (if empty then DLL's will be searched in 'CurDir', this parameter is needed only for Windows platform, on Linux platform Physx Shared Libraries are always expected to be in the "Bin" folder relative to app file, on other platforms it's ignored), 'hardware'=if use hardware physics simulations (on GPU), if it's not available or 'hardware' is set to false then CPU will be used, false on fail
  115. // get / set
  116. Bool created ()C; // if physics has been created
  117. Bool updated ()C {return _updated ;} // if physics simulation has been updated during last simulation. This value is valid after calling 'stopSimulation'. This may be false if you use 'PHYS_TIMESTEP_ROUND' and requested simulation time didn't exceed minimum required value
  118. Flt updatedTime ()C {return _updated_time;} // get actual amount of physics simulation time which has been performed during all steps of last simulation. This value is valid after calling 'stopSimulation'. When 'PHYS_TIMESTEP_ROUND' is used, the returned value will always be a multiple of a constant value based on the 'precision', for 'PHYS_TIMESTEP_VARIABLE' the returned value will be equal to 'dt' parameter used for 'startSimulation'. This value is equal to the sum of all 'stepTime' for each simulation step that occurred in the last simulation.
  119. Flt stepTime ()C {return _step_time;} // get actual amount of physics simulation time which has been performed during a single step of last simulation. This value is valid after calling 'startSimulation'. It's equal to 'updatedTime' divided by number of simulation steps. To get simulated time for all steps in a simulation, please use 'updatedTime'.
  120. Flt time ()C {return _time;} // get actual amount of physics simulation time which has been performed during a single or all steps of last simulation. This value is valid after calling 'stopSimulation' and during 'simulation_step_completed'. It's set to 'stepTime' during 'simulation_step_completed' and to 'updatedTime' when outside 'simulation_step_completed'.
  121. Flt cpuTime ()C {return _cpu_time;} // get amount of CPU time on the main thread which was needed to perform last simulation. This value is valid after calling 'stopSimulation'. You can use this method to know how much CPU time on the main thread was required to perform the last simulation. Simulation can also take time on other threads, however that time is not measured.
  122. Bool hw ()C {return _hw ;} // if physics is simulated in the hardware
  123. PhysicsClass& skin ( Flt skin ); Flt skin ()C {return _skin ;} // set/get physics skin width (allowed object interpenetration), default=0.005 (changing this value will not affect actors that are already created, in order to have one global skin value, please call this function after physics creation and before any actor creation)
  124. PhysicsClass& gravity (C Vec &gravity ); C Vec& gravity ()C {return _gravity ;} // set/get gravity acceleration , default=(0, -9.8, 0)
  125. PhysicsClass& precision( Int steps_ps); Int precision ()C {return _precision ;} // set/get number of desired simulation steps per second , default=60 (setting precision to zero forces usage of screen refresh rate)
  126. PhysicsClass& timestep (PHYS_TIMESTEP_MODE mode ); PHYS_TIMESTEP_MODE timestep ()C {return _timestep ;} // set/get physics time stepping mode , default=PHYS_TIMESTEP_ROUND
  127. PHYS_ENGINE engine ()C; // get physics engine which is available in current build
  128. UInt collisionGroups(Byte group)C; // get bit combination of ACTOR_GROUP that collide with 'group' ACTOR_GROUP
  129. #if EE_PRIVATE
  130. Flt minShapeRadius()C {return _skin*4;}
  131. Flt minCapsuleEdge()C {return 0.01f ;}
  132. Int actorShapes ()C; // get number of actor shapes in world
  133. #endif
  134. // if shape cuts with any actor on the scene, 'groups'=group flag (ACTOR_GROUP) bit combination specifying which groups should be included in testing, use 'IndexToFlag' function
  135. static Bool cuts(C Box &box , UInt groups=~0);
  136. static Bool cuts(C OBox &obox , UInt groups=~0);
  137. static Bool cuts(C Ball &ball , UInt groups=~0);
  138. static Bool cuts(C Capsule &capsule, UInt groups=~0);
  139. static Bool cuts(C Shape &shape , UInt groups=~0); // only SHAPE_BOX, SHAPE_OBOX, SHAPE_BALL, SHAPE_CAPSULE shape types are supported
  140. // if shape cuts with any actor on the scene, 'callback' will be used for every contact check, 'groups'=group flag (ACTOR_GROUP) bit combination specifying which groups should be included in testing, use 'IndexToFlag' function, contacts are not listed in any specific order
  141. static void cuts(C Box &box , PhysCutsCallback &callback, UInt groups=~0);
  142. static void cuts(C OBox &obox , PhysCutsCallback &callback, UInt groups=~0);
  143. static void cuts(C Ball &ball , PhysCutsCallback &callback, UInt groups=~0);
  144. static void cuts(C Capsule &capsule, PhysCutsCallback &callback, UInt groups=~0);
  145. static void cuts(C Shape &shape , PhysCutsCallback &callback, UInt groups=~0); // only SHAPE_BOX, SHAPE_OBOX, SHAPE_BALL, SHAPE_CAPSULE shape types are supported
  146. // if ray cuts with any actor on the scene, 'groups'=group flag (ACTOR_GROUP) bit combination specifying which groups should be included in testing, use 'IndexToFlag' function
  147. static Bool ray(C Vec &pos, C Vec &move, PhysHit *phys_hit=null, UInt groups=~0); // 'phys_hit'=optionally pass pointer to 'PhysHit' class to receive additional data about the nearest contact
  148. static void ray(C Vec &pos, C Vec &move, PhysHitCallback &callback , UInt groups=~0); // 'callback' will be used for every contact check, contacts are not listed in any specific order (do not assume that they are sorted from nearest to furthest)
  149. // if shape hits something on 'move' way, 'phys_hit'=optionally pass pointer to 'PhysHit' class to receive additional data about the nearest contact, 'groups'=group flag (ACTOR_GROUP) bit combination specifying which groups should be included in testing, use 'IndexToFlag' function
  150. static Bool sweep(C Box &box , C Vec &move, PhysHit *phys_hit=null, UInt groups=~0);
  151. static Bool sweep(C OBox &obox , C Vec &move, PhysHit *phys_hit=null, UInt groups=~0);
  152. static Bool sweep(C Ball &ball , C Vec &move, PhysHit *phys_hit=null, UInt groups=~0);
  153. static Bool sweep(C Capsule &capsule, C Vec &move, PhysHit *phys_hit=null, UInt groups=~0);
  154. static Bool sweep(C Shape &shape , C Vec &move, PhysHit *phys_hit=null, UInt groups=~0); // only SHAPE_BOX, SHAPE_OBOX, SHAPE_BALL, SHAPE_CAPSULE shape types are supported
  155. // if shape hits something on 'move' way, 'callback' will be used for every contact check, 'groups'=group flag (ACTOR_GROUP) bit combination specifying which groups should be included in testing, use 'IndexToFlag' function, contacts are not listed in any specific order (do not assume that they are sorted from nearest to furthest)
  156. static void sweep(C Box &box , C Vec &move, PhysHitCallback &callback, UInt groups=~0);
  157. static void sweep(C OBox &obox , C Vec &move, PhysHitCallback &callback, UInt groups=~0);
  158. static void sweep(C Ball &ball , C Vec &move, PhysHitCallback &callback, UInt groups=~0);
  159. static void sweep(C Capsule &capsule, C Vec &move, PhysHitCallback &callback, UInt groups=~0);
  160. static void sweep(C Shape &shape , C Vec &move, PhysHitCallback &callback, UInt groups=~0); // only SHAPE_BOX, SHAPE_OBOX, SHAPE_BALL, SHAPE_CAPSULE shape types are supported
  161. // move shape by 'move' way, if shape encounters an obstacle along the way it will be stopped at contact point, 'groups'=group flag (ACTOR_GROUP) bit combination specifying which groups should be included in testing, use 'IndexToFlag' function
  162. static void move(Box &box , C Vec &move, UInt groups=~0);
  163. static void move(OBox &obox , C Vec &move, UInt groups=~0);
  164. static void move(Ball &ball , C Vec &move, UInt groups=~0);
  165. static void move(Capsule &capsule, C Vec &move, UInt groups=~0);
  166. static void move(Shape &shape , C Vec &move, UInt groups=~0); // only SHAPE_BOX, SHAPE_OBOX, SHAPE_BALL, SHAPE_CAPSULE shape types are supported
  167. // operations
  168. PhysicsClass& ignore(Int group_a, Int group_b, Bool ignore=true); // ignore collisions between 'group_a' and 'group_b' actor group pairs (ACTOR_GROUP)
  169. PhysicsClass& reportContact(Int group_a, Int group_b, Bool report=true ); // allow contact reporting between 'group_a' and 'group_b' actor group pairs (ACTOR_GROUP), this will enable calling 'ReportContact' function which can be specified in 'reportContact' method
  170. PhysicsClass& reportContact(void (*ReportContact)(ActorInfo &actor_a, ActorInfo &actor_b, C PhysContact *contact, Int contacts)); // set custom function for reporting physical contacts, this function will be called for actor group pairs that have been enabled using the 'reportContact' method, 'ReportContact' function will be called during physical contacts between actors in physical simulation, this function will not be called if the actors aren't in contact or have their collisions disabled or are asleep, creating or deleting physical objects inside callbacks is forbidden, instead you should record information about contacts, and perform operations on them outside of the callback, 'contact'=array of contacts, 'contacts'=number of elements in 'contact' array
  171. PhysicsClass& reportTrigger(void (*ReportTrigger)(ActorInfo &trigger, ActorInfo &actor, PHYS_CONTACT contact)); // set custom function for reporting trigger events, this function will be called for actors (with enabled 'Actor::trigger') when they collide with other actors, creating or deleting physical objects inside callbacks is forbidden, instead you should record information about contacts, and perform operations on them outside of the callback
  172. PhysicsClass& wheelFriction(Flt (*WheelFriction)(C PhysMtrl &ground_material, C PhysMtrl &wheel_material, C ActorInfo &vehicle, WHEEL_TYPE wheel)); // set custom function for calculating vehicle wheel friction with ground depending on given parameters, this function will be called when vehicle wheels will be in contact with any physical surface, you should return friction value (in range 0..Inf), where 0=no friction, 1=good friction, set null for default function (always returning friction of 1)
  173. PhysicsClass& dominance(Int dominance_a, Int dominance_b, Bool a_factor, Bool b_factor); // set dominance constraints factors, 'dominance_a'=dominance index (0..31), 'dominance_b'=dominance index (0..31), 'a_factor'=how much actors of 'dominance_a' index are affected by actors of 'dominance_b' index (factor in range 0..1), 'b_factor'=how much actors of 'dominance_b' index are affected by actors of 'dominance_a' index (factor in range 0..1), this allows for specifying one-way interactions between different actor dominance groups
  174. // simulation
  175. PhysicsClass& startSimulation(Flt dt=Time.d()); // start physics simulation !! on Bullet engine you may not perform any changes in physics between startSimulation() and stopSimulation(), this includes actor creation/removal, modifying parameters, etc. this does not apply to PhysX !! each simulation can be divided into 0, 1 or multiple simulation steps, amount of simulation steps depends on 'dt' parameter, 'timestep' and 'precision'. To get notified about when each simulation step completed, please use the 'simulation_step_completed' callback. Simulation may be performed on secondary threads.
  176. PhysicsClass& stopSimulation( ); // get results of simulation !! on Bullet engine you may not perform any changes in physics between startSimulation() and stopSimulation(), this includes actor creation/removal, modifying parameters, etc. this does not apply to PhysX !! this method waits until the last simulation has completed.
  177. // draw
  178. void draw(); // draw all actors, this can be optionally called outside of Render function
  179. #if EE_PRIVATE
  180. static Bool ignored (PHYS_API(PxRigidActor, RigidBody) &a, PHYS_API(PxRigidActor, RigidBody) &b); // if 'a' and 'b' actors are ignoring each other (based on Actor::ignore)
  181. Bool collides (Byte a, Byte b)C {return FlagTest(_collision_array[a], 1<<b);} // if 'a' can collide with 'b' ACTOR_GROUP
  182. Bool collidesMask (Byte a, UInt m)C {return FlagTest( m , 1<<a);} // if 'a' can collide with 'm' ACTOR_GROUP mask
  183. Bool reports (Byte a, Byte b)C {return _contact_report [a][b] ;} // if 'a' reports contacts with 'b' ACTOR_GROUP
  184. Bool createMaterials();
  185. void step ();
  186. void stepCompleted ();
  187. #endif
  188. void del(); // manually release physics and its DLL file usage, normally you don't need to call this as the engine will call this automatically
  189. #if !EE_PRIVATE
  190. private:
  191. #endif
  192. Bool _hw, _simulated, _updated, _new_updated, _last_updated, _contact_report[32][32];
  193. Int _precision, _actual_precision, _step_left;
  194. UInt _update_count, _collision_array[32];
  195. Flt _skin, _cpu_time, _new_cpu_time, _updated_time, _new_updated_time, _last_updated_time, _prec_time, _accumulated_time, _step_time, _time;
  196. Vec _gravity;
  197. ReadWriteSync _rws;
  198. CONTROLLER_SLOPE_SLIDING_MODE _css;
  199. PHYS_TIMESTEP_MODE _timestep;
  200. void (*_report_contact)(ActorInfo &actor_a, ActorInfo &actor_b, C PhysContact *contact, Int contacts);
  201. void (*_report_trigger)(ActorInfo &trigger, ActorInfo &actor, PHYS_CONTACT contact);
  202. Flt (*_wheel_friction)(C PhysMtrl &ground_material, C PhysMtrl &wheel_material, C ActorInfo &vehicle, WHEEL_TYPE wheel);
  203. Memc<Vehicle*> _vehicles;
  204. PhysicsClass();
  205. }extern
  206. Physics; // !! Physics needs to be manually created !!
  207. /******************************************************************************/
  208. #if EE_PRIVATE
  209. #if PHYSX
  210. struct PhysxClass
  211. {
  212. #define MAX_ACTOR_IGNORE_SHIFT 10
  213. #define MAX_ACTOR_IGNORE (1<<MAX_ACTOR_IGNORE_SHIFT)
  214. STRUCT(AllocatorCallback , PxDefaultAllocator)
  215. //{
  216. virtual void* allocate(size_t size, const char* typeName, const char* filename, int line)override;
  217. virtual void deallocate(void* ptr)override;
  218. };
  219. static Vec vec (C PxVec3 &v ) {return Vec (v.x, v.y, v.z);}
  220. static PxVec3 vec (C Vec &v ) {return PxVec3 (v.x, v.y, v.z);}
  221. static Box box (C PxBounds3 &box ) {return Box (vec(box.minimum), vec(box.maximum));}
  222. static PxBounds3 box (C Box &box ) {return PxBounds3(vec(box.min ), vec(box.max ));}
  223. static Matrix matrix(C PxTransform &matrix);
  224. static PxTransform matrix(C Matrix &matrix);
  225. static Matrix3 orn (C PxQuat &quat );
  226. static Matrix3 orn (C PxMat33 &mat );
  227. static PxQuat orn (C Matrix3 &matrix);
  228. void del ();
  229. Bool create(Str dll_path, Bool hardware);
  230. void updateVehicles();
  231. INLINE Byte& ignoreMap(UInt a, UInt b) {return ignore_map[a + ((b>>3)<<MAX_ACTOR_IGNORE_SHIFT)];}
  232. Int _mem_leaks;
  233. PxFoundation *foundation;
  234. PxPhysics *physics;
  235. PxCooking *cook[2];
  236. PxScene *world;
  237. AllocatorCallback allocator;
  238. Mems<Byte> ignore_map;
  239. IDGenerator ignore_id_gen;
  240. #define SUPPORT_PHYSX_VEHICLE 0
  241. #if SUPPORT_PHYSX_VEHICLE
  242. IDGenerator vehicle_id_gen;
  243. PhysPart wheel_mesh;
  244. PxRaycastQueryResult raycast_query_result[4];
  245. PxRaycastHit raycast_hit [4];
  246. PxBatchQuery *batch_query_4;
  247. Memc<PxVehicleDrive4W*> vehicles;
  248. #endif
  249. #if PHYSX_DLL_ACTUAL
  250. DLL PhysX3, PhysXCommon, PhysXCooking, PhysXFoundation;
  251. Ptr raycast;
  252. #endif
  253. PhysxClass()
  254. {
  255. foundation=null; physics=null; cook[0]=cook[1]=null; world=null; _mem_leaks=0;
  256. #if SUPPORT_PHYSX_VEHICLE
  257. batch_query_4=null;
  258. #endif
  259. #if PHYSX_DLL_ACTUAL
  260. raycast=null;
  261. #endif
  262. }
  263. NO_COPY_CONSTRUCTOR(PhysxClass);
  264. }extern
  265. Physx;
  266. void DrawConvex(PxConvexMesh &convex, C Color &color=WHITE, Bool fill=false);
  267. void DrawMesh (PxTriangleMesh &mesh , C Color &color=WHITE, Bool fill=false);
  268. #else
  269. struct BulletClass
  270. {
  271. static Vec vec (C btVector3 &v) {return Vec (v.x(), v.y(), v.z());}
  272. static btVector3 vec (C Vec &v) {return btVector3(v.x , v.y , v.z );}
  273. static Matrix3 matrix(C btMatrix3x3 &t);
  274. static Matrix matrix(C btTransform &t);
  275. static btMatrix3x3 matrix(C Matrix3 &m);
  276. static btTransform matrix(C Matrix &m);
  277. void del ();
  278. Bool create();
  279. btDefaultCollisionConfiguration *collision_config;
  280. btCollisionDispatcher *dispatcher;
  281. btBroadphaseInterface *broadphase;
  282. btConstraintSolver *solver;
  283. btDynamicsWorld *world;
  284. Memc<btTypedConstraint*> breakables;
  285. BulletClass() {collision_config=null; dispatcher=null; broadphase=null; solver=null; world=null;}
  286. NO_COPY_CONSTRUCTOR(BulletClass);
  287. }extern
  288. Bullet;
  289. void DrawConvex(btConvexHullShape &convex, C Color &color=WHITE, Bool fill=false);
  290. void DrawMesh (btBvhTriangleMeshShape &mesh , C Color &color=WHITE, Bool fill=false);
  291. #endif
  292. void DrawPhys(C MeshBase &base, C Color &color=WHITE, Bool fill=false);
  293. #endif
  294. /******************************************************************************/