Panda3D
 All Classes Functions Variables Enumerations
bulletRigidBodyNode.h
00001 // Filename: bulletRigidBodyNode.h
00002 // Created by:  enn0x (19Nov10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef __BULLET_RIGID_BODY_NODE_H__
00016 #define __BULLET_RIGID_BODY_NODE_H__
00017 
00018 #include "pandabase.h"
00019 
00020 #include "bullet_includes.h"
00021 #include "bullet_utils.h"
00022 #include "bulletBodyNode.h"
00023 
00024 #include "pandaNode.h"
00025 #include "collideMask.h"
00026 
00027 class BulletShape;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : BulletRigidBodyNode
00031 // Description : 
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_PANDABULLET BulletRigidBodyNode : public BulletBodyNode {
00034 
00035 PUBLISHED:
00036   BulletRigidBodyNode(const char *name="rigid");
00037   INLINE ~BulletRigidBodyNode();
00038 
00039   // Mass & inertia
00040   void set_mass(PN_stdfloat mass);
00041   PN_stdfloat get_mass() const;
00042   void set_inertia(const LVecBase3 &inertia);
00043   LVector3 get_inertia() const;
00044 
00045   // Velocity
00046   LVector3 get_linear_velocity() const;
00047   LVector3 get_angular_velocity() const;
00048   void set_linear_velocity(const LVector3 &velocity);
00049   void set_angular_velocity(const LVector3 &velocity);
00050 
00051   // Damping
00052   INLINE PN_stdfloat get_linear_damping() const;
00053   INLINE PN_stdfloat get_angular_damping() const;
00054   INLINE void set_linear_damping(PN_stdfloat value);
00055   INLINE void set_angular_damping(PN_stdfloat value);
00056 
00057   // Forces
00058   void clear_forces();
00059   void apply_force(const LVector3 &force, const LPoint3 &pos);
00060   void apply_central_force(const LVector3 &force);
00061   void apply_impulse(const LVector3 &impulse, const LPoint3 &pos);
00062   void apply_central_impulse(const LVector3 &impulse);
00063   void apply_torque(const LVector3 &torque);
00064   void apply_torque_impulse(const LVector3 &torque);
00065 
00066   // Deactivation thresholds
00067   PN_stdfloat get_linear_sleep_threshold() const;
00068   PN_stdfloat get_angular_sleep_threshold() const;
00069   void set_linear_sleep_threshold(PN_stdfloat threshold);
00070   void set_angular_sleep_threshold(PN_stdfloat threshold);
00071 
00072   // Gravity
00073   void set_gravity(const LVector3 &gravity);
00074   LVector3 get_gravity() const;
00075 
00076   // Restrict movement
00077   void set_linear_factor(const LVector3 &factor);
00078   void set_angular_factor(const LVector3 &factor);
00079 
00080 public:
00081   virtual btCollisionObject *get_object() const;
00082 
00083   virtual void output(ostream &out) const;
00084 
00085   void sync_p2b();
00086   void sync_b2p();
00087 
00088 protected:
00089   virtual void transform_changed();
00090 
00091 private:
00092   virtual void shape_changed();
00093 
00094   // The motion state is required only for kinematic bodies.
00095   // For kinematic nodies getWorldTransform is called each frame, and
00096   // should return the current world transform of the node.
00097   class MotionState : public btMotionState {
00098 
00099   public:
00100     MotionState(CPT(TransformState) & sync) : _sync(sync) {};
00101     ~MotionState() {};
00102 
00103     virtual void getWorldTransform(btTransform &trans) const;
00104     virtual void setWorldTransform(const btTransform &trans);
00105 
00106   private:
00107     CPT(TransformState) &_sync;
00108   };
00109 
00110   CPT(TransformState) _sync;
00111   bool _sync_disable;
00112 
00113   btRigidBody *_rigid;
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 public:
00117   static TypeHandle get_class_type() {
00118     return _type_handle;
00119   }
00120   static void init_type() {
00121     BulletBodyNode::init_type();
00122     register_type(_type_handle, "BulletRigidBodyNode", 
00123                   BulletBodyNode::get_class_type());
00124   }
00125   virtual TypeHandle get_type() const {
00126     return get_class_type();
00127   }
00128   virtual TypeHandle force_init_type() {
00129     init_type();
00130     return get_class_type();
00131   }
00132 
00133 private:
00134   static TypeHandle _type_handle;
00135 };
00136 
00137 #include "bulletRigidBodyNode.I"
00138 
00139 #endif // __BULLET_RIGID_BODY_NODE_H__
00140 
 All Classes Functions Variables Enumerations