Panda3D
Loading...
Searching...
No Matches
physxScene.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 physxScene.h
10 * @author enn0x
11 * @date 2009-09-14
12 */
13
14#ifndef PHYSXSCENE_H
15#define PHYSXSCENE_H
16
17#include "pandabase.h"
18#include "luse.h"
19#include "callbackObject.h"
20
21#include "physxObject.h"
23#include "physxEnums.h"
24#include "physxContactReport.h"
26#include "physxTriggerReport.h"
27#include "physxOverlapReport.h"
28#include "physxMask.h"
29#include "physxGroupsMask.h"
30#include "physx_includes.h"
31
32class PhysxActor;
33class PhysxActorDesc;
34class PhysxController;
38class PhysxForceField;
42class PhysxJoint;
43class PhysxJointDesc;
44class PhysxMaterial;
47class PhysxRay;
48class PhysxRaycastHit;
51class PhysxVehicle;
53class PhysxCloth;
54class PhysxClothDesc;
55class PhysxSoftBody;
57
58/**
59 * A scene is a collection of bodies, constraints, and effectors which can
60 * interact.
61 *
62 * The scene simulates the behavior of these objects over time. Several
63 * scenes may exist at the same time, but each body, constraint, or effector
64 * object is specific to a scene -- they may not be shared.
65 *
66 * For example, attempting to create a joint in one scene and then using it to
67 * attach bodies from a different scene results in undefined behavior.
68 */
69class EXPCL_PANDAPHYSX PhysxScene : public PhysxObject, public PhysxEnums {
70
71PUBLISHED:
72 INLINE PhysxScene();
73 INLINE ~PhysxScene();
74
75 void simulate(float dt);
76 void fetch_results();
78 void set_timing_fixed(float maxTimestep=1.0f/60.0f, unsigned int maxIter=8);
79
81
82 void enable_contact_reporting(bool enabled);
83 bool is_contact_reporting_enabled() const;
84 void enable_trigger_reporting(bool enabled);
85 bool is_trigger_reporting_enabled() const;
86 void enable_controller_reporting(bool enabled);
87 bool is_controller_reporting_enabled() const;
88
89 INLINE void set_controller_shape_hit_callback(PT(CallbackObject) cbobj);
90 INLINE void set_controller_controller_hit_callback(PT(CallbackObject) cbobj);
91
92 void set_gravity(const LVector3f &gravity);
93
94 LVector3f get_gravity() const;
95 PhysxSceneStats2 get_stats2() const;
96 bool get_flag(PhysxSceneFlag flag) const;
97 bool is_hardware_scene() const;
98
99 // Actors
100 unsigned int get_num_actors() const;
101 PhysxActor *create_actor(PhysxActorDesc &desc);
102 PhysxActor *get_actor(unsigned int idx) const;
103 MAKE_SEQ(get_actors, get_num_actors, get_actor);
104
105 // Joints
106 unsigned int get_num_joints() const;
108 PhysxJoint *get_joint(unsigned int idx) const;
109 MAKE_SEQ(get_joints, get_num_joints, get_joint);
110
111 // Materials
112 unsigned int get_num_materials() const;
113 unsigned int get_hightest_material_index() const;
116 PhysxMaterial *get_material(unsigned int idx) const;
117 PhysxMaterial *get_material_from_index(unsigned int idx) const;
118 MAKE_SEQ(get_materials, get_num_materials, get_material);
119
120 // Controllers
121 unsigned int get_num_controllers() const;
123 PhysxController *get_controller(unsigned int idx) const;
124 MAKE_SEQ(get_controllers, get_num_controllers, get_controller);
125
126 // Force fields
127 unsigned int get_num_force_fields() const;
129 PhysxForceField *get_force_field(unsigned int idx) const;
130 MAKE_SEQ(get_force_fields, get_num_force_fields, get_force_field);
131
132 // Force field shape groups
133 unsigned int get_num_force_field_shape_groups() const;
136 MAKE_SEQ(get_force_field_shape_groups, get_num_force_field_shape_groups, get_force_field_shape_group);
137
138 // Cloths
139 unsigned int get_num_cloths() const;
141 PhysxCloth *get_cloth(unsigned int idx) const;
142 MAKE_SEQ(get_cloths, get_num_cloths, get_cloth);
143
144 // Soft bodies
145 unsigned int get_num_soft_bodies() const;
147 PhysxSoftBody *get_soft_body(unsigned int idx) const;
148 MAKE_SEQ(get_soft_bodies, get_num_soft_bodies, get_soft_body);
149
150 // Vehicles
151 unsigned int get_num_vehicles() const;
153 PhysxVehicle *get_vehicle(unsigned int idx) const;
154 MAKE_SEQ(get_vehicles, get_num_vehicles, get_vehicle);
155
156 // Raycast queries
157 bool raycast_any_shape(const PhysxRay &ray,
158 PhysxShapesType shapesType=ST_all,
160 PhysxGroupsMask *groups=nullptr) const;
161
163 PhysxShapesType shapesType=ST_all,
165 PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const;
166
168 PhysxShapesType shapesType=ST_all,
170 PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const;
171
172 bool raycast_any_bounds(const PhysxRay &ray,
173 PhysxShapesType shapesType=ST_all,
175 PhysxGroupsMask *groups=nullptr) const;
176
178 PhysxShapesType shapesType=ST_all,
180 PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const;
181
183 PhysxShapesType shapesType=ST_all,
185 PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const;
186
187 // Overlap queries
188 PhysxOverlapReport overlap_sphere_shapes(const LPoint3f &center, float radius,
189 PhysxShapesType shapesType=ST_all,
190 PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const;
191
192 PhysxOverlapReport overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius,
193 PhysxShapesType shapesType=ST_all,
194 PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const;
195
196 // Filters
197 void set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag, bool value);
198 void set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value);
199 void set_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag, bool value);
200 void set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable);
201 void set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2);
202 void set_filter_bool(bool flag);
203 void set_filter_constant0(const PhysxGroupsMask &mask);
204 void set_filter_constant1(const PhysxGroupsMask &mask);
205 void set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance);
206
207 bool get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag);
208 bool get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB);
209 bool get_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag);
210 bool get_group_collision_flag(unsigned int g1, unsigned int g2);
211 bool get_filter_bool() const;
214 PhysxFilterOp get_filter_op0() const;
215 PhysxFilterOp get_filter_op1() const;
216 PhysxFilterOp get_filter_op2() const;
217 PhysxConstraintDominance get_dominance_group_pair(unsigned int g1, unsigned int g2);
218
219PUBLISHED:
220 void release();
221
222 INLINE void ls() const;
223 INLINE void ls(std::ostream &out, int indent_level=0) const;
224
225public:
226 INLINE NxScene *ptr() const { return _ptr; };
227 INLINE NxControllerManager *cm() const { return _cm; };
228
229 void link(NxScene *ptr);
230 void unlink();
231
232 PhysxObjectCollection<PhysxMaterial> _materials;
233 PhysxObjectCollection<PhysxActor> _actors;
234 PhysxObjectCollection<PhysxJoint> _joints;
235 PhysxObjectCollection<PhysxForceField> _forcefields;
236 PhysxObjectCollection<PhysxForceFieldShapeGroup> _ffgroups;
237 PhysxObjectCollection<PhysxController> _controllers;
238 PhysxObjectCollection<PhysxVehicle> _vehicles;
239 PhysxObjectCollection<PhysxCloth> _cloths;
240 PhysxObjectCollection<PhysxSoftBody> _softbodies;
241
242 PhysxMaterial *get_wheel_shape_material();
243
244private:
245 NxScene *_ptr;
246 NxControllerManager *_cm;
247 PT(PhysxDebugGeomNode) _debugNode;
248 PT(PhysxMaterial) _wheelShapeMaterial;
249
250 PhysxContactReport _contact_report;
251 PhysxControllerReport _controller_report;
252 PhysxTriggerReport _trigger_report;
253
254 static PStatCollector _pcollector_fetch_results;
255 static PStatCollector _pcollector_update_transforms;
256 static PStatCollector _pcollector_debug_renderer;
257 static PStatCollector _pcollector_simulate;
258 static PStatCollector _pcollector_cloth;
259 static PStatCollector _pcollector_softbody;
260
261public:
262 static TypeHandle get_class_type() {
263 return _type_handle;
264 }
265 static void init_type() {
266 PhysxObject::init_type();
267 register_type(_type_handle, "PhysxScene",
268 PhysxObject::get_class_type());
269 }
270 virtual TypeHandle get_type() const {
271 return get_class_type();
272 }
273 virtual TypeHandle force_init_type() {
274 init_type();
275 return get_class_type();
276 }
277
278private:
279 static TypeHandle _type_handle;
280};
281
282#include "physxScene.I"
283
284#endif // PHYSXSCENE_H
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a generic object that can be assigned to a callback at various points in the rendering proces...
Descriptor for PhysxActor.
Actors are the main simulation objects.
Definition physxActor.h:44
Descriptor for PhysxCloth.
Expresses the dominance relationship of a constraint.
Descriptor class for a character controller.
Abstract base class for character controllers.
Renderable geometry which represents visualizations of physics objects.
This class exists just to provide scoping for the enums shared by PhysX classes.
Definition physxEnums.h:355
Descriptor class for force fields.
A force field effector.
128-bit bitmask class.
Abstract base class for joint descriptors.
Abstract base class for the different types of joints.
Definition physxJoint.h:32
32-bit bitmask class.
Definition physxMask.h:24
static PhysxMask all_on()
Returns a PhysxMask whose bits are all on.
Definition physxMask.cxx:20
Descriptor class for materials.
A class for describing a shape's surface properties.
Objects of this class are returned by the 'overlap shape' methods, for example overlapSphereShapes.
Represents an ray as an origin and direction.
Definition physxRay.h:26
This structure captures results for a single raycast query.
Objects of this class are returned by the 'raycast all' methods.
get_vehicle
Returns the n-th vehicle from the array of all the vehicles in the scene.
Definition physxScene.h:154
unsigned int get_hightest_material_index() const
Returns current highest valid material index.
PhysxSoftBody * create_soft_body(PhysxSoftBodyDesc &desc)
Creates a soft body in this scene.
void set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable)
Specifies if collision should be performed by a pair of shape groups.
get_num_force_fields
Gets the number of force fields in the scene.
Definition physxScene.h:130
void set_timing_fixed(float maxTimestep=1.0f/60.0f, unsigned int maxIter=8)
Sets simulation timing parameters used in simulate.
get_num_controllers
Return the number of controllers in the scene.
Definition physxScene.h:124
get_soft_body
Returns the n-th soft body from the array of all the soft bodies in the scene.
Definition physxScene.h:148
PhysxForceField * create_force_field(PhysxForceFieldDesc &desc)
Creates a force field in this scene.
void set_filter_constant0(const PhysxGroupsMask &mask)
Setups filtering's K0 value.
bool is_hardware_scene() const
Returns TRUE if the the scene is simulated in hardware.
get_cloth
Returns the n-th cloth from the array of all the cloths in the scene.
Definition physxScene.h:142
PhysxGroupsMask get_filter_constant1() const
Gets filtering constant K1.
void set_filter_constant1(const PhysxGroupsMask &mask)
Setups filtering's K1 value.
PhysxOverlapReport overlap_sphere_shapes(const LPoint3f &center, float radius, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const
Returns the set of shapes overlapped by the world-space sphere.
void simulate(float dt)
Advances the simulation by an elapsedTime time.
bool get_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag)
Retrieves a single flag set with PhysxScene::set_actor_group_pair_flag()
void set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value)
Disables or enables contact generation for a pair of shapes.
void set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag, bool value)
Sets the pair flags for the given pair of actors.
bool get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag)
Retrieves a single flag for the given pair of actors.
get_num_materials
Return the number of materials in the scene.
Definition physxScene.h:118
bool get_group_collision_flag(unsigned int g1, unsigned int g2)
Determines if collision detection is performed between a pair of groups.
void set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance)
Specifies the dominance behavior of constraints between two actors with two certain dominance groups.
void fetch_results()
Waits until the simulation has finished, and then updates the scene graph with with simulation result...
PhysxForceFieldShapeGroup * create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc)
Creates a new force field shape group in this scene.
PhysxFilterOp get_filter_op1() const
Retrieves the op1 filtering operation.
PhysxConstraintDominance get_dominance_group_pair(unsigned int g1, unsigned int g2)
Samples the dominance matrix.
PhysxRaycastHit raycast_closest_shape(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns the first shape that is hit along the ray.
void set_timing_variable()
Sets simulation timing parameters used in simulate.
PhysxFilterOp get_filter_op2() const
Retrieves the op2 filtering operation.
PhysxMaterial * get_material_from_index(unsigned int idx) const
Retrieves the material with the given material index.
get_material
Retrieves the n-th material from the array of materials.
Definition physxScene.h:118
PhysxRaycastReport raycast_all_shapes(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns a PhysxRaycastReport object which can be used to iterate over all shapes that have been hit b...
bool raycast_any_bounds(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr) const
Returns true if any axis aligned bounding box enclosing a shape is intersected by the ray.
get_force_field
Returns the n-th force field from the array of all the force fields in the scene.
Definition physxScene.h:130
void set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2)
Setups filtering operations.
get_controller
Retrieves the n-th controller within the scene.
Definition physxScene.h:124
PhysxFilterOp get_filter_op0() const
Retrieves the op0 filtering operation.
PhysxGroupsMask get_filter_constant0() const
Gets filtering constant K0.
PhysxJoint * create_joint(PhysxJointDesc &desc)
Creates a joint in this scene.
PhysxCloth * create_cloth(PhysxClothDesc &desc)
Creates a cloth in this scene.
PhysxVehicle * create_vehicle(PhysxVehicleDesc &desc)
Creates a vehicle in this scene.
PhysxMaterial * create_material(PhysxMaterialDesc &desc)
Creates a new PhysxMaterial.
get_num_cloths
Gets the number of cloths in the scene.
Definition physxScene.h:142
LVector3f get_gravity() const
Retrieves the current gravity setting.
PhysxRaycastReport raycast_all_bounds(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns a PhysxRaycastReport object which can be used to iterate over all shapes that have been enclo...
bool get_flag(PhysxSceneFlag flag) const
Return the specified scene flag flag.
void set_filter_bool(bool flag)
Setups filtering's boolean value.
bool raycast_any_shape(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr) const
Returns true if any shape is intersected by the ray.
bool get_filter_bool() const
Retrieves filtering's boolean value.
void set_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag, bool value)
With this method one can set contact reporting flags between actors belonging to a pair of groups.
get_joint
Retrieve the n-th joint from the array of all the joints in the scene.
Definition physxScene.h:109
get_num_soft_bodies
Gets the number of soft bodies in the scene.
Definition physxScene.h:148
PhysxController * create_controller(PhysxControllerDesc &controllerDesc)
Creates a new character controller.
get_num_vehicles
Returns the number of vehicles in the scene.
Definition physxScene.h:154
PhysxRaycastHit raycast_closest_bounds(const PhysxRay &ray, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const
Returns the first axis aligned bounding box enclosing a shape that is hit along the ray.
PhysxOverlapReport overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius, PhysxShapesType shapesType=ST_all, PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const
Returns the set of shapes overlapped by the world-space capsule.
PhysxDebugGeomNode * get_debug_geom_node()
Retrieves the debug geom node for this scene.
get_num_joints
Returns the number of joints in the scene (excluding "dead" joints).
Definition physxScene.h:109
get_force_field_shape_group
Returns the n-th force field shape group in this scene.
Definition physxScene.h:136
bool get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB)
Returns /true/ if contact generation between a pair of shapes is enabled, and /false/ if contact gene...
void set_gravity(const LVector3f &gravity)
Sets a constant gravity for the entire scene.
get_num_force_field_shape_groups
Gets the number of force field shape groups in the scene.
Definition physxScene.h:136
Abstract base class for shapes.
Definition physxShape.h:39
Descriptor for PhysxSoftBody.
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.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...