Panda3D
 All Classes Functions Variables Enumerations
physxMaterial.cxx
00001 // Filename: physxMaterial.cxx
00002 // Created by:  enn0x (21Sep09)
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 "physxMaterial.h"
00016 #include "physxMaterialDesc.h"
00017 #include "physxManager.h"
00018 
00019 TypeHandle PhysxMaterial::_type_handle;
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: PhysxMaterial::link
00023 //       Access: Public
00024 //  Description: 
00025 ////////////////////////////////////////////////////////////////////
00026 void PhysxMaterial::
00027 link(NxMaterial *materialPtr) {
00028 
00029   // Link self
00030   _ptr = materialPtr;
00031   _ptr->userData = this;
00032   _error_type = ET_ok;
00033 
00034   PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
00035   scene->_materials.add(this);
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: PhysxMaterial::unlink
00040 //       Access: Public
00041 //  Description: 
00042 ////////////////////////////////////////////////////////////////////
00043 void PhysxMaterial::
00044 unlink() {
00045 
00046   // Unlink self
00047   _ptr->userData = NULL;
00048   _error_type = ET_released;
00049 
00050   PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
00051   scene->_materials.remove(this);
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: PhysxMaterial::release
00056 //       Access: Published
00057 //  Description: 
00058 ////////////////////////////////////////////////////////////////////
00059 void PhysxMaterial::
00060 release() {
00061 
00062   nassertv(_error_type == ET_ok);
00063 
00064   unlink();
00065   _ptr->getScene().releaseMaterial(*_ptr);
00066   _ptr = NULL;
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: PhysxMaterial::get_scene
00071 //       Access: Published
00072 //  Description: Returns the scene that owns this material.
00073 ////////////////////////////////////////////////////////////////////
00074 PhysxScene *PhysxMaterial::
00075 get_scene() const {
00076 
00077   nassertr(_error_type == ET_ok, NULL);
00078   return (PhysxScene *)(_ptr->getScene().userData);
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: PhysxMaterial::get_material_index
00083 //       Access: Published
00084 //  Description: Returns the material index for this material.
00085 //
00086 //               Materials are associated with mesh faces and shapes
00087 //               using material index identifiers.
00088 //
00089 //               If you release a material while its material index
00090 //               is still in use by shapes or meshes, the material
00091 //               usage of these objects becomes undefined as the
00092 //               material index gets recycled.
00093 ////////////////////////////////////////////////////////////////////
00094 unsigned short PhysxMaterial::
00095 get_material_index() const {
00096 
00097   nassertr(_error_type == ET_ok, 0);
00098   return _ptr->getMaterialIndex();
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function : PhysxMaterial::load_from_desc
00103 //       Access : Published
00104 //  Description : Loads the entire state of the material from a 
00105 //                descriptor with a single call.
00106 ////////////////////////////////////////////////////////////////////
00107 void PhysxMaterial::
00108 load_from_desc(const PhysxMaterialDesc &materialDesc) {
00109 
00110   nassertv(_error_type == ET_ok);
00111   _ptr->loadFromDesc(materialDesc._desc);
00112 }
00113 
00114 ////////////////////////////////////////////////////////////////////
00115 //     Function : PhysxMaterial::save_to_desc
00116 //       Access : Published
00117 //  Description : Saves the state of the material object to a 
00118 //                descriptor.
00119 ////////////////////////////////////////////////////////////////////
00120 void PhysxMaterial::
00121 save_to_desc(PhysxMaterialDesc & materialDesc) const {
00122 
00123   nassertv(_error_type == ET_ok);
00124   _ptr->saveToDesc(materialDesc._desc);
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: PhysxMaterial::set_restitution
00129 //       Access: Published
00130 //  Description: Sets the coefficient of restitution. 
00131 //               A coefficient of 0 makes the object bounce as
00132 //               little as possible, higher values up to 1.0 result
00133 //               in more bounce.
00134 ////////////////////////////////////////////////////////////////////
00135 void PhysxMaterial::
00136 set_restitution(float restitution) {
00137 
00138   nassertv(_error_type == ET_ok);
00139   _ptr->setRestitution(restitution);
00140 }
00141 
00142 ////////////////////////////////////////////////////////////////////
00143 //     Function: PhysxMaterial::get_restitution
00144 //       Access: Published
00145 //  Description: Returns the coefficient of restitution.
00146 ////////////////////////////////////////////////////////////////////
00147 float PhysxMaterial::
00148 get_restitution() const {
00149 
00150   nassertr(_error_type == ET_ok, 0.0f);
00151   return _ptr->getRestitution();
00152 }
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: PhysxMaterial::set_static_friction
00156 //       Access: Published
00157 //  Description: Sets the coefficient of static friction. 
00158 //               The coefficient of static friction should be in the
00159 //               range [0, +inf].
00160 //               If the flag MF_anisotropic is set, then this value
00161 //               is used for the primary direction of anisotropy
00162 //               (U axis).
00163 ////////////////////////////////////////////////////////////////////
00164 void PhysxMaterial::
00165 set_static_friction(float coef) {
00166 
00167   nassertv(_error_type == ET_ok);
00168   _ptr->setStaticFriction(coef);
00169 }
00170 
00171 ////////////////////////////////////////////////////////////////////
00172 //     Function: PhysxMaterial::get_static_friction
00173 //       Access: Published
00174 //  Description: Returns the coefficient of static friction.
00175 ////////////////////////////////////////////////////////////////////
00176 float PhysxMaterial::
00177 get_static_friction() const {
00178 
00179   nassertr(_error_type == ET_ok, 0.0f);
00180   return _ptr->getStaticFriction();
00181 }
00182 
00183 ////////////////////////////////////////////////////////////////////
00184 //     Function: PhysxMaterial::set_dynamic_friction
00185 //       Access: Published
00186 //  Description: Sets the coefficient of dynamic friction. 
00187 //               The coefficient of dynamic friction should be in
00188 //               [0, +inf]. If set to greater than staticFriction,
00189 //               the effective value of staticFriction will be
00190 //               increased to match.
00191 //               If the flag MF_anisotropic is set, then this value
00192 //               is used for the primary direction of anisotropy
00193 //               (U axis).
00194 ////////////////////////////////////////////////////////////////////
00195 void PhysxMaterial::
00196 set_dynamic_friction(float coef) {
00197 
00198   nassertv(_error_type == ET_ok);
00199   _ptr->setDynamicFriction(coef);
00200 }
00201 
00202 ////////////////////////////////////////////////////////////////////
00203 //     Function: PhysxMaterial::get_dynamic_friction
00204 //       Access: Published
00205 //  Description: Returns the DynamicFriction value.
00206 ////////////////////////////////////////////////////////////////////
00207 float PhysxMaterial::
00208 get_dynamic_friction() const {
00209 
00210   nassertr(_error_type == ET_ok, 0.0f);
00211   return _ptr->getDynamicFriction();
00212 }
00213 
00214 ////////////////////////////////////////////////////////////////////
00215 //     Function: PhysxMaterial::set_static_friction_v
00216 //       Access: Published
00217 //  Description: Sets the static friction coefficient along the
00218 //               secondary (V) axis. This is used when anisotropic
00219 //               friction is being applied. I.e. the flag
00220 //               MF_anisotropic is set.
00221 ////////////////////////////////////////////////////////////////////
00222 void PhysxMaterial::
00223 set_static_friction_v(float coef) {
00224 
00225   nassertv(_error_type == ET_ok);
00226   _ptr->setStaticFrictionV(coef);
00227 }
00228 
00229 ////////////////////////////////////////////////////////////////////
00230 //     Function: PhysxMaterial::get_static_friction_v
00231 //       Access: Published
00232 //  Description: Returns the static friction coefficient for the
00233 //               V direction.
00234 ////////////////////////////////////////////////////////////////////
00235 float PhysxMaterial::
00236 get_static_friction_v() const {
00237 
00238   nassertr(_error_type == ET_ok, 0.0f);
00239   return _ptr->getStaticFrictionV();
00240 }
00241 
00242 ////////////////////////////////////////////////////////////////////
00243 //     Function: PhysxMaterial::set_dynamic_friction_v
00244 //       Access: Published
00245 //  Description: Sets the dynamic friction coefficient along the
00246 //               secondary (V) axis. This is used when anisotropic
00247 //               friction is being applied. I.e. the flag
00248 //               MF_anisotropic is set.
00249 ////////////////////////////////////////////////////////////////////
00250 void PhysxMaterial::
00251 set_dynamic_friction_v(float coef) {
00252 
00253   nassertv(_error_type == ET_ok);
00254   _ptr->setDynamicFrictionV(coef);
00255 }
00256 
00257 ////////////////////////////////////////////////////////////////////
00258 //     Function: PhysxMaterial::get_dynamic_friction_v
00259 //       Access: Published
00260 //  Description: Returns the dynamic friction coefficient for the
00261 //               V direction.
00262 ////////////////////////////////////////////////////////////////////
00263 float PhysxMaterial::
00264 get_dynamic_friction_v() const {
00265 
00266   nassertr(_error_type == ET_ok, 0.0f);
00267   return _ptr->getDynamicFrictionV();
00268 }
00269 
00270 ////////////////////////////////////////////////////////////////////
00271 //     Function: PhysxMaterial::set_flag
00272 //       Access: Published
00273 //  Description: Sets the value of a single flag.
00274 ////////////////////////////////////////////////////////////////////
00275 void PhysxMaterial::
00276 set_flag(PhysxMaterialFlag flag, bool value) {
00277 
00278   nassertv(_error_type == ET_ok);
00279   NxU32 flags = _ptr->getFlags();
00280 
00281   if (value == true) {
00282     flags |= flag;
00283   }
00284   else {
00285     flags &= ~(flag);
00286   }
00287 
00288   _ptr->setFlags(flags);
00289 }
00290 
00291 ////////////////////////////////////////////////////////////////////
00292 //     Function: PhysxMaterial::get_flag
00293 //       Access: Published
00294 //  Description: Returns the value of a single flag.
00295 ////////////////////////////////////////////////////////////////////
00296 bool PhysxMaterial::
00297 get_flag(PhysxMaterialFlag flag) const {
00298 
00299   nassertr(_error_type == ET_ok, false);
00300   return (_ptr->getFlags() & flag) ? true : false;
00301 }
00302 
00303 ////////////////////////////////////////////////////////////////////
00304 //     Function: PhysxMaterial::set_dir_of_anisotropy
00305 //       Access: Published
00306 //  Description: Sets the shape space direction (unit vector) of
00307 //               anisotropy. This is only used if the flag 
00308 //               MF_anisotropic is set.
00309 ////////////////////////////////////////////////////////////////////
00310 void PhysxMaterial::
00311 set_dir_of_anisotropy(const LVector3f dir) {
00312 
00313   nassertv(_error_type == ET_ok);
00314   _ptr->setDirOfAnisotropy(PhysxManager::vec3_to_nxVec3(dir));
00315 }
00316 
00317 ////////////////////////////////////////////////////////////////////
00318 //     Function: PhysxMaterial::get_dir_of_anisotropy
00319 //       Access: Published
00320 //  Description: Returns the direction of anisotropy value.
00321 ////////////////////////////////////////////////////////////////////
00322 LVector3f PhysxMaterial::
00323 get_dir_of_anisotropy() const {
00324 
00325   nassertr(_error_type == ET_ok, LVector3f::zero());
00326   return PhysxManager::nxVec3_to_vec3(_ptr->getDirOfAnisotropy());
00327 }
00328 
00329 ////////////////////////////////////////////////////////////////////
00330 //     Function: PhysxMaterial::set_friction_combine_mode
00331 //       Access: Published
00332 //  Description: Sets the friction combine mode.
00333 //               - CM_average : Average: (a + b)/2.
00334 //               - CM_min : Minimum: min(a,b).
00335 //               - CM_multiply : Multiply: a*b.
00336 //               - CM_max : Maximum: max(a,b).
00337 ////////////////////////////////////////////////////////////////////
00338 void PhysxMaterial::
00339 set_friction_combine_mode(PhysxCombineMode mode) {
00340 
00341   nassertv(_error_type == ET_ok);
00342   _ptr->setFrictionCombineMode((NxCombineMode)mode);
00343 }
00344 
00345 ////////////////////////////////////////////////////////////////////
00346 //     Function: PhysxMaterial::get_friction_combine_mode
00347 //       Access: Published
00348 //  Description: Returns the friction combine mode.
00349 ////////////////////////////////////////////////////////////////////
00350 PhysxEnums::PhysxCombineMode PhysxMaterial::
00351 get_friction_combine_mode() const {
00352 
00353   nassertr(_error_type == ET_ok, CM_average);
00354   return (PhysxCombineMode)_ptr->getFrictionCombineMode();
00355 }
00356 
00357 ////////////////////////////////////////////////////////////////////
00358 //     Function: PhysxMaterial::set_restitution_combine_mode
00359 //       Access: Published
00360 //  Description: Sets the restitution combine mode.
00361 //               - CM_average : Average: (a + b)/2.
00362 //               - CM_min : Minimum: min(a,b).
00363 //               - CM_multiply : Multiply: a*b.
00364 //               - CM_max : Maximum: max(a,b).
00365 ////////////////////////////////////////////////////////////////////
00366 void PhysxMaterial::
00367 set_restitution_combine_mode(PhysxCombineMode mode) {
00368 
00369   nassertv(_error_type == ET_ok);
00370   _ptr->setRestitutionCombineMode((NxCombineMode)mode);
00371 }
00372 
00373 ////////////////////////////////////////////////////////////////////
00374 //     Function: PhysxMaterial::get_restitution_combine_mode
00375 //       Access: Published
00376 //  Description: Returns the restitution combine mode.
00377 ////////////////////////////////////////////////////////////////////
00378 PhysxEnums::PhysxCombineMode PhysxMaterial::
00379 get_restitution_combine_mode() const {
00380 
00381   nassertr(_error_type == ET_ok, CM_average);
00382   return (PhysxCombineMode)_ptr->getRestitutionCombineMode();
00383 }
00384 
 All Classes Functions Variables Enumerations