Panda3D

physxSceneDesc.cxx

00001 // Filename: physxSceneDesc.cxx
00002 // Created by:  enn0x (05Sep09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "physxSceneDesc.h"
00016 #include "physxManager.h"
00017 #include "physxBounds3.h"
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: PhysxSceneDesc::set_gravity
00021 //       Access: Published
00022 //  Description: Sets the gravity vector.
00023 ////////////////////////////////////////////////////////////////////
00024 void PhysxSceneDesc::
00025 set_gravity(const LVector3f &gravity) {
00026 
00027   nassertv_always(!gravity.is_nan());
00028   _desc.gravity = PhysxManager::vec3_to_nxVec3(gravity);
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: PhysxSceneDesc::get_gravity
00033 //       Access: Published
00034 //  Description: Get the gravity vector.
00035 ////////////////////////////////////////////////////////////////////
00036 LVector3f PhysxSceneDesc::
00037 get_gravity() const {
00038 
00039   return PhysxManager::nxVec3_to_vec3(_desc.gravity);
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: PhysxSceneDesc::set_flag
00044 //       Access: Published
00045 //  Description: Raise or lower individual scene flags.
00046 ////////////////////////////////////////////////////////////////////
00047 void PhysxSceneDesc::
00048 set_flag(const PhysxSceneFlag flag, bool value) {
00049 
00050   if (value == true) {
00051     _desc.flags |= flag;
00052   }
00053   else {
00054     _desc.flags &= ~(flag);
00055   }
00056 }
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //     Function: PhysxSceneDesc::get_flag
00060 //       Access: Published
00061 //  Description: Returns the specified scene flag.
00062 ////////////////////////////////////////////////////////////////////
00063 bool PhysxSceneDesc::
00064 get_flag(const PhysxSceneFlag flag) const {
00065 
00066   return (_desc.flags & flag) ? true : false;
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: PhysxSceneDesc::set_max_bounds
00071 //       Access: Published
00072 //  Description: Set the max scene bounds. 
00073 //
00074 //               If scene bounds are provided (maxBounds in the
00075 //               descriptor), the SDK takes advantage of this
00076 //               information to accelerate scene-level collision
00077 //               queries (e.g. raycasting). When using maxBounds,
00078 //               you have to make sure created objects stay within
00079 //               the scene bounds. In particular, the position of
00080 //               dynamic shapes should stay within the provided
00081 //               bounds. Otherwise the shapes outside the bounds
00082 //               will not be taken into account by all scene queries
00083 //               (raycasting, sweep tests, overlap tests, etc). They
00084 //               will nonetheless still work correctly for the main
00085 //               physics simulation.
00086 ////////////////////////////////////////////////////////////////////
00087 void PhysxSceneDesc::
00088 set_max_bounds(PhysxBounds3 &bounds) {
00089 
00090   _desc.maxBounds = &(bounds._bounds);
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: PhysxSceneDesc::get_max_bounds
00095 //       Access: Published
00096 //  Description: 
00097 ////////////////////////////////////////////////////////////////////
00098 PhysxBounds3 PhysxSceneDesc::
00099 get_max_bounds() const {
00100 
00101   throw "Not Implemented";
00102 
00103   //PhysxBounds3 value;
00104   //value._bounds = *(_desc.maxBounds);
00105   //return value;
00106 }
00107 
00108 ////////////////////////////////////////////////////////////////////
00109 //     Function: PhysxSceneDesc::set_static_structure
00110 //       Access: Published
00111 //  Description: Defines the structure used to store static
00112 //               objects.
00113 ////////////////////////////////////////////////////////////////////
00114 void PhysxSceneDesc::
00115 set_static_structure(PhysxPruningStructure value) {
00116 
00117   _desc.staticStructure = (NxPruningStructure)value;
00118 }
00119 
00120 ////////////////////////////////////////////////////////////////////
00121 //     Function: PhysxSceneDesc::set_dynamic_structure
00122 //       Access: Published
00123 //  Description: Defines the subdivision level for acceleration
00124 //               structures used for scene queries.
00125 //               This is only used when maxBounds are defined!
00126 ////////////////////////////////////////////////////////////////////
00127 void PhysxSceneDesc::
00128 set_dynamic_structure(PhysxPruningStructure value) {
00129 
00130   _desc.dynamicStructure = (NxPruningStructure)value;
00131 }
00132 
00133 ////////////////////////////////////////////////////////////////////
00134 //     Function: PhysxSceneDesc::get_static_structure
00135 //       Access: Published
00136 //  Description: Returns the structure used to store static
00137 //               objects.
00138 ////////////////////////////////////////////////////////////////////
00139 PhysxEnums::PhysxPruningStructure PhysxSceneDesc::
00140 get_static_structure() const {
00141 
00142   return (PhysxPruningStructure)_desc.staticStructure;
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: PhysxSceneDesc::get_dynamic_structure
00147 //       Access: Published
00148 //  Description: Returns the subdivision level for acceleration
00149 //               structures used for scene queries.
00150 ////////////////////////////////////////////////////////////////////
00151 PhysxEnums::PhysxPruningStructure PhysxSceneDesc::
00152 get_dynamic_structure() const {
00153 
00154   return (PhysxPruningStructure)_desc.dynamicStructure;
00155 }
00156 
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: PhysxSceneDesc::set_subdivision_level
00159 //       Access: Published
00160 //  Description: Defines the subdivision level for acceleration
00161 //               structures used for scene queries. 
00162 //               This is only used when maxBounds are defined!
00163 ////////////////////////////////////////////////////////////////////
00164 void PhysxSceneDesc::
00165 set_subdivision_level(unsigned int value) {
00166 
00167   _desc.subdivisionLevel = (NxU32)value;
00168 }
00169 
00170 ////////////////////////////////////////////////////////////////////
00171 //     Function: PhysxSceneDesc::set_num_grid_cells_x
00172 //       Access: Published
00173 //  Description: Defines the number of broadphase cells along the
00174 //               grid x-axis. Must be power of two. Max is 8 at the
00175 //               moment. The broadphase type must be set to
00176 //               BPT_sap_multi for this parameter to have
00177 //               an effect.
00178 ////////////////////////////////////////////////////////////////////
00179 void PhysxSceneDesc::
00180 set_num_grid_cells_x(unsigned int value) {
00181 
00182   _desc.nbGridCellsX = (NxU32)value;
00183 }
00184 
00185 ////////////////////////////////////////////////////////////////////
00186 //     Function: PhysxSceneDesc::set_num_grid_cells_y
00187 //       Access: Published
00188 //  Description: Defines the number of broadphase cells along the
00189 //               grid y-axis. Must be power of two. Max is 8 at the
00190 //               moment. The broadphase type must be set to
00191 //               BPT_sap_multi for this parameter to have
00192 //               an effect.
00193 ////////////////////////////////////////////////////////////////////
00194 void PhysxSceneDesc::
00195 set_num_grid_cells_y(unsigned int value) {
00196 
00197   _desc.nbGridCellsY = (NxU32)value;
00198 }
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //     Function: PhysxSceneDesc::get_subdivision_level
00202 //       Access: Published
00203 //  Description: Returns the subdivision level for acceleration
00204 //               structures used for scene queries. 
00205 ////////////////////////////////////////////////////////////////////
00206 unsigned int PhysxSceneDesc::
00207 get_subdivision_level() const {
00208 
00209   return _desc.subdivisionLevel;
00210 }
00211 
00212 ////////////////////////////////////////////////////////////////////
00213 //     Function: PhysxSceneDesc::get_num_grid_cells_x
00214 //       Access: Published
00215 //  Description: Returns the number of broadphase cells along the
00216 //               grid x-axis.
00217 ////////////////////////////////////////////////////////////////////
00218 unsigned int PhysxSceneDesc::
00219 get_num_grid_cells_x() const {
00220 
00221   return _desc.nbGridCellsX;
00222 }
00223 
00224 ////////////////////////////////////////////////////////////////////
00225 //     Function: PhysxSceneDesc::get_num_grid_cells_y
00226 //       Access: Published
00227 //  Description: Returns the number of broadphase cells along the
00228 //               grid y-axis.
00229 ////////////////////////////////////////////////////////////////////
00230 unsigned int PhysxSceneDesc::
00231 get_num_grid_cells_y() const {
00232 
00233   return _desc.nbGridCellsY;
00234 }
00235 
00236 ////////////////////////////////////////////////////////////////////
00237 //     Function: PhysxSceneDesc::set_bp_type
00238 //       Access: Published
00239 //  Description: Defines which type of broadphase to use.
00240 //
00241 //               (1) BPT_sap_single: A sweep-and-prune (SAP)
00242 //               algorithm to find pairs of potentially colliding
00243 //               shapes.
00244 //
00245 //               (2) BPT_sap_multi: A multi sweep-and-prune
00246 //               algorithm to find pairs of potentially colliding
00247 //               shapes. Uses a configurable 2D grid to divide the
00248 //               scene space into cells. The potentially overlapping
00249 //               shape pairs are detected in each cell and the
00250 //               information is merged together. This approach is
00251 //               usually faster than BPT_sap_single in scenarios
00252 //               with many shapes and a high creation/deletion rate
00253 //               of shapes. However, the amount of memory required
00254 //               is considerably higher depending on the number of
00255 //               grid cells used.
00256 //               The following extra parameters need to be defined: 
00257 //               - PhysxSceneDesc.set_max_bounds
00258 //               - PhysxSceneDesc.set_num_grid_cells_x
00259 //               - PhysxSceneDesc.set_num_grid_cells_y
00260 //               (the scene up direction is set via config options)
00261 ////////////////////////////////////////////////////////////////////
00262 void PhysxSceneDesc::
00263 set_bp_type(PhysxBroadPhaseType value) {
00264 
00265   _desc.bpType = (NxBroadPhaseType)value;
00266 }
00267 
00268 ////////////////////////////////////////////////////////////////////
00269 //     Function: PhysxSceneDesc::get_bp_type
00270 //       Access: Published
00271 //  Description: Returns the type of broadphase to use.
00272 ////////////////////////////////////////////////////////////////////
00273 PhysxEnums::PhysxBroadPhaseType PhysxSceneDesc::
00274 get_bp_type() const {
00275 
00276   return (PhysxBroadPhaseType)_desc.bpType;
00277 }
00278 
 All Classes Functions Variables Enumerations