Panda3D
Loading...
Searching...
No Matches
physxSceneDesc.cxx
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 physxSceneDesc.cxx
10 * @author enn0x
11 * @date 2009-09-05
12 */
13
14#include "physxSceneDesc.h"
15#include "physxManager.h"
16#include "physxBounds3.h"
17
18/**
19 * Sets the gravity vector.
20 */
22set_gravity(const LVector3f &gravity) {
23
24 nassertv_always(!gravity.is_nan());
25 _desc.gravity = PhysxManager::vec3_to_nxVec3(gravity);
26}
27
28/**
29 * Get the gravity vector.
30 */
32get_gravity() const {
33
34 return PhysxManager::nxVec3_to_vec3(_desc.gravity);
35}
36
37/**
38 * Raise or lower individual scene flags.
39 */
41set_flag(const PhysxSceneFlag flag, bool value) {
42
43 if (value == true) {
44 _desc.flags |= flag;
45 }
46 else {
47 _desc.flags &= ~(flag);
48 }
49}
50
51/**
52 * Returns the specified scene flag.
53 */
55get_flag(const PhysxSceneFlag flag) const {
56
57 return (_desc.flags & flag) ? true : false;
58}
59
60/**
61 * Set the max scene bounds.
62 *
63 * If scene bounds are provided (maxBounds in the descriptor), the SDK takes
64 * advantage of this information to accelerate scene-level collision queries
65 * (e.g. raycasting). When using maxBounds, you have to make sure created
66 * objects stay within the scene bounds. In particular, the position of
67 * dynamic shapes should stay within the provided bounds. Otherwise the
68 * shapes outside the bounds will not be taken into account by all scene
69 * queries (raycasting, sweep tests, overlap tests, etc). They will
70 * nonetheless still work correctly for the main physics simulation.
71 */
74
75 _desc.maxBounds = &(bounds._bounds);
76}
77
78/**
79 *
80 */
81PhysxBounds3 PhysxSceneDesc::
82get_max_bounds() const {
83 assert(false /* Not implemented */);
84
85 // PhysxBounds3 value; value._bounds = *(_desc.maxBounds); return value;
86 return PhysxBounds3();
87}
88
89/**
90 * Defines the structure used to store static objects.
91 */
93set_static_structure(PhysxPruningStructure value) {
94
95 _desc.staticStructure = (NxPruningStructure)value;
96}
97
98/**
99 * Defines the subdivision level for acceleration structures used for scene
100 * queries. This is only used when maxBounds are defined!
101 */
103set_dynamic_structure(PhysxPruningStructure value) {
104
105 _desc.dynamicStructure = (NxPruningStructure)value;
106}
107
108/**
109 * Returns the structure used to store static objects.
110 */
111PhysxEnums::PhysxPruningStructure PhysxSceneDesc::
112get_static_structure() const {
113
114 return (PhysxPruningStructure)_desc.staticStructure;
115}
116
117/**
118 * Returns the subdivision level for acceleration structures used for scene
119 * queries.
120 */
121PhysxEnums::PhysxPruningStructure PhysxSceneDesc::
122get_dynamic_structure() const {
123
124 return (PhysxPruningStructure)_desc.dynamicStructure;
125}
126
127/**
128 * Defines the subdivision level for acceleration structures used for scene
129 * queries. This is only used when maxBounds are defined!
130 */
132set_subdivision_level(unsigned int value) {
133
134 _desc.subdivisionLevel = (NxU32)value;
135}
136
137/**
138 * Defines the number of broadphase cells along the grid x-axis. Must be
139 * power of two. Max is 8 at the moment. The broadphase type must be set to
140 * BPT_sap_multi for this parameter to have an effect.
141 */
143set_num_grid_cells_x(unsigned int value) {
144
145 _desc.nbGridCellsX = (NxU32)value;
146}
147
148/**
149 * Defines the number of broadphase cells along the grid y-axis. Must be
150 * power of two. Max is 8 at the moment. The broadphase type must be set to
151 * BPT_sap_multi for this parameter to have an effect.
152 */
154set_num_grid_cells_y(unsigned int value) {
155
156 _desc.nbGridCellsY = (NxU32)value;
157}
158
159/**
160 * Returns the subdivision level for acceleration structures used for scene
161 * queries.
162 */
164get_subdivision_level() const {
165
166 return _desc.subdivisionLevel;
167}
168
169/**
170 * Returns the number of broadphase cells along the grid x-axis.
171 */
173get_num_grid_cells_x() const {
174
175 return _desc.nbGridCellsX;
176}
177
178/**
179 * Returns the number of broadphase cells along the grid y-axis.
180 */
182get_num_grid_cells_y() const {
183
184 return _desc.nbGridCellsY;
185}
186
187/**
188 * Defines which type of broadphase to use.
189 *
190 * (1) BPT_sap_single: A sweep-and-prune (SAP) algorithm to find pairs of
191 * potentially colliding shapes.
192 *
193 * (2) BPT_sap_multi: A multi sweep-and-prune algorithm to find pairs of
194 * potentially colliding shapes. Uses a configurable 2D grid to divide the
195 * scene space into cells. The potentially overlapping shape pairs are
196 * detected in each cell and the information is merged together. This
197 * approach is usually faster than BPT_sap_single in scenarios with many
198 * shapes and a high creation/deletion rate of shapes. However, the amount of
199 * memory required is considerably higher depending on the number of grid
200 * cells used. The following extra parameters need to be defined: -
201 * PhysxSceneDesc.set_max_bounds - PhysxSceneDesc.set_num_grid_cells_x -
202 * PhysxSceneDesc.set_num_grid_cells_y (the scene up direction is set via
203 * config options)
204 */
206set_bp_type(PhysxBroadPhaseType value) {
207
208 _desc.bpType = (NxBroadPhaseType)value;
209}
210
211/**
212 * Returns the type of broadphase to use.
213 */
214PhysxEnums::PhysxBroadPhaseType PhysxSceneDesc::
215get_bp_type() const {
216
217 return (PhysxBroadPhaseType)_desc.bpType;
218}
Represention of a axis aligned bounding box.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
unsigned int get_num_grid_cells_y() const
Returns the number of broadphase cells along the grid y-axis.
LVector3f get_gravity() const
Get the gravity vector.
PhysxPruningStructure get_dynamic_structure() const
Returns the subdivision level for acceleration structures used for scene queries.
unsigned int get_subdivision_level() const
Returns the subdivision level for acceleration structures used for scene queries.
void set_dynamic_structure(PhysxPruningStructure value)
Defines the subdivision level for acceleration structures used for scene queries.
void set_num_grid_cells_x(unsigned int value)
Defines the number of broadphase cells along the grid x-axis.
PhysxPruningStructure get_static_structure() const
Returns the structure used to store static objects.
void set_max_bounds(PhysxBounds3 &bounds)
Set the max scene bounds.
PhysxBroadPhaseType get_bp_type() const
Returns the type of broadphase to use.
void set_gravity(const LVector3f &gravity)
Sets the gravity vector.
unsigned int get_num_grid_cells_x() const
Returns the number of broadphase cells along the grid x-axis.
void set_static_structure(PhysxPruningStructure value)
Defines the structure used to store static objects.
bool get_flag(PhysxSceneFlag flag) const
Returns the specified scene flag.
void set_num_grid_cells_y(unsigned int value)
Defines the number of broadphase cells along the grid y-axis.
void set_subdivision_level(unsigned int value)
Defines the subdivision level for acceleration structures used for scene queries.
void set_bp_type(PhysxBroadPhaseType value)
Defines which type of broadphase to use.
void set_flag(PhysxSceneFlag flag, bool value)
Raise or lower individual scene flags.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.