Panda3D
Loading...
Searching...
No Matches
bulletWorld.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 bulletWorld.h
10 * @author enn0x
11 * @date 2010-01-23
12 */
13
14#ifndef __BULLET_WORLD_H__
15#define __BULLET_WORLD_H__
16
17#include "pandabase.h"
18
19#include "bullet_includes.h"
20#include "bullet_utils.h"
21
25#include "bulletContactResult.h"
26#include "bulletDebugNode.h"
28#include "bulletConstraint.h"
29#include "bulletGhostNode.h"
30#include "bulletRigidBodyNode.h"
31#include "bulletSoftBodyNode.h"
32#include "bulletVehicle.h"
33
34#include "typedReferenceCount.h"
35#include "transformState.h"
36#include "pandaNode.h"
37#include "callbackObject.h"
38#include "collideMask.h"
39#include "luse.h"
40#include "lightMutex.h"
41
43class BulletShape;
45
46extern EXPCL_PANDABULLET PT(CallbackObject) bullet_contact_added_callback;
47
48/**
49 *
50 */
51class EXPCL_PANDABULLET BulletWorld : public TypedReferenceCount {
52
53PUBLISHED:
55 INLINE ~BulletWorld();
56
57 void set_gravity(const LVector3 &gravity);
58 void set_gravity(PN_stdfloat gx, PN_stdfloat gy, PN_stdfloat gz);
59 const LVector3 get_gravity() const;
60
61 int do_physics(PN_stdfloat dt, int max_substeps=1, PN_stdfloat stepsize=1.0f/60.0f);
62
63 BulletSoftBodyWorldInfo get_world_info();
64
65 // Debug
66 void set_debug_node(BulletDebugNode *node);
67 void clear_debug_node();
68 INLINE BulletDebugNode *get_debug_node() const;
69 INLINE bool has_debug_node() const;
70
71 // AttachRemove
72 void attach(TypedObject *object);
73 void remove(TypedObject *object);
74 void attach_constraint(BulletConstraint *constraint, bool linked_collision=false);
75
76 // Ghost object
77 int get_num_ghosts() const;
78 BulletGhostNode *get_ghost(int idx) const;
79 MAKE_SEQ(get_ghosts, get_num_ghosts, get_ghost);
80
81 // Rigid body
82 int get_num_rigid_bodies() const;
83 BulletRigidBodyNode *get_rigid_body(int idx) const;
84 MAKE_SEQ(get_rigid_bodies, get_num_rigid_bodies, get_rigid_body);
85
86 // Soft body
87 int get_num_soft_bodies() const;
88 BulletSoftBodyNode *get_soft_body(int idx) const;
89 MAKE_SEQ(get_soft_bodies, get_num_soft_bodies, get_soft_body);
90
91 // Character controller
92 int get_num_characters() const;
93 BulletBaseCharacterControllerNode *get_character(int idx) const;
94 MAKE_SEQ(get_characters, get_num_characters, get_character);
95
96 int get_num_vehicles() const;
97 BulletVehicle *get_vehicle(int idx) const;
98 MAKE_SEQ(get_vehicles, get_num_vehicles, get_vehicle);
99
100 // Constraint
101 int get_num_constraints() const;
102 BulletConstraint *get_constraint(int idx) const;
103 MAKE_SEQ(get_constraints, get_num_constraints, get_constraint);
104
105 // Raycast and other queries
106 BulletClosestHitRayResult ray_test_closest(
107 const LPoint3 &from_pos,
108 const LPoint3 &to_pos,
109 const CollideMask &mask=CollideMask::all_on()) const;
110
111 BulletAllHitsRayResult ray_test_all(
112 const LPoint3 &from_pos,
113 const LPoint3 &to_pos,
114 const CollideMask &mask=CollideMask::all_on()) const;
115
116 BulletClosestHitSweepResult sweep_test_closest(
117 BulletShape *shape,
118 const TransformState &from_ts,
119 const TransformState &to_ts,
120 const CollideMask &mask=CollideMask::all_on(),
121 PN_stdfloat penetration=0.0f) const;
122
123 BulletContactResult contact_test(PandaNode *node, bool use_filter=false) const;
124 BulletContactResult contact_test_pair(PandaNode *node0, PandaNode *node1) const;
125
126 bool filter_test(PandaNode *node0, PandaNode *node1) const;
127
128 // Manifolds
129 int get_num_manifolds() const;
130 BulletPersistentManifold *get_manifold(int idx) const;
131 BulletPersistentManifold __get_manifold(int idx) const;
132 MAKE_SEQ(get_manifolds, get_num_manifolds, __get_manifold);
133
134 // Collision filtering
135 void set_group_collision_flag(unsigned int group1, unsigned int group2, bool enable);
136 bool get_group_collision_flag(unsigned int group1, unsigned int group2) const;
137
138 void set_force_update_all_aabbs(bool force);
139 bool get_force_update_all_aabbs() const;
140
141 // Callbacks
142 void set_contact_added_callback(CallbackObject *obj);
143 void clear_contact_added_callback();
144
145 void set_tick_callback(CallbackObject *obj, bool is_pretick=false);
146 void clear_tick_callback();
147
148 void set_filter_callback(CallbackObject *obj);
149 void clear_filter_callback();
150
151 // Configuration
152 enum BroadphaseAlgorithm {
153 BA_sweep_and_prune,
154 BA_dynamic_aabb_tree,
155 };
156
157 enum FilterAlgorithm {
158 FA_mask,
159 FA_groups_mask,
160 FA_callback,
161 };
162
163 MAKE_PROPERTY(gravity, get_gravity, set_gravity);
164 MAKE_PROPERTY(world_info, get_world_info);
165 MAKE_PROPERTY2(debug_node, has_debug_node, get_debug_node, set_debug_node, clear_debug_node);
166 MAKE_SEQ_PROPERTY(ghosts, get_num_ghosts, get_ghost);
167 MAKE_SEQ_PROPERTY(rigid_bodies, get_num_rigid_bodies, get_rigid_body);
168 MAKE_SEQ_PROPERTY(soft_bodies, get_num_soft_bodies, get_soft_body);
169 MAKE_SEQ_PROPERTY(characters, get_num_characters, get_character);
170 MAKE_SEQ_PROPERTY(vehicles, get_num_vehicles, get_vehicle);
171 MAKE_SEQ_PROPERTY(constraints, get_num_constraints, get_constraint);
172 MAKE_SEQ_PROPERTY(manifolds, get_num_manifolds, __get_manifold);
173 MAKE_PROPERTY(force_update_all_aabbs, get_force_update_all_aabbs,
174 set_force_update_all_aabbs);
175
176PUBLISHED: // Deprecated methods, will be removed soon
177 void attach_ghost(BulletGhostNode *node);
178 void remove_ghost(BulletGhostNode *node);
179
180 void attach_rigid_body(BulletRigidBodyNode *node);
181 void remove_rigid_body(BulletRigidBodyNode *node);
182
183 void attach_soft_body(BulletSoftBodyNode *node);
184 void remove_soft_body(BulletSoftBodyNode *node);
185
186 void attach_character(BulletBaseCharacterControllerNode *node);
187 void remove_character(BulletBaseCharacterControllerNode *node);
188
189 void attach_vehicle(BulletVehicle *vehicle);
190 void remove_vehicle(BulletVehicle *vehicle);
191
192 void remove_constraint(BulletConstraint *constraint);
193
194public:
195 static btCollisionObject *get_collision_object(PandaNode *node);
196
197 INLINE btDynamicsWorld *get_world() const;
198 INLINE btBroadphaseInterface *get_broadphase() const;
199 INLINE btDispatcher *get_dispatcher() const;
200
201 static LightMutex &get_global_lock();
202
203private:
204 void do_sync_p2b(PN_stdfloat dt, int num_substeps);
205 void do_sync_b2p();
206
207 void do_attach_ghost(BulletGhostNode *node);
208 void do_remove_ghost(BulletGhostNode *node);
209
210 void do_attach_rigid_body(BulletRigidBodyNode *node);
211 void do_remove_rigid_body(BulletRigidBodyNode *node);
212
213 void do_attach_soft_body(BulletSoftBodyNode *node);
214 void do_remove_soft_body(BulletSoftBodyNode *node);
215
216 void do_attach_character(BulletBaseCharacterControllerNode *node);
217 void do_remove_character(BulletBaseCharacterControllerNode *node);
218
219 void do_attach_vehicle(BulletVehicle *vehicle);
220 void do_remove_vehicle(BulletVehicle *vehicle);
221
222 void do_attach_constraint(BulletConstraint *constraint, bool linked_collision=false);
223 void do_remove_constraint(BulletConstraint *constraint);
224
225 static void tick_callback(btDynamicsWorld *world, btScalar timestep);
226
227 typedef PTA(PT(BulletRigidBodyNode)) BulletRigidBodies;
228 typedef PTA(PT(BulletSoftBodyNode)) BulletSoftBodies;
229 typedef PTA(PT(BulletGhostNode)) BulletGhosts;
230 typedef PTA(PT(BulletBaseCharacterControllerNode)) BulletCharacterControllers;
231 typedef PTA(PT(BulletVehicle)) BulletVehicles;
232 typedef PTA(PT(BulletConstraint)) BulletConstraints;
233
234 static PStatCollector _pstat_physics;
235 static PStatCollector _pstat_simulation;
236 static PStatCollector _pstat_p2b;
237 static PStatCollector _pstat_b2p;
238
239 struct btFilterCallback1 : public btOverlapFilterCallback {
240 virtual bool needBroadphaseCollision(
241 btBroadphaseProxy* proxy0,
242 btBroadphaseProxy* proxy1) const;
243 };
244
245 struct btFilterCallback2 : public btOverlapFilterCallback {
246 virtual bool needBroadphaseCollision(
247 btBroadphaseProxy* proxy0,
248 btBroadphaseProxy* proxy1) const;
249
250 CollideMask _collide[32];
251 };
252
253 struct btFilterCallback3 : public btOverlapFilterCallback {
254 virtual bool needBroadphaseCollision(
255 btBroadphaseProxy* proxy0,
256 btBroadphaseProxy* proxy1) const;
257
258 PT(CallbackObject) _filter_callback_obj;
259 };
260
261 btBroadphaseInterface *_broadphase;
262 btCollisionConfiguration *_configuration;
263 btCollisionDispatcher *_dispatcher;
264 btConstraintSolver *_solver;
265 btSoftRigidDynamicsWorld *_world;
266
267 btGhostPairCallback _ghost_cb;
268
269 FilterAlgorithm _filter_algorithm;
270 btFilterCallback1 _filter_cb1;
271 btFilterCallback2 _filter_cb2;
272 btFilterCallback3 _filter_cb3;
273 btOverlapFilterCallback *_filter_cb;
274
275 PT(CallbackObject) _tick_callback_obj;
276
277 PT(BulletDebugNode) _debug;
278
279 btSoftBodyWorldInfo _info;
280
281 BulletRigidBodies _bodies;
282 BulletSoftBodies _softbodies;
283 BulletGhosts _ghosts;
284 BulletCharacterControllers _characters;
285 BulletVehicles _vehicles;
286 BulletConstraints _constraints;
287
288public:
289 static TypeHandle get_class_type() {
290 return _type_handle;
291 }
292 static void init_type() {
293 TypedReferenceCount::init_type();
294 register_type(_type_handle, "BulletWorld",
295 TypedReferenceCount::get_class_type());
296 }
297 virtual TypeHandle get_type() const {
298 return get_class_type();
299 }
300 virtual TypeHandle force_init_type() {
301 init_type();
302 return get_class_type();
303 }
304
305private:
306 static TypeHandle _type_handle;
307};
308
309EXPCL_PANDABULLET std::ostream &
310operator << (std::ostream &out, BulletWorld::BroadphaseAlgorithm algorithm);
311EXPCL_PANDABULLET std::istream &
312operator >> (std::istream &in, BulletWorld::BroadphaseAlgorithm &algorithm);
313
314EXPCL_PANDABULLET std::ostream &
315operator << (std::ostream &out, BulletWorld::FilterAlgorithm algorithm);
316EXPCL_PANDABULLET std::istream &
317operator >> (std::istream &in, BulletWorld::FilterAlgorithm &algorithm);
318
319#include "bulletWorld.I"
320
321#endif // __BULLET_WORLD_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.
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.
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.
static BitMask< uint32_t, nbits > all_on()
Returns a BitMask whose bits are all on.
Definition bitMask.I:32
Simulates a raycast vehicle which casts a ray per wheel at the ground as a cheap replacement for comp...
This is a generic object that can be assigned to a callback at various points in the rendering proces...
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
A lightweight class that represents a single element that may be timed and/or counted via stats.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition typedObject.h:88
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
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.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.