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 */
21 void PhysxSceneDesc::
22 set_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 */
31LVector3f PhysxSceneDesc::
32 get_gravity() const {
33
34 return PhysxManager::nxVec3_to_vec3(_desc.gravity);
35}
36
37/**
38 * Raise or lower individual scene flags.
39 */
40 void PhysxSceneDesc::
41 set_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 */
54 bool PhysxSceneDesc::
55 get_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 */
72 void PhysxSceneDesc::
73 set_max_bounds(PhysxBounds3 &bounds) {
74
75 _desc.maxBounds = &(bounds._bounds);
76}
77
78/**
79 *
80 */
81 PhysxBounds3 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 */
92 void PhysxSceneDesc::
93 set_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 */
102 void PhysxSceneDesc::
103 set_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::
112 get_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::
122 get_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 */
131 void PhysxSceneDesc::
132 set_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 */
142 void PhysxSceneDesc::
143 set_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 */
153 void PhysxSceneDesc::
154 set_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 */
163 unsigned int PhysxSceneDesc::
164 get_subdivision_level() const {
165
166 return _desc.subdivisionLevel;
167}
168
169/**
170 * Returns the number of broadphase cells along the grid x-axis.
171 */
172 unsigned int PhysxSceneDesc::
173 get_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 */
181 unsigned int PhysxSceneDesc::
182 get_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 */
205 void PhysxSceneDesc::
206 set_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::
215 get_bp_type() const {
216
217 return (PhysxBroadPhaseType)_desc.bpType;
218}
PhysxBounds3
Represention of a axis aligned bounding box.
Definition physxBounds3.h:29
PhysxManager::vec3_to_nxVec3
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition physxManager.I:27
PhysxManager::nxVec3_to_vec3
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition physxManager.I:36
PhysxSceneDesc::get_num_grid_cells_y
unsigned int get_num_grid_cells_y() const
Returns the number of broadphase cells along the grid y-axis.
Definition physxSceneDesc.cxx:182
PhysxSceneDesc::get_gravity
LVector3f get_gravity() const
Get the gravity vector.
Definition physxSceneDesc.cxx:32
PhysxSceneDesc::get_dynamic_structure
PhysxPruningStructure get_dynamic_structure() const
Returns the subdivision level for acceleration structures used for scene queries.
Definition physxSceneDesc.cxx:122
PhysxSceneDesc::get_subdivision_level
unsigned int get_subdivision_level() const
Returns the subdivision level for acceleration structures used for scene queries.
Definition physxSceneDesc.cxx:164
PhysxSceneDesc::set_dynamic_structure
void set_dynamic_structure(PhysxPruningStructure value)
Defines the subdivision level for acceleration structures used for scene queries.
Definition physxSceneDesc.cxx:103
PhysxSceneDesc::set_num_grid_cells_x
void set_num_grid_cells_x(unsigned int value)
Defines the number of broadphase cells along the grid x-axis.
Definition physxSceneDesc.cxx:143
PhysxSceneDesc::get_static_structure
PhysxPruningStructure get_static_structure() const
Returns the structure used to store static objects.
Definition physxSceneDesc.cxx:112
PhysxSceneDesc::set_max_bounds
void set_max_bounds(PhysxBounds3 &bounds)
Set the max scene bounds.
Definition physxSceneDesc.cxx:73
PhysxSceneDesc::get_bp_type
PhysxBroadPhaseType get_bp_type() const
Returns the type of broadphase to use.
Definition physxSceneDesc.cxx:215
PhysxSceneDesc::set_gravity
void set_gravity(const LVector3f &gravity)
Sets the gravity vector.
Definition physxSceneDesc.cxx:22
PhysxSceneDesc::get_num_grid_cells_x
unsigned int get_num_grid_cells_x() const
Returns the number of broadphase cells along the grid x-axis.
Definition physxSceneDesc.cxx:173
PhysxSceneDesc::set_static_structure
void set_static_structure(PhysxPruningStructure value)
Defines the structure used to store static objects.
Definition physxSceneDesc.cxx:93
PhysxSceneDesc::get_flag
bool get_flag(PhysxSceneFlag flag) const
Returns the specified scene flag.
Definition physxSceneDesc.cxx:55
PhysxSceneDesc::set_num_grid_cells_y
void set_num_grid_cells_y(unsigned int value)
Defines the number of broadphase cells along the grid y-axis.
Definition physxSceneDesc.cxx:154
PhysxSceneDesc::set_subdivision_level
void set_subdivision_level(unsigned int value)
Defines the subdivision level for acceleration structures used for scene queries.
Definition physxSceneDesc.cxx:132
PhysxSceneDesc::set_bp_type
void set_bp_type(PhysxBroadPhaseType value)
Defines which type of broadphase to use.
Definition physxSceneDesc.cxx:206
PhysxSceneDesc::set_flag
void set_flag(PhysxSceneFlag flag, bool value)
Raise or lower individual scene flags.
Definition physxSceneDesc.cxx:41
physxBounds3.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxManager.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxSceneDesc.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.