00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00024
00025
00026
00027 void PhysxForceField::
00028 link(NxForceField *fieldPtr) {
00029
00030
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
00041 PhysxForceFieldShapeGroup *group = new PhysxForceFieldShapeGroup();
00042 group->link(&(_ptr->getIncludeShapeGroup()));
00043 }
00044
00045
00046
00047
00048
00049
00050 void PhysxForceField::
00051 unlink() {
00052
00053
00054 PhysxForceFieldShapeGroup *group = (PhysxForceFieldShapeGroup *)(_ptr->getIncludeShapeGroup().userData);
00055 group->unlink();
00056
00057
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
00067
00068
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
00082
00083
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
00096
00097
00098
00099 const char *PhysxForceField::
00100 get_name() const {
00101
00102 nassertr(_error_type == ET_ok, "");
00103 return _ptr->getName();
00104 }
00105
00106
00107
00108
00109
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
00120
00121
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
00132
00133
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
00144
00145
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