Panda3D
|
00001 // Filename: physxForceFieldShapeGroup.cxx 00002 // Created by: enn0x (11Nov09) 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 "physxForceFieldShapeGroup.h" 00016 #include "physxForceFieldShapeGroupDesc.h" 00017 #include "physxForceField.h" 00018 #include "physxForceFieldShape.h" 00019 00020 TypeHandle PhysxForceFieldShapeGroup::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: PhysxForceFieldShapeGroup::link 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 void PhysxForceFieldShapeGroup:: 00028 link(NxForceFieldShapeGroup *groupPtr) { 00029 00030 // Link self 00031 _ptr = groupPtr; 00032 _ptr->userData = this; 00033 _error_type = ET_ok; 00034 00035 set_name(groupPtr->getName()); 00036 00037 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; 00038 scene->_ffgroups.add(this); 00039 00040 // Link shapes 00041 NxU32 nShapes = _ptr->getNbShapes(); 00042 _ptr->resetShapesIterator(); 00043 for (NxU32 i=0; i < nShapes; i++) { 00044 NxForceFieldShape *shapePtr = _ptr->getNextShape(); 00045 PhysxForceFieldShape *shape = PhysxForceFieldShape::factory(shapePtr->getType()); 00046 shape->link(shapePtr); 00047 } 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: PhysxForceFieldShapeGroup::unlink 00052 // Access: Public 00053 // Description: 00054 //////////////////////////////////////////////////////////////////// 00055 void PhysxForceFieldShapeGroup:: 00056 unlink() { 00057 00058 // Unlink shapes 00059 NxU32 nShapes = _ptr->getNbShapes(); 00060 _ptr->resetShapesIterator(); 00061 for (NxU32 i=0; i < nShapes; i++) { 00062 NxForceFieldShape *shapePtr = _ptr->getNextShape(); 00063 PhysxForceFieldShape *shape = (PhysxForceFieldShape *)shapePtr->userData; 00064 shape->unlink(); 00065 } 00066 00067 // Unlink self 00068 _ptr->userData = NULL; 00069 _error_type = ET_released; 00070 00071 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; 00072 scene->_ffgroups.remove(this); 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: PhysxForceFieldShapeGroup::release 00077 // Access: Published 00078 // Description: Releases the force field shape. 00079 //////////////////////////////////////////////////////////////////// 00080 void PhysxForceFieldShapeGroup:: 00081 release() { 00082 00083 nassertv(_error_type == ET_ok); 00084 00085 unlink(); 00086 _ptr->getScene().releaseForceFieldShapeGroup(*_ptr); 00087 _ptr = NULL; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: PhysxForceFieldShapeGroup::get_scene 00092 // Access: Published 00093 // Description: Returns the scene that owns this force field shape 00094 // group. 00095 //////////////////////////////////////////////////////////////////// 00096 PhysxScene *PhysxForceFieldShapeGroup:: 00097 get_scene() const { 00098 00099 nassertr(_error_type == ET_ok, NULL); 00100 return (PhysxScene *)(_ptr->getScene().userData); 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: PhysxForceFieldShapeGroup::get_force_field 00105 // Access: Published 00106 // Description: Returns the force field of this group if this is 00107 // an include group. If not NULL will be returned. 00108 //////////////////////////////////////////////////////////////////// 00109 PhysxForceField *PhysxForceFieldShapeGroup:: 00110 get_force_field() const { 00111 00112 nassertr(_error_type == ET_ok, NULL); 00113 00114 if (_ptr->getForceField() == NULL) { 00115 return NULL; 00116 } 00117 else { 00118 return (PhysxForceField *)(_ptr->getForceField()->userData); 00119 } 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function : PhysxForceFieldShapeGroup::save_to_desc 00124 // Access : Published 00125 // Description : Saves the state of the force field shape group 00126 // object to a descriptor. 00127 //////////////////////////////////////////////////////////////////// 00128 void PhysxForceFieldShapeGroup:: 00129 save_to_desc(PhysxForceFieldShapeGroupDesc &groupDesc) const { 00130 00131 nassertv(_error_type == ET_ok); 00132 _ptr->saveToDesc(groupDesc._desc); 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: PhysxForceFieldShapeGroup::set_name 00137 // Access: Published 00138 // Description: Sets a name string for the object that can be 00139 // retrieved with get_name(). 00140 // This is for debugging and is not used by the 00141 // engine. 00142 //////////////////////////////////////////////////////////////////// 00143 void PhysxForceFieldShapeGroup:: 00144 set_name(const char *name) { 00145 00146 nassertv(_error_type == ET_ok); 00147 00148 _name = name ? name : ""; 00149 _ptr->setName(_name.c_str()); 00150 } 00151 00152 //////////////////////////////////////////////////////////////////// 00153 // Function: PhysxForceFieldShapeGroup::get_name 00154 // Access: Published 00155 // Description: Returns the name string. 00156 //////////////////////////////////////////////////////////////////// 00157 const char *PhysxForceFieldShapeGroup:: 00158 get_name() const { 00159 00160 nassertr(_error_type == ET_ok, ""); 00161 return _ptr->getName(); 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: PhysxForceFieldShapeGroup::get_num_shapes 00166 // Access: Published 00167 // Description: Returns the number of shapes assigned to the 00168 // force field shape group. 00169 //////////////////////////////////////////////////////////////////// 00170 unsigned int PhysxForceFieldShapeGroup:: 00171 get_num_shapes() const { 00172 00173 nassertr(_error_type == ET_ok, -1); 00174 00175 return _ptr->getNbShapes(); 00176 } 00177 00178 //////////////////////////////////////////////////////////////////// 00179 // Function: PhysxForceFieldShapeGroup::create_shape 00180 // Access: Published 00181 // Description: Creates a force field shape and adds it to the 00182 // group. 00183 //////////////////////////////////////////////////////////////////// 00184 PhysxForceFieldShape *PhysxForceFieldShapeGroup:: 00185 create_shape(PhysxForceFieldShapeDesc &desc) { 00186 00187 nassertr(_error_type == ET_ok, NULL); 00188 nassertr(desc.is_valid(),NULL); 00189 00190 PhysxForceFieldShape *shape = PhysxForceFieldShape::factory(desc.ptr()->getType()); 00191 nassertr(shape, NULL); 00192 00193 NxForceFieldShape *shapePtr = _ptr->createShape(*desc.ptr()); 00194 nassertr(shapePtr, NULL); 00195 00196 shape->link(shapePtr); 00197 00198 return shape; 00199 } 00200 00201 //////////////////////////////////////////////////////////////////// 00202 // Function: PhysxForceFieldShapeGroup::get_shape 00203 // Access: Published 00204 // Description: Returns the i-th shape in the force field group. 00205 //////////////////////////////////////////////////////////////////// 00206 PhysxForceFieldShape *PhysxForceFieldShapeGroup:: 00207 get_shape(unsigned int idx) const { 00208 00209 nassertr(_error_type == ET_ok, NULL); 00210 nassertr_always(idx < _ptr->getNbShapes(), NULL); 00211 00212 NxForceFieldShape *shapePtr; 00213 NxU32 nShapes = _ptr->getNbShapes(); 00214 00215 _ptr->resetShapesIterator(); 00216 for (NxU32 i=0; i <= idx; i++) { 00217 shapePtr = _ptr->getNextShape(); 00218 } 00219 00220 return (PhysxForceFieldShape *)(shapePtr->userData); 00221 } 00222