Panda3D
 All Classes Functions Variables Enumerations
bulletRigidBodyNode.h
1 // Filename: bulletRigidBodyNode.h
2 // Created by: enn0x (19Nov10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef __BULLET_RIGID_BODY_NODE_H__
16 #define __BULLET_RIGID_BODY_NODE_H__
17 
18 #include "pandabase.h"
19 
20 #include "bullet_includes.h"
21 #include "bullet_utils.h"
22 #include "bulletBodyNode.h"
23 
24 #include "pandaNode.h"
25 #include "collideMask.h"
26 
27 class BulletShape;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : BulletRigidBodyNode
31 // Description :
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDABULLET BulletRigidBodyNode : public BulletBodyNode {
34 
35 PUBLISHED:
36  BulletRigidBodyNode(const char *name="rigid");
37  INLINE ~BulletRigidBodyNode();
38 
39  // Mass & inertia
40  void set_mass(PN_stdfloat mass);
41  PN_stdfloat get_mass() const;
42  PN_stdfloat get_inv_mass() const;
43  void set_inertia(const LVecBase3 &inertia);
44  LVector3 get_inertia() const;
45  LVector3 get_inv_inertia_diag_local() const;
46  LMatrix3 get_inv_inertia_tensor_world() const;
47 
48  // Velocity
49  LVector3 get_linear_velocity() const;
50  LVector3 get_angular_velocity() const;
51  void set_linear_velocity(const LVector3 &velocity);
52  void set_angular_velocity(const LVector3 &velocity);
53 
54  // Damping
55  INLINE PN_stdfloat get_linear_damping() const;
56  INLINE PN_stdfloat get_angular_damping() const;
57  INLINE void set_linear_damping(PN_stdfloat value);
58  INLINE void set_angular_damping(PN_stdfloat value);
59 
60  // Forces
61  void clear_forces();
62  void apply_force(const LVector3 &force, const LPoint3 &pos);
63  void apply_central_force(const LVector3 &force);
64  void apply_impulse(const LVector3 &impulse, const LPoint3 &pos);
65  void apply_central_impulse(const LVector3 &impulse);
66  void apply_torque(const LVector3 &torque);
67  void apply_torque_impulse(const LVector3 &torque);
68 
69  LVector3 get_total_force() const;
70  LVector3 get_total_torque() const;
71 
72  // Deactivation thresholds
73  PN_stdfloat get_linear_sleep_threshold() const;
74  PN_stdfloat get_angular_sleep_threshold() const;
75  void set_linear_sleep_threshold(PN_stdfloat threshold);
76  void set_angular_sleep_threshold(PN_stdfloat threshold);
77 
78  // Gravity
79  void set_gravity(const LVector3 &gravity);
80  LVector3 get_gravity() const;
81 
82  // Restrict movement
83  void set_linear_factor(const LVector3 &factor);
84  void set_angular_factor(const LVector3 &factor);
85 
86  // Special
87  bool pick_dirty_flag();
88 
89 public:
90  virtual btCollisionObject *get_object() const;
91 
92  virtual void output(ostream &out) const;
93 
94  void sync_p2b();
95  void sync_b2p();
96 
97 protected:
98  virtual void transform_changed();
99 
100 private:
101  virtual void shape_changed();
102 
103  // The motion state is used for syncronisation between Bullet
104  // and the Panda3D scene graph.
105  class MotionState : public btMotionState {
106 
107  public:
108  MotionState();
109 
110  virtual void getWorldTransform(btTransform &trans) const;
111  virtual void setWorldTransform(const btTransform &trans);
112 
113  void set_net_transform(const TransformState *ts);
114 
115  void sync_b2p(PandaNode *node);
116  bool sync_disabled() const;
117 
118  bool pick_dirty_flag();
119 
120  private:
121  btTransform _trans;
122  bool _disabled;
123  bool _dirty;
124  bool _was_dirty;
125  };
126 
127  MotionState *_motion;
128  btRigidBody *_rigid;
129 
130 ////////////////////////////////////////////////////////////////////
131 public:
132  static TypeHandle get_class_type() {
133  return _type_handle;
134  }
135  static void init_type() {
136  BulletBodyNode::init_type();
137  register_type(_type_handle, "BulletRigidBodyNode",
138  BulletBodyNode::get_class_type());
139  }
140  virtual TypeHandle get_type() const {
141  return get_class_type();
142  }
143  virtual TypeHandle force_init_type() {
144  init_type();
145  return get_class_type();
146  }
147 
148 private:
149  static TypeHandle _type_handle;
150 };
151 
152 #include "bulletRigidBodyNode.I"
153 
154 #endif // __BULLET_RIGID_BODY_NODE_H__
155 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110