Browse Source

An implementation of btMotionState is required for kineamtic bodies.

enn0x 14 years ago
parent
commit
5bea667a74
2 changed files with 38 additions and 1 deletions
  1. 22 1
      panda/src/bullet/bulletRigidBodyNode.cxx
  2. 16 0
      panda/src/bullet/bulletRigidBodyNode.h

+ 22 - 1
panda/src/bullet/bulletRigidBodyNode.cxx

@@ -34,7 +34,7 @@ BulletRigidBodyNode(const char *name) : BulletBodyNode(name) {
   btVector3 inertia(0, 0, 0);
 
   // Motion state and construction info
-  btDefaultMotionState *motion = new btDefaultMotionState();
+  MotionState *motion = new MotionState(_sync);
   btRigidBody::btRigidBodyConstructionInfo ci(mass, motion, _shape, inertia);
 
   // Additional damping
@@ -451,3 +451,24 @@ set_angular_factor(const LVector3f &factor) {
   _rigid->setAngularFactor(LVecBase3f_to_btVector3(factor));
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: BulletRigidBodyNode::MotionState::getWorldTransform
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void BulletRigidBodyNode::MotionState::
+getWorldTransform(btTransform &trans) const {
+
+  trans = TransformState_to_btTrans(_sync);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletRigidBodyNode::MotionState::setWorldTransform
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void BulletRigidBodyNode::MotionState::
+setWorldTransform(const btTransform &trans) {
+
+}
+

+ 16 - 0
panda/src/bullet/bulletRigidBodyNode.h

@@ -91,6 +91,22 @@ protected:
 private:
   virtual void shape_changed();
 
+  // The motion state is required only for kinematic bodies.
+  // For kinematic nodies getWorldTransform is called each frame, and
+  // should return the current world transform of the node.
+  class MotionState : public btMotionState {
+
+  public:
+    MotionState(CPT(TransformState) & sync) : _sync(sync) {};
+    ~MotionState() {};
+
+    virtual void getWorldTransform(btTransform &trans) const;
+    virtual void setWorldTransform(const btTransform &trans);
+
+  private:
+    CPT(TransformState) &_sync;
+  };
+
   CPT(TransformState) _sync;
   bool _sync_disable;