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();
77 void set_timing_variable();
78 void set_timing_fixed(float maxTimestep=1.0f/60.0f, unsigned int maxIter=8);
79
80 PhysxDebugGeomNode *get_debug_geom_node();
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;
107 PhysxJoint *create_joint(PhysxJointDesc &desc);
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;
114 PhysxMaterial *create_material(PhysxMaterialDesc &desc);
115 PhysxMaterial *create_material();
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;
122 PhysxController *create_controller(PhysxControllerDesc &controllerDesc);
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;
128 PhysxForceField *create_force_field(PhysxForceFieldDesc &desc);
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;
134 PhysxForceFieldShapeGroup *create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc);
135 PhysxForceFieldShapeGroup *get_force_field_shape_group(unsigned int idx) 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;
140 PhysxCloth *create_cloth(PhysxClothDesc &desc);
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;
146 PhysxSoftBody *create_soft_body(PhysxSoftBodyDesc &desc);
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;
152 PhysxVehicle *create_vehicle(PhysxVehicleDesc &desc);
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
162 PhysxRaycastHit raycast_closest_shape(const PhysxRay &ray,
163 PhysxShapesType shapesType=ST_all,
165 PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const;
166
167 PhysxRaycastReport raycast_all_shapes(const PhysxRay &ray,
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
177 PhysxRaycastHit raycast_closest_bounds(const PhysxRay &ray,
178 PhysxShapesType shapesType=ST_all,
180 PhysxGroupsMask *groups=nullptr, bool smoothNormal=true) const;
181
182 PhysxRaycastReport raycast_all_bounds(const PhysxRay &ray,
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;
212 PhysxGroupsMask get_filter_constant0() const;
213 PhysxGroupsMask get_filter_constant1() 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
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...
A lightweight class that represents a single element that may be timed and/or counted via stats.
Descriptor for PhysxActor.
Actors are the main simulation objects.
Definition physxActor.h:44
Descriptor for PhysxCloth.
Expresses the dominance relationship of a constraint.
Implementation of the NxUserContactReport interface.
Descriptor class for a character controller.
Implementation of the NxUserControllerHitReport interface.
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.
A scene is a collection of bodies, constraints, and effectors which can interact.
Definition physxScene.h:69
Abstract base class for shapes.
Definition physxShape.h:39
Descriptor for PhysxSoftBody.
Implementation of the NxUserTriggerReport interface.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
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(),...