00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00024
00025
00026
00027 void PhysxForceFieldShapeGroup::
00028 link(NxForceFieldShapeGroup *groupPtr) {
00029
00030
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
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
00052
00053
00054
00055 void PhysxForceFieldShapeGroup::
00056 unlink() {
00057
00058
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
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
00077
00078
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
00092
00093
00094
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
00105
00106
00107
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
00124
00125
00126
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
00137
00138
00139
00140
00141
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
00154
00155
00156
00157 const char *PhysxForceFieldShapeGroup::
00158 get_name() const {
00159
00160 nassertr(_error_type == ET_ok, "");
00161 return _ptr->getName();
00162 }
00163
00164
00165
00166
00167
00168
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
00180
00181
00182
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
00203
00204
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