Guest User

Bullet Physics Basic Wrapper

a guest
May 7th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include "clVector3.h"
  2. #include "btBulletDynamicsCommon.h"
  3.  
  4. template<typename T> class clList;
  5. template<typename T> struct clMatrix4x4; using clMat4 = clMatrix4x4<float>;
  6. template<typename T> struct clQuaternion; using clQuat = clQuaternion<float>;
  7.  
  8. class clBulletPhysicsObject
  9. {
  10. public:
  11.   clBulletPhysicsObject(btCollisionObject *pObject, btDiscreteDynamicsWorld *pWorld);
  12.  
  13.   clVec3 Position() const;
  14.   void SetPosition(const clVec3 &pos);
  15.   clVec3 Velocity() const;
  16.   void SetVelocity(const clVec3 &vel);
  17.   clMat4 ModelMatrix() const;
  18.   clQuat Orientation() const;
  19.   void ApplyForce(const clVec3 &force, const clVec3 &offset = clVec3::Zero());
  20.   void SetCanSleep(const bool &canSleep = true);
  21.   void Destroy();
  22.  
  23. private:
  24.   btCollisionObject *m_pObject;
  25.   btDiscreteDynamicsWorld *m_pWorld;
  26.   clList<clByteList> m_meshDataBlocks;
  27. };
  28.  
  29. class clBulletPhysicsScene
  30. {
  31. public:
  32.   clBulletPhysicsScene(clVec3 gravity = clVec3{ 0, 0, -1 });
  33.   ~clBulletPhysicsScene();
  34.  
  35.   bool RayCast(const clVec3 &start, const clVec3 &end, clVec3 *pHitLocation = nullptr);
  36.   void Update(const float &timeStep = 1.f / 60.f, const int &maxSubSteps = 10, const float &fixedTimeStep = 0.0005);
  37.  
  38.   clBulletPhysicsObject* AddSphere(const clVec3 &position, const float &radius, const float &mass);
  39.   clBulletPhysicsObject* AddBox(const clVec3 &position, const clVec3 &dimensions, const float &mass);
  40.   clBulletPhysicsObject* AddMesh(const clVec3 &position, const clList<clVec3> &verts, const float &mass);
  41.  
  42. private:
  43.   btDiscreteDynamicsWorld *m_pWorld;
  44.   btCollisionDispatcher *m_pDispatcher;
  45.   btDbvtBroadphase m_overlappingPairsCache;
  46.   btSequentialImpulseConstraintSolver m_solver;
  47.   btDefaultCollisionConfiguration *m_pCollisionConfiguration;
  48. };
  49.  
Add Comment
Please, Sign In to add comment