Panda3D
bulletBodyNode.h
1 // Filename: bulletBodyNode.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_BODY_NODE_H__
16 #define __BULLET_BODY_NODE_H__
17 
18 #include "pandabase.h"
19 
20 #include "bullet_includes.h"
21 #include "bullet_utils.h"
22 
23 #include "pandaNode.h"
24 #include "collideMask.h"
25 #include "collisionNode.h"
26 #include "transformState.h"
27 #include "boundingSphere.h"
28 
29 class BulletShape;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : BulletBodyNode
33 // Description :
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_PANDABULLET BulletBodyNode : public PandaNode {
36 
37 PUBLISHED:
38  BulletBodyNode(const char *name);
39  INLINE ~BulletBodyNode();
40 
41  // Shapes
42  void add_shape(BulletShape *shape, const TransformState *xform=TransformState::make_identity());
43  void remove_shape(BulletShape *shape);
44 
45  INLINE int get_num_shapes() const;
46  INLINE BulletShape *get_shape(int idx) const;
47  MAKE_SEQ(get_shapes, get_num_shapes, get_shape);
48 
49  LPoint3 get_shape_pos(int idx) const;
50  LMatrix4 get_shape_mat(int idx) const;
51  BoundingSphere get_shape_bounds() const;
52 
53  void add_shapes_from_collision_solids(CollisionNode *cnode);
54 
55  // Static and kinematic
56  INLINE bool is_static() const;
57  INLINE bool is_kinematic() const;
58 
59  INLINE void set_static(bool value);
60  INLINE void set_kinematic(bool value);
61 
62  // Contacts
63  INLINE void set_into_collide_mask(CollideMask mask);
64 
65  INLINE void notify_collisions(bool value);
66  INLINE bool notifies_collisions() const;
67 
68  INLINE void set_collision_response(bool value);
69  INLINE bool get_collision_response() const;
70 
71  bool check_collision_with(PandaNode *node);
72 
73  bool has_contact_response() const;
74 
75  PN_stdfloat get_contact_processing_threshold() const;
76  void set_contact_processing_threshold(PN_stdfloat threshold);
77 
78  // Deactivation
79  bool is_active() const;
80  void set_active(bool active, bool force=false);
81 
82  void set_deactivation_time(PN_stdfloat dt);
83  PN_stdfloat get_deactivation_time() const;
84 
85  void set_deactivation_enabled(const bool enabled, const bool force=false);
86  bool is_deactivation_enabled() const;
87 
88  // Debug Visualistion
89  INLINE void set_debug_enabled(const bool enabled);
90  INLINE bool is_debug_enabled() const;
91 
92  // Friction and Restitution
93  INLINE PN_stdfloat get_restitution() const;
94  INLINE void set_restitution(PN_stdfloat restitution);
95 
96  INLINE PN_stdfloat get_friction() const;
97  INLINE void set_friction(PN_stdfloat friction);
98 
99 #if BT_BULLET_VERSION >= 281
100  INLINE PN_stdfloat get_rolling_friction() const;
101  INLINE void set_rolling_friction(PN_stdfloat friction);
102 #endif
103 
104  INLINE bool has_anisotropic_friction() const;
105  void set_anisotropic_friction(const LVecBase3 &friction);
106  LVecBase3 get_anisotropic_friction() const;
107 
108  // CCD
109  PN_stdfloat get_ccd_swept_sphere_radius() const;
110  PN_stdfloat get_ccd_motion_threshold() const;
111  void set_ccd_swept_sphere_radius(PN_stdfloat radius);
112  void set_ccd_motion_threshold(PN_stdfloat threshold);
113 
114  // Special
115  void set_transform_dirty();
116 
117 public:
118  virtual btCollisionObject *get_object() const = 0;
119 
120  virtual CollideMask get_legal_collide_mask() const;
121 
122  virtual bool safe_to_flatten() const;
123  virtual bool safe_to_transform() const;
124  virtual bool safe_to_modify_transform() const;
125  virtual bool safe_to_combine() const;
126  virtual bool safe_to_combine_children() const;
127  virtual bool safe_to_flatten_below() const;
128 
129  virtual void output(ostream &out) const;
130 
131 protected:
132  INLINE void set_collision_flag(int flag, bool value);
133  INLINE bool get_collision_flag(int flag) const;
134 
135  btCollisionShape *_shape;
136 
137  typedef PTA(PT(BulletShape)) BulletShapes;
138  BulletShapes _shapes;
139 
140 private:
141  virtual void shape_changed();
142 
143  static bool is_identity(btTransform &trans);
144 
145 ////////////////////////////////////////////////////////////////////
146 public:
147  static TypeHandle get_class_type() {
148  return _type_handle;
149  }
150  static void init_type() {
151  PandaNode::init_type();
152  register_type(_type_handle, "BulletBodyNode",
153  PandaNode::get_class_type());
154  }
155  virtual TypeHandle get_type() const {
156  return get_class_type();
157  }
158  virtual TypeHandle force_init_type() {
159  init_type();
160  return get_class_type();
161  }
162 
163 private:
164  static TypeHandle _type_handle;
165 };
166 
167 #include "bulletBodyNode.I"
168 
169 #endif // __BULLET_BODY_NODE_H__
170 
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
virtual CollideMask get_legal_collide_mask() const
Returns the subset of CollideMask bits that may be set for this particular type of PandaNode...
Definition: pandaNode.cxx:2069
virtual bool safe_to_modify_transform() const
Returns true if it is safe to automatically adjust the transform on this kind of node.
Definition: pandaNode.cxx:266
This defines a bounding sphere, consisting of a center and a radius.
virtual bool safe_to_combine_children() const
Returns true if it is generally safe to combine the children of this PandaNode with each other...
Definition: pandaNode.cxx:295
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
Definition: pandaNode.cxx:281
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
void set_into_collide_mask(CollideMask mask)
Sets the "into" CollideMask.
Definition: pandaNode.cxx:2037
virtual bool safe_to_flatten_below() const
Returns true if a flatten operation may safely continue past this node, or false if nodes below this ...
Definition: pandaNode.cxx:307
A node in the scene graph that can hold any number of CollisionSolids.
Definition: collisionNode.h:33
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool safe_to_transform() const
Returns true if it is generally safe to transform this particular kind of PandaNode by calling the xf...
Definition: pandaNode.cxx:249
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating ...
Definition: pandaNode.cxx:237