Panda3D
|
00001 // Filename: physxShapeDesc.cxx 00002 // Created by: enn0x (08Sep09) 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 "physxShapeDesc.h" 00016 #include "physxManager.h" 00017 #include "physxMaterial.h" 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: PhysxShapeDesc::set_name 00021 // Access: Published 00022 // Description: Sets a possible debug name. 00023 //////////////////////////////////////////////////////////////////// 00024 void PhysxShapeDesc:: 00025 set_name(const char *name) { 00026 00027 _name = name ? name : ""; 00028 ptr()->name = _name.c_str(); 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: PhysxShapeDesc::set_trigger 00033 // Access: Published 00034 // Description: This shape will become a trigger shape if this 00035 // parameter is set to TRUE. It won't take part in 00036 // collisions, but trigger events if some other 00037 // shape passes through it. 00038 //////////////////////////////////////////////////////////////////// 00039 void PhysxShapeDesc:: 00040 set_trigger(bool value) { 00041 00042 if (value == true) { 00043 ptr()->shapeFlags |= NX_TRIGGER_ENABLE; 00044 } 00045 else { 00046 ptr()->shapeFlags &= ~(NX_TRIGGER_ENABLE); 00047 } 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: PhysxShapeDesc::set_local_pos 00052 // Access: Published 00053 // Description: 00054 //////////////////////////////////////////////////////////////////// 00055 void PhysxShapeDesc:: 00056 set_local_pos(const LPoint3f &pos) { 00057 00058 nassertv(!pos.is_nan()); 00059 ptr()->localPose.t = PhysxManager::point3_to_nxVec3(pos); 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: PhysxShapeDesc::set_local_mat 00064 // Access: Published 00065 // Description: 00066 //////////////////////////////////////////////////////////////////// 00067 void PhysxShapeDesc:: 00068 set_local_mat(const LMatrix4f &mat) { 00069 00070 nassertv(!mat.is_nan()); 00071 ptr()->localPose = PhysxManager::mat4_to_nxMat34(mat); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: PhysxShapeDesc::set_local_hpr 00076 // Access: Published 00077 // Description: 00078 //////////////////////////////////////////////////////////////////// 00079 void PhysxShapeDesc:: 00080 set_local_hpr(float h, float p, float r) { 00081 00082 LQuaternionf q; 00083 LMatrix3f rot; 00084 NxMat34 m; 00085 00086 q.set_hpr(LVector3f(h, p, r)); 00087 q.extract_to_matrix(rot); 00088 00089 ptr()->localPose.M = PhysxManager::mat3_to_nxMat33(rot); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: PhysxShapeDesc::set_skin_width 00094 // Access: Published 00095 // Description: Specifies by how much shapes can interpenetrate. 00096 // 00097 // Two shapes will interpenetrate by the sum of their 00098 // skin widths. This means that their graphical 00099 // representations should be adjusted so that they 00100 // just touch when the shapes are interpenetrating. 00101 // 00102 // The default skin width is the 'physx-skin-width' 00103 // parameter. 00104 // 00105 // A skin width sum of zero for two bodies is not 00106 // permitted because it will lead to an unstable 00107 // simulation. 00108 // 00109 // If your simulation jitters because resting bodies 00110 // occasionally lose contact, increasing the size of 00111 // your collision volumes and the skin width may 00112 // improve things. 00113 //////////////////////////////////////////////////////////////////// 00114 void PhysxShapeDesc:: 00115 set_skin_width(float skinWidth) { 00116 00117 nassertv(skinWidth >= 0.0f); 00118 ptr()->skinWidth = skinWidth; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: PhysxShapeDesc::set_shape_flag 00123 // Access: Published 00124 // Description: 00125 //////////////////////////////////////////////////////////////////// 00126 void PhysxShapeDesc:: 00127 set_shape_flag(const PhysxShapeFlag flag, bool value) { 00128 00129 if (value == true) { 00130 ptr()->shapeFlags |= flag; 00131 } 00132 else { 00133 ptr()->shapeFlags &= ~(flag); 00134 } 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: PhysxShapeDesc::set_mass 00139 // Access: Published 00140 // Description: Sets the mass of this individual shape when 00141 // computing mass inertial properties for a rigidbody. 00142 // When mass<=0.0 then density and volume determine 00143 // the mass. Note that this will only be used if the 00144 // body has a zero inertia tensor, or if you call 00145 // PhysxActor::update_mass_from_shapes explicitly. 00146 //////////////////////////////////////////////////////////////////// 00147 void PhysxShapeDesc:: 00148 set_mass(float mass) { 00149 00150 ptr()->mass = mass; 00151 } 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: PhysxShapeDesc::set_density 00155 // Access: Published 00156 // Description: Sets the density of this individual shape when 00157 // computing mass inertial properties for a rigidbody 00158 // (unless a valid mass >0.0 is provided). Note that 00159 // this will only be used if the body has a zero 00160 // inertia tensor, or if you call 00161 // PhysxActor::update_mass_from_shapes explicitly. 00162 //////////////////////////////////////////////////////////////////// 00163 void PhysxShapeDesc:: 00164 set_density(float density) { 00165 00166 nassertv(density > 0.0f); 00167 ptr()->density = density; 00168 } 00169 00170 //////////////////////////////////////////////////////////////////// 00171 // Function: PhysxShapeDesc::set_group 00172 // Access: Published 00173 // Description: 00174 //////////////////////////////////////////////////////////////////// 00175 void PhysxShapeDesc:: 00176 set_group(unsigned short group) { 00177 00178 ptr()->group = group; 00179 } 00180 00181 //////////////////////////////////////////////////////////////////// 00182 // Function: PhysxShapeDesc::get_name 00183 // Access: Published 00184 // Description: 00185 //////////////////////////////////////////////////////////////////// 00186 const char *PhysxShapeDesc:: 00187 get_name() const { 00188 00189 return ptr()->name; 00190 } 00191 00192 //////////////////////////////////////////////////////////////////// 00193 // Function: PhysxShapeDesc::get_local_pos 00194 // Access: Published 00195 // Description: 00196 //////////////////////////////////////////////////////////////////// 00197 LPoint3f PhysxShapeDesc:: 00198 get_local_pos() const { 00199 00200 return PhysxManager::nxVec3_to_point3(ptr()->localPose.t); 00201 } 00202 00203 //////////////////////////////////////////////////////////////////// 00204 // Function: PhysxShapeDesc::get_local_mat 00205 // Access: Published 00206 // Description: 00207 //////////////////////////////////////////////////////////////////// 00208 LMatrix4f PhysxShapeDesc:: 00209 get_local_mat() const { 00210 00211 return PhysxManager::nxMat34_to_mat4(ptr()->localPose); 00212 } 00213 00214 //////////////////////////////////////////////////////////////////// 00215 // Function: PhysxShapeDesc::get_skin_width 00216 // Access: Published 00217 // Description: 00218 //////////////////////////////////////////////////////////////////// 00219 float PhysxShapeDesc:: 00220 get_skin_width() const { 00221 00222 return ptr()->skinWidth; 00223 } 00224 00225 //////////////////////////////////////////////////////////////////// 00226 // Function: PhysxShapeDesc::get_shape_flag 00227 // Access: Published 00228 // Description: 00229 //////////////////////////////////////////////////////////////////// 00230 bool PhysxShapeDesc:: 00231 get_shape_flag(const PhysxShapeFlag flag) const { 00232 00233 return (ptr()->shapeFlags & flag) ? true : false; 00234 } 00235 00236 //////////////////////////////////////////////////////////////////// 00237 // Function: PhysxShapeDesc::get_mass 00238 // Access: Published 00239 // Description: 00240 //////////////////////////////////////////////////////////////////// 00241 float PhysxShapeDesc:: 00242 get_mass() const { 00243 00244 return ptr()->mass; 00245 } 00246 00247 //////////////////////////////////////////////////////////////////// 00248 // Function: PhysxShapeDesc::get_density 00249 // Access: Published 00250 // Description: 00251 //////////////////////////////////////////////////////////////////// 00252 float PhysxShapeDesc:: 00253 get_density() const { 00254 00255 return ptr()->density; 00256 } 00257 00258 //////////////////////////////////////////////////////////////////// 00259 // Function: PhysxShapeDesc::get_group 00260 // Access: Published 00261 // Description: 00262 //////////////////////////////////////////////////////////////////// 00263 unsigned short PhysxShapeDesc:: 00264 get_group() const { 00265 00266 return ptr()->group; 00267 } 00268 00269 //////////////////////////////////////////////////////////////////// 00270 // Function: PhysxShapeDesc::set_material 00271 // Access: Published 00272 // Description: 00273 //////////////////////////////////////////////////////////////////// 00274 void PhysxShapeDesc:: 00275 set_material(const PhysxMaterial &material) { 00276 00277 ptr()->materialIndex = material.ptr()->getMaterialIndex(); 00278 } 00279 00280 //////////////////////////////////////////////////////////////////// 00281 // Function: PhysxShapeDesc::set_material_index 00282 // Access: Published 00283 // Description: 00284 //////////////////////////////////////////////////////////////////// 00285 void PhysxShapeDesc:: 00286 set_material_index(unsigned short index) { 00287 00288 ptr()->materialIndex = index; 00289 } 00290 00291 //////////////////////////////////////////////////////////////////// 00292 // Function: PhysxShapeDesc::get_material_index 00293 // Access: Published 00294 // Description: 00295 //////////////////////////////////////////////////////////////////// 00296 unsigned short PhysxShapeDesc:: 00297 get_material_index() const { 00298 00299 return ptr()->materialIndex; 00300 } 00301