Panda3D
|
00001 // Filename: physxForceField.cxx 00002 // Created by: enn0x (06Nov09) 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 "physxForceField.h" 00016 #include "physxForceFieldDesc.h" 00017 #include "physxForceFieldShapeGroup.h" 00018 #include "physxScene.h" 00019 00020 TypeHandle PhysxForceField::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: PhysxForceField::link 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 void PhysxForceField:: 00028 link(NxForceField *fieldPtr) { 00029 00030 // Link self 00031 _ptr = fieldPtr; 00032 _ptr->userData = this; 00033 _error_type = ET_ok; 00034 00035 set_name(fieldPtr->getName()); 00036 00037 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; 00038 scene->_forcefields.add(this); 00039 00040 // Link include shape group 00041 PhysxForceFieldShapeGroup *group = new PhysxForceFieldShapeGroup(); 00042 group->link(&(_ptr->getIncludeShapeGroup())); 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: PhysxForceField::unlink 00047 // Access: Public 00048 // Description: 00049 //////////////////////////////////////////////////////////////////// 00050 void PhysxForceField:: 00051 unlink() { 00052 00053 // Unlink inlcude shape group 00054 PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)(_ptr->getIncludeShapeGroup().userData); 00055 group->unlink(); 00056 00057 // Unlink self 00058 _ptr->userData = NULL; 00059 _error_type = ET_released; 00060 00061 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; 00062 scene->_forcefields.remove(this); 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: PhysxForceField::release 00067 // Access: Published 00068 // Description: 00069 //////////////////////////////////////////////////////////////////// 00070 void PhysxForceField:: 00071 release() { 00072 00073 nassertv(_error_type == ET_ok); 00074 00075 unlink(); 00076 _ptr->getScene().releaseForceField(*_ptr); 00077 _ptr = NULL; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: PhysxForceField::set_name 00082 // Access: Published 00083 // Description: 00084 //////////////////////////////////////////////////////////////////// 00085 void PhysxForceField:: 00086 set_name(const char *name) { 00087 00088 nassertv(_error_type == ET_ok); 00089 00090 _name = name ? name : ""; 00091 _ptr->setName(_name.c_str()); 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: PhysxForceField::get_name 00096 // Access: Published 00097 // Description: 00098 //////////////////////////////////////////////////////////////////// 00099 const char *PhysxForceField:: 00100 get_name() const { 00101 00102 nassertr(_error_type == ET_ok, ""); 00103 return _ptr->getName(); 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: PhysxForceField::get_scene 00108 // Access: Published 00109 // Description: 00110 //////////////////////////////////////////////////////////////////// 00111 PhysxScene *PhysxForceField:: 00112 get_scene() const { 00113 00114 nassertr(_error_type == ET_ok, NULL); 00115 return (PhysxScene *)(_ptr->getScene().userData); 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: PhysxForceField::get_include_shape_group 00120 // Access: Published 00121 // Description: 00122 //////////////////////////////////////////////////////////////////// 00123 PhysxForceFieldShapeGroup *PhysxForceField:: 00124 get_include_shape_group() const { 00125 00126 nassertr(_error_type == ET_ok, NULL); 00127 return (PhysxForceFieldShapeGroup *)(_ptr->getIncludeShapeGroup().userData); 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function: PhysxForceField::get_num_shape_groups 00132 // Access: Published 00133 // Description: 00134 //////////////////////////////////////////////////////////////////// 00135 unsigned int PhysxForceField:: 00136 get_num_shape_groups() const { 00137 00138 nassertr(_error_type == ET_ok, NULL); 00139 return _ptr->getNbShapeGroups(); 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: PhysxForceField::get_shape_group 00144 // Access: Published 00145 // Description: 00146 //////////////////////////////////////////////////////////////////// 00147 PhysxForceFieldShapeGroup *PhysxForceField:: 00148 get_shape_group(unsigned int idx) const { 00149 00150 nassertr(_error_type == ET_ok, NULL); 00151 nassertr_always(idx < _ptr->getNbShapeGroups(), NULL); 00152 00153 NxForceFieldShapeGroup *groupPtr; 00154 NxU32 nGroups = _ptr->getNbShapeGroups(); 00155 00156 _ptr->resetShapeGroupsIterator(); 00157 for (NxU32 i=0; i <= idx; i++) { 00158 groupPtr = _ptr->getNextShapeGroup(); 00159 } 00160 00161 return (PhysxForceFieldShapeGroup *)(groupPtr->userData); 00162 } 00163