Panda3D
physxSceneDesc.cxx
1 // Filename: physxSceneDesc.cxx
2 // Created by: enn0x (05Sep09)
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 #include "physxSceneDesc.h"
16 #include "physxManager.h"
17 #include "physxBounds3.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: PhysxSceneDesc::set_gravity
21 // Access: Published
22 // Description: Sets the gravity vector.
23 ////////////////////////////////////////////////////////////////////
25 set_gravity(const LVector3f &gravity) {
26 
27  nassertv_always(!gravity.is_nan());
28  _desc.gravity = PhysxManager::vec3_to_nxVec3(gravity);
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: PhysxSceneDesc::get_gravity
33 // Access: Published
34 // Description: Get the gravity vector.
35 ////////////////////////////////////////////////////////////////////
37 get_gravity() const {
38 
39  return PhysxManager::nxVec3_to_vec3(_desc.gravity);
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: PhysxSceneDesc::set_flag
44 // Access: Published
45 // Description: Raise or lower individual scene flags.
46 ////////////////////////////////////////////////////////////////////
48 set_flag(const PhysxSceneFlag flag, bool value) {
49 
50  if (value == true) {
51  _desc.flags |= flag;
52  }
53  else {
54  _desc.flags &= ~(flag);
55  }
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: PhysxSceneDesc::get_flag
60 // Access: Published
61 // Description: Returns the specified scene flag.
62 ////////////////////////////////////////////////////////////////////
64 get_flag(const PhysxSceneFlag flag) const {
65 
66  return (_desc.flags & flag) ? true : false;
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: PhysxSceneDesc::set_max_bounds
71 // Access: Published
72 // Description: Set the max scene bounds.
73 //
74 // If scene bounds are provided (maxBounds in the
75 // descriptor), the SDK takes advantage of this
76 // information to accelerate scene-level collision
77 // queries (e.g. raycasting). When using maxBounds,
78 // you have to make sure created objects stay within
79 // the scene bounds. In particular, the position of
80 // dynamic shapes should stay within the provided
81 // bounds. Otherwise the shapes outside the bounds
82 // will not be taken into account by all scene queries
83 // (raycasting, sweep tests, overlap tests, etc). They
84 // will nonetheless still work correctly for the main
85 // physics simulation.
86 ////////////////////////////////////////////////////////////////////
89 
90  _desc.maxBounds = &(bounds._bounds);
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: PhysxSceneDesc::get_max_bounds
95 // Access: Published
96 // Description:
97 ////////////////////////////////////////////////////////////////////
98 PhysxBounds3 PhysxSceneDesc::
99 get_max_bounds() const {
100  assert(false /* Not implemented */);
101 
102  //PhysxBounds3 value;
103  //value._bounds = *(_desc.maxBounds);
104  //return value;
105  return PhysxBounds3();
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: PhysxSceneDesc::set_static_structure
110 // Access: Published
111 // Description: Defines the structure used to store static
112 // objects.
113 ////////////////////////////////////////////////////////////////////
114 void PhysxSceneDesc::
115 set_static_structure(PhysxPruningStructure value) {
116 
117  _desc.staticStructure = (NxPruningStructure)value;
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: PhysxSceneDesc::set_dynamic_structure
122 // Access: Published
123 // Description: Defines the subdivision level for acceleration
124 // structures used for scene queries.
125 // This is only used when maxBounds are defined!
126 ////////////////////////////////////////////////////////////////////
127 void PhysxSceneDesc::
128 set_dynamic_structure(PhysxPruningStructure value) {
129 
130  _desc.dynamicStructure = (NxPruningStructure)value;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: PhysxSceneDesc::get_static_structure
135 // Access: Published
136 // Description: Returns the structure used to store static
137 // objects.
138 ////////////////////////////////////////////////////////////////////
139 PhysxEnums::PhysxPruningStructure PhysxSceneDesc::
141 
142  return (PhysxPruningStructure)_desc.staticStructure;
143 }
144 
145 ////////////////////////////////////////////////////////////////////
146 // Function: PhysxSceneDesc::get_dynamic_structure
147 // Access: Published
148 // Description: Returns the subdivision level for acceleration
149 // structures used for scene queries.
150 ////////////////////////////////////////////////////////////////////
151 PhysxEnums::PhysxPruningStructure PhysxSceneDesc::
153 
154  return (PhysxPruningStructure)_desc.dynamicStructure;
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: PhysxSceneDesc::set_subdivision_level
159 // Access: Published
160 // Description: Defines the subdivision level for acceleration
161 // structures used for scene queries.
162 // This is only used when maxBounds are defined!
163 ////////////////////////////////////////////////////////////////////
164 void PhysxSceneDesc::
165 set_subdivision_level(unsigned int value) {
166 
167  _desc.subdivisionLevel = (NxU32)value;
168 }
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: PhysxSceneDesc::set_num_grid_cells_x
172 // Access: Published
173 // Description: Defines the number of broadphase cells along the
174 // grid x-axis. Must be power of two. Max is 8 at the
175 // moment. The broadphase type must be set to
176 // BPT_sap_multi for this parameter to have
177 // an effect.
178 ////////////////////////////////////////////////////////////////////
179 void PhysxSceneDesc::
180 set_num_grid_cells_x(unsigned int value) {
181 
182  _desc.nbGridCellsX = (NxU32)value;
183 }
184 
185 ////////////////////////////////////////////////////////////////////
186 // Function: PhysxSceneDesc::set_num_grid_cells_y
187 // Access: Published
188 // Description: Defines the number of broadphase cells along the
189 // grid y-axis. Must be power of two. Max is 8 at the
190 // moment. The broadphase type must be set to
191 // BPT_sap_multi for this parameter to have
192 // an effect.
193 ////////////////////////////////////////////////////////////////////
194 void PhysxSceneDesc::
195 set_num_grid_cells_y(unsigned int value) {
196 
197  _desc.nbGridCellsY = (NxU32)value;
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: PhysxSceneDesc::get_subdivision_level
202 // Access: Published
203 // Description: Returns the subdivision level for acceleration
204 // structures used for scene queries.
205 ////////////////////////////////////////////////////////////////////
206 unsigned int PhysxSceneDesc::
208 
209  return _desc.subdivisionLevel;
210 }
211 
212 ////////////////////////////////////////////////////////////////////
213 // Function: PhysxSceneDesc::get_num_grid_cells_x
214 // Access: Published
215 // Description: Returns the number of broadphase cells along the
216 // grid x-axis.
217 ////////////////////////////////////////////////////////////////////
218 unsigned int PhysxSceneDesc::
220 
221  return _desc.nbGridCellsX;
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: PhysxSceneDesc::get_num_grid_cells_y
226 // Access: Published
227 // Description: Returns the number of broadphase cells along the
228 // grid y-axis.
229 ////////////////////////////////////////////////////////////////////
230 unsigned int PhysxSceneDesc::
232 
233  return _desc.nbGridCellsY;
234 }
235 
236 ////////////////////////////////////////////////////////////////////
237 // Function: PhysxSceneDesc::set_bp_type
238 // Access: Published
239 // Description: Defines which type of broadphase to use.
240 //
241 // (1) BPT_sap_single: A sweep-and-prune (SAP)
242 // algorithm to find pairs of potentially colliding
243 // shapes.
244 //
245 // (2) BPT_sap_multi: A multi sweep-and-prune
246 // algorithm to find pairs of potentially colliding
247 // shapes. Uses a configurable 2D grid to divide the
248 // scene space into cells. The potentially overlapping
249 // shape pairs are detected in each cell and the
250 // information is merged together. This approach is
251 // usually faster than BPT_sap_single in scenarios
252 // with many shapes and a high creation/deletion rate
253 // of shapes. However, the amount of memory required
254 // is considerably higher depending on the number of
255 // grid cells used.
256 // The following extra parameters need to be defined:
257 // - PhysxSceneDesc.set_max_bounds
258 // - PhysxSceneDesc.set_num_grid_cells_x
259 // - PhysxSceneDesc.set_num_grid_cells_y
260 // (the scene up direction is set via config options)
261 ////////////////////////////////////////////////////////////////////
262 void PhysxSceneDesc::
263 set_bp_type(PhysxBroadPhaseType value) {
264 
265  _desc.bpType = (NxBroadPhaseType)value;
266 }
267 
268 ////////////////////////////////////////////////////////////////////
269 // Function: PhysxSceneDesc::get_bp_type
270 // Access: Published
271 // Description: Returns the type of broadphase to use.
272 ////////////////////////////////////////////////////////////////////
273 PhysxEnums::PhysxBroadPhaseType PhysxSceneDesc::
274 get_bp_type() const {
275 
276  return (PhysxBroadPhaseType)_desc.bpType;
277 }
278 
bool get_flag(PhysxSceneFlag flag) const
Returns the specified scene flag.
unsigned int get_num_grid_cells_x() const
Returns the number of broadphase cells along the grid x-axis.
LVector3f get_gravity() const
Get the gravity vector.
unsigned int get_subdivision_level() const
Returns the subdivision level for acceleration structures used for scene queries. ...
Represention of a axis aligned bounding box.
Definition: physxBounds3.h:32
unsigned int get_num_grid_cells_y() const
Returns the number of broadphase cells along the grid y-axis.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
void set_bp_type(PhysxBroadPhaseType value)
Defines which type of broadphase to use.
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:464
void set_static_structure(PhysxPruningStructure value)
Defines the structure used to store static objects.
void set_num_grid_cells_x(unsigned int value)
Defines the number of broadphase cells along the grid x-axis.
void set_gravity(const LVector3f &gravity)
Sets the gravity vector.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:44
PhysxPruningStructure get_dynamic_structure() const
Returns the subdivision level for acceleration structures used for scene queries. ...
PhysxBroadPhaseType get_bp_type() const
Returns the type of broadphase to use.
void set_flag(PhysxSceneFlag flag, bool value)
Raise or lower individual scene flags.
void set_dynamic_structure(PhysxPruningStructure value)
Defines the subdivision level for acceleration structures used for scene queries. ...
void set_num_grid_cells_y(unsigned int value)
Defines the number of broadphase cells along the grid y-axis.
void set_max_bounds(PhysxBounds3 &bounds)
Set the max scene bounds.
PhysxPruningStructure get_static_structure() const
Returns the structure used to store static objects.
void set_subdivision_level(unsigned int value)
Defines the subdivision level for acceleration structures used for scene queries. ...