Panda3D
physxScene.h
1 // Filename: physxScene.h
2 // Created by: enn0x (14Sep09)
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 PHYSXSCENE_H
16 #define PHYSXSCENE_H
17 
18 #include "pandabase.h"
19 #include "luse.h"
20 #include "callbackObject.h"
21 
22 #include "physxObject.h"
23 #include "physxObjectCollection.h"
24 #include "physxEnums.h"
25 #include "physxContactReport.h"
26 #include "physxControllerReport.h"
27 #include "physxTriggerReport.h"
28 #include "physxOverlapReport.h"
29 #include "physxMask.h"
30 #include "physxGroupsMask.h"
31 #include "physx_includes.h"
32 
33 class PhysxActor;
34 class PhysxActorDesc;
35 class PhysxController;
38 class PhysxDebugGeomNode;
39 class PhysxForceField;
43 class PhysxJoint;
44 class PhysxJointDesc;
45 class PhysxMaterial;
46 class PhysxMaterialDesc;
47 class PhysxOverlapReport;
48 class PhysxRay;
49 class PhysxRaycastHit;
50 class PhysxRaycastReport;
51 class PhysxSceneStats2;
52 class PhysxVehicle;
53 class PhysxVehicleDesc;
54 class PhysxCloth;
55 class PhysxClothDesc;
56 class PhysxSoftBody;
57 class PhysxSoftBodyDesc;
58 
59 ////////////////////////////////////////////////////////////////////
60 // Class : PhysxScene
61 // Description : A scene is a collection of bodies, constraints,
62 // and effectors which can interact.
63 //
64 // The scene simulates the behavior of these objects
65 // over time. Several scenes may exist at the same
66 // time, but each body, constraint, or effector object
67 // is specific to a scene -- they may not be shared.
68 //
69 // For example, attempting to create a joint in one
70 // scene and then using it to attach bodies from a
71 // different scene results in undefined behavior.
72 ////////////////////////////////////////////////////////////////////
73 class EXPCL_PANDAPHYSX PhysxScene : public PhysxObject, public PhysxEnums {
74 
75 PUBLISHED:
76  INLINE PhysxScene();
77  INLINE ~PhysxScene();
78 
79  void simulate(float dt);
80  void fetch_results();
81  void set_timing_variable();
82  void set_timing_fixed(float maxTimestep=1.0f/60.0f, unsigned int maxIter=8);
83 
84  PhysxDebugGeomNode *get_debug_geom_node();
85 
86  void enable_contact_reporting(bool enabled);
87  bool is_contact_reporting_enabled() const;
88  void enable_trigger_reporting(bool enabled);
89  bool is_trigger_reporting_enabled() const;
90  void enable_controller_reporting(bool enabled);
91  bool is_controller_reporting_enabled() const;
92 
93  INLINE void set_controller_shape_hit_callback(PT(CallbackObject) cbobj);
94  INLINE void set_controller_controller_hit_callback(PT(CallbackObject) cbobj);
95 
96  void set_gravity(const LVector3f &gravity);
97 
98  LVector3f get_gravity() const;
99  PhysxSceneStats2 get_stats2() const;
100  bool get_flag(PhysxSceneFlag flag) const;
101  bool is_hardware_scene() const;
102 
103  // Actors
104  unsigned int get_num_actors() const;
105  PhysxActor *create_actor(PhysxActorDesc &desc);
106  PhysxActor *get_actor(unsigned int idx) const;
107  MAKE_SEQ(get_actors, get_num_actors, get_actor);
108 
109  // Joints
110  unsigned int get_num_joints() const;
111  PhysxJoint *create_joint(PhysxJointDesc &desc);
112  PhysxJoint *get_joint(unsigned int idx) const;
113  MAKE_SEQ(get_joints, get_num_joints, get_joint);
114 
115  // Materials
116  unsigned int get_num_materials() const;
117  unsigned int get_hightest_material_index() const;
118  PhysxMaterial *create_material(PhysxMaterialDesc &desc);
119  PhysxMaterial *create_material();
120  PhysxMaterial *get_material(unsigned int idx) const;
121  PhysxMaterial *get_material_from_index(unsigned int idx) const;
122  MAKE_SEQ(get_materials, get_num_materials, get_material);
123 
124  // Controllers
125  unsigned int get_num_controllers() const;
126  PhysxController *create_controller(PhysxControllerDesc &controllerDesc);
127  PhysxController *get_controller(unsigned int idx) const;
128  MAKE_SEQ(get_controllers, get_num_controllers, get_controller);
129 
130  // Force fields
131  unsigned int get_num_force_fields() const;
132  PhysxForceField *create_force_field(PhysxForceFieldDesc &desc);
133  PhysxForceField *get_force_field(unsigned int idx) const;
134  MAKE_SEQ(get_force_fields, get_num_force_fields, get_force_field);
135 
136  // Force field shape groups
137  unsigned int get_num_force_field_shape_groups() const;
138  PhysxForceFieldShapeGroup *create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc);
139  PhysxForceFieldShapeGroup *get_force_field_shape_group(unsigned int idx) const;
140  MAKE_SEQ(get_force_field_shape_groups, get_num_force_field_shape_groups, get_force_field_shape_group);
141 
142  // Cloths
143  unsigned int get_num_cloths() const;
144  PhysxCloth *create_cloth(PhysxClothDesc &desc);
145  PhysxCloth *get_cloth(unsigned int idx) const;
146  MAKE_SEQ(get_cloths, get_num_cloths, get_cloth);
147 
148  // Soft bodies
149  unsigned int get_num_soft_bodies() const;
150  PhysxSoftBody *create_soft_body(PhysxSoftBodyDesc &desc);
151  PhysxSoftBody *get_soft_body(unsigned int idx) const;
152  MAKE_SEQ(get_soft_bodies, get_num_soft_bodies, get_soft_body);
153 
154  // Vehicles
155  unsigned int get_num_vehicles() const;
156  PhysxVehicle *create_vehicle(PhysxVehicleDesc &desc);
157  PhysxVehicle *get_vehicle(unsigned int idx) const;
158  MAKE_SEQ(get_vehicles, get_num_vehicles, get_vehicle);
159 
160  // Raycast queries
161  bool raycast_any_shape(const PhysxRay &ray,
162  PhysxShapesType shapesType=ST_all,
164  PhysxGroupsMask *groups=NULL) const;
165 
166  PhysxRaycastHit raycast_closest_shape(const PhysxRay &ray,
167  PhysxShapesType shapesType=ST_all,
169  PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
170 
171  PhysxRaycastReport raycast_all_shapes(const PhysxRay &ray,
172  PhysxShapesType shapesType=ST_all,
174  PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
175 
176  bool raycast_any_bounds(const PhysxRay &ray,
177  PhysxShapesType shapesType=ST_all,
179  PhysxGroupsMask *groups=NULL) const;
180 
181  PhysxRaycastHit raycast_closest_bounds(const PhysxRay &ray,
182  PhysxShapesType shapesType=ST_all,
184  PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
185 
186  PhysxRaycastReport raycast_all_bounds(const PhysxRay &ray,
187  PhysxShapesType shapesType=ST_all,
189  PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
190 
191  // Overlap queries
192  PhysxOverlapReport overlap_sphere_shapes(const LPoint3f &center, float radius,
193  PhysxShapesType shapesType=ST_all,
194  PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const;
195 
196  PhysxOverlapReport overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius,
197  PhysxShapesType shapesType=ST_all,
198  PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const;
199 
200  // Filters
201  void set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag, bool value);
202  void set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value);
203  void set_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag, bool value);
204  void set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable);
205  void set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2);
206  void set_filter_bool(bool flag);
207  void set_filter_constant0(const PhysxGroupsMask &mask);
208  void set_filter_constant1(const PhysxGroupsMask &mask);
209  void set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance);
210 
211  bool get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag);
212  bool get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB);
213  bool get_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag);
214  bool get_group_collision_flag(unsigned int g1, unsigned int g2);
215  bool get_filter_bool() const;
216  PhysxGroupsMask get_filter_constant0() const;
217  PhysxGroupsMask get_filter_constant1() const;
218  PhysxFilterOp get_filter_op0() const;
219  PhysxFilterOp get_filter_op1() const;
220  PhysxFilterOp get_filter_op2() const;
221  PhysxConstraintDominance get_dominance_group_pair(unsigned int g1, unsigned int g2);
222 
223 ////////////////////////////////////////////////////////////////////
224 PUBLISHED:
225  void release();
226 
227  INLINE void ls() const;
228  INLINE void ls(ostream &out, int indent_level=0) const;
229 
230 public:
231  INLINE NxScene *ptr() const { return _ptr; };
232  INLINE NxControllerManager *cm() const { return _cm; };
233 
234  void link(NxScene *ptr);
235  void unlink();
236 
246 
247  PhysxMaterial *get_wheel_shape_material();
248 
249 private:
250  NxScene *_ptr;
251  NxControllerManager *_cm;
252  PT(PhysxDebugGeomNode) _debugNode;
253  PT(PhysxMaterial) _wheelShapeMaterial;
254 
255  PhysxContactReport _contact_report;
256  PhysxControllerReport _controller_report;
257  PhysxTriggerReport _trigger_report;
258 
259  static PStatCollector _pcollector_fetch_results;
260  static PStatCollector _pcollector_update_transforms;
261  static PStatCollector _pcollector_debug_renderer;
262  static PStatCollector _pcollector_simulate;
263  static PStatCollector _pcollector_cloth;
264  static PStatCollector _pcollector_softbody;
265 
266 ////////////////////////////////////////////////////////////////////
267 public:
268  static TypeHandle get_class_type() {
269  return _type_handle;
270  }
271  static void init_type() {
272  PhysxObject::init_type();
273  register_type(_type_handle, "PhysxScene",
274  PhysxObject::get_class_type());
275  }
276  virtual TypeHandle get_type() const {
277  return get_class_type();
278  }
279  virtual TypeHandle force_init_type() {
280  init_type();
281  return get_class_type();
282  }
283 
284 private:
285  static TypeHandle _type_handle;
286 };
287 
288 #include "physxScene.I"
289 
290 #endif // PHYSXSCENE_H
Objects of this class are returned by the 'overlap shape' methods, for example overlapSphereShapes.
Descriptor class for materials.
Abstract base class for the different types of joints.
Definition: physxJoint.h:35
Abstract base class for shapes.
Definition: physxShape.h:41
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
Descriptor for PhysxCloth.
Implementation of the NxUserContactReport interface.
Abstract base class for joint descriptors.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
A scene is a collection of bodies, constraints, and effectors which can interact. ...
Definition: physxScene.h:73
Descriptor class for force fields.
A class for describing a shape's surface properties.
Definition: physxMaterial.h:51
Descriptor class for a character controller.
This structure captures results for a single raycast query.
A lightweight class that represents a single element that may be timed and/or counted via stats...
Abstract base class for character controllers.
Descriptor for PhysxSoftBody.
This class exists just to provide scoping for the enums shared by PhysX classes.
Definition: physxEnums.h:357
static PhysxMask all_on()
Returns a PhysxMask whose bits are all on.
Definition: physxMask.cxx:23
32-bit bitmask class.
Definition: physxMask.h:26
Descriptor for PhysxActor.
Actors are the main simulation objects.
Definition: physxActor.h:48
This is a generic object that can be assigned to a callback at various points in the rendering proces...
A force field effector.
Implementation of the NxUserControllerHitReport interface.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Implementation of the NxUserTriggerReport interface.
Objects of this class are returned by the 'raycast all' methods.
Represents an ray as an origin and direction.
Definition: physxRay.h:28
Renderable geometry which represents visualizations of physics objects.
128-bit bitmask class.
Expresses the dominance relationship of a constraint.