Panda3D
bulletBodyNode.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file bulletBodyNode.h
10  * @author enn0x
11  * @date 2010-11-19
12  */
13 
14 #ifndef __BULLET_BODY_NODE_H__
15 #define __BULLET_BODY_NODE_H__
16 
17 #include "pandabase.h"
18 
19 #include "bulletShape.h"
20 
21 #include "bullet_includes.h"
22 #include "bullet_utils.h"
23 
24 #include "pandaNode.h"
25 #include "collideMask.h"
26 #include "collisionNode.h"
27 #include "transformState.h"
28 #include "boundingSphere.h"
29 
30 /**
31  *
32  */
33 class EXPCL_PANDABULLET BulletBodyNode : public PandaNode {
34 protected:
35  BulletBodyNode(const char *name);
36  BulletBodyNode(const BulletBodyNode &copy);
37 
38 PUBLISHED:
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  int get_num_shapes() const;
46  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  CPT(TransformState) get_shape_transform(int idx) const;
52  BoundingSphere get_shape_bounds() const;
53 
54  void add_shapes_from_collision_solids(CollisionNode *cnode);
55 
56  // Static and kinematic
57  bool is_static() const;
58  bool is_kinematic() const;
59 
60  INLINE void set_static(bool value);
61  INLINE void set_kinematic(bool value);
62 
63  // Contacts
64  INLINE void set_into_collide_mask(CollideMask mask);
65 
66  INLINE void notify_collisions(bool value);
67  INLINE bool notifies_collisions() const;
68 
69  INLINE void set_collision_response(bool value);
70  INLINE bool get_collision_response() const;
71 
72  bool check_collision_with(PandaNode *node);
73 
74  bool has_contact_response() const;
75 
76  PN_stdfloat get_contact_processing_threshold() const;
77  void set_contact_processing_threshold(PN_stdfloat threshold);
78 
79  // Deactivation
80  bool is_active() const;
81  void set_active(bool active, bool force=false);
82  void force_active(bool active);
83 
84  void set_deactivation_time(PN_stdfloat dt);
85  PN_stdfloat get_deactivation_time() const;
86 
87  void set_deactivation_enabled(bool enabled);
88  bool is_deactivation_enabled() const;
89 
90  // Debug Visualisation
91  INLINE void set_debug_enabled(const bool enabled);
92  INLINE bool is_debug_enabled() const;
93 
94  // Friction and Restitution
95  PN_stdfloat get_restitution() const;
96  void set_restitution(PN_stdfloat restitution);
97 
98  PN_stdfloat get_friction() const;
99  void set_friction(PN_stdfloat friction);
100 
101 #if BT_BULLET_VERSION >= 281
102  PN_stdfloat get_rolling_friction() const;
103  void set_rolling_friction(PN_stdfloat friction);
104  MAKE_PROPERTY(rolling_friction, get_rolling_friction, set_rolling_friction);
105 #endif
106 
107  bool has_anisotropic_friction() const;
108  void set_anisotropic_friction(const LVecBase3 &friction);
109  LVecBase3 get_anisotropic_friction() const;
110 
111  // CCD
112  PN_stdfloat get_ccd_swept_sphere_radius() const;
113  PN_stdfloat get_ccd_motion_threshold() const;
114  void set_ccd_swept_sphere_radius(PN_stdfloat radius);
115  void set_ccd_motion_threshold(PN_stdfloat threshold);
116 
117  // Special
118  void set_transform_dirty();
119 
120  MAKE_SEQ_PROPERTY(shapes, get_num_shapes, get_shape);
121  MAKE_SEQ_PROPERTY(shape_pos, get_num_shapes, get_shape_pos);
122  MAKE_SEQ_PROPERTY(shape_mat, get_num_shapes, get_shape_mat);
123  MAKE_SEQ_PROPERTY(shape_transform, get_num_shapes, get_shape_transform);
124  MAKE_PROPERTY(shape_bounds, get_shape_bounds);
125  MAKE_PROPERTY(static, is_static, set_static);
126  MAKE_PROPERTY(kinematic, is_kinematic, set_kinematic);
127  MAKE_PROPERTY(collision_notification, notifies_collisions, notify_collisions);
128  MAKE_PROPERTY(collision_response, get_collision_response, set_collision_response);
129  MAKE_PROPERTY(contact_response, has_contact_response);
130  MAKE_PROPERTY(contact_processing_threshold, get_contact_processing_threshold, set_contact_processing_threshold);
131  MAKE_PROPERTY(active, is_active, force_active);
132  MAKE_PROPERTY(deactivation_time, get_deactivation_time, set_deactivation_time);
133  MAKE_PROPERTY(deactivation_enabled, is_deactivation_enabled, set_deactivation_enabled);
134  MAKE_PROPERTY(debug_enabled, is_debug_enabled, set_debug_enabled);
135  MAKE_PROPERTY(restitution, get_restitution, set_restitution);
136  MAKE_PROPERTY(friction, get_friction, set_friction);
137  MAKE_PROPERTY(anisotropic_friction, get_anisotropic_friction, set_anisotropic_friction);
138  MAKE_PROPERTY(ccd_swept_sphere_radius, get_ccd_swept_sphere_radius, set_ccd_swept_sphere_radius);
139  MAKE_PROPERTY(ccd_motion_threshold, get_ccd_motion_threshold, set_ccd_motion_threshold);
140 
141 public:
142  virtual btCollisionObject *get_object() const = 0;
143 
144  virtual CollideMask get_legal_collide_mask() const;
145 
146  virtual bool safe_to_flatten() const;
147  virtual bool safe_to_transform() const;
148  virtual bool safe_to_modify_transform() const;
149  virtual bool safe_to_combine() const;
150  virtual bool safe_to_combine_children() const;
151  virtual bool safe_to_flatten_below() const;
152 
153  virtual void output(std::ostream &out) const;
154  virtual void do_output(std::ostream &out) const;
155 
156 protected:
157  void set_collision_flag(int flag, bool value);
158  bool get_collision_flag(int flag) const;
159 
160  btCollisionShape *_shape;
161 
162  typedef PTA(PT(BulletShape)) BulletShapes;
163  BulletShapes _shapes;
164 
165 private:
166  virtual void do_shape_changed();
167  void do_add_shape(BulletShape *shape, const TransformState *xform=TransformState::make_identity());
168  CPT(TransformState) do_get_shape_transform(int idx) const;
169 
170  static bool is_identity(btTransform &trans);
171 
172 public:
173  virtual void write_datagram(BamWriter *manager, Datagram &dg);
174  virtual int complete_pointers(TypedWritable **plist,
175  BamReader *manager);
176  virtual bool require_fully_complete() const;
177 
178 protected:
179  void fillin(DatagramIterator &scan, BamReader *manager);
180 
181 public:
182  static TypeHandle get_class_type() {
183  return _type_handle;
184  }
185  static void init_type() {
186  PandaNode::init_type();
187  register_type(_type_handle, "BulletBodyNode",
188  PandaNode::get_class_type());
189  }
190  virtual TypeHandle get_type() const {
191  return get_class_type();
192  }
193  virtual TypeHandle force_init_type() {
194  init_type();
195  return get_class_type();
196  }
197 
198 private:
199  static TypeHandle _type_handle;
200 };
201 
202 #include "bulletBodyNode.I"
203 
204 #endif // __BULLET_BODY_NODE_H__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This defines a bounding sphere, consisting of a center and a radius.
A node in the scene graph that can hold any number of CollisionSolids.
Definition: collisionNode.h:30
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
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:228
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:204
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:238
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:217
get_legal_collide_mask
Returns the subset of CollideMask bits that may be set for this particular type of PandaNode.
Definition: pandaNode.h:265
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:247
set_into_collide_mask
Sets the "into" CollideMask.
Definition: pandaNode.h:264
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:3583
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:195
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.