00001 // Filename: physxForceFieldShape.cxx 00002 // Created by: enn0x (15Nov09) 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 "physxForceFieldShape.h" 00016 #include "physxForceFieldShapeGroup.h" 00017 #include "physxForceField.h" 00018 #include "physxBoxForceFieldShape.h" 00019 #include "physxCapsuleForceFieldShape.h" 00020 #include "physxSphereForceFieldShape.h" 00021 #include "physxConvexForceFieldShape.h" 00022 #include "physxManager.h" 00023 00024 TypeHandle PhysxForceFieldShape::_type_handle; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: PhysxForceFieldShape::release 00028 // Access: Published 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 void PhysxForceFieldShape:: 00032 release() { 00033 00034 nassertv(_error_type == ET_ok); 00035 00036 unlink(); 00037 ptr()->getShapeGroup().releaseShape(*ptr()); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: PhysxForceFieldShape::factory 00042 // Access: Public 00043 // Description: 00044 //////////////////////////////////////////////////////////////////// 00045 PhysxForceFieldShape *PhysxForceFieldShape:: 00046 factory(NxShapeType shapeType) { 00047 00048 switch (shapeType) { 00049 00050 case NX_SHAPE_SPHERE: 00051 return new PhysxSphereForceFieldShape(); 00052 00053 case NX_SHAPE_BOX: 00054 return new PhysxBoxForceFieldShape(); 00055 00056 case NX_SHAPE_CAPSULE: 00057 return new PhysxCapsuleForceFieldShape(); 00058 00059 case NX_SHAPE_CONVEX: 00060 return new PhysxConvexForceFieldShape(); 00061 } 00062 00063 physx_cat.error() << "Unknown shape type.\n"; 00064 return NULL; 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: PhysxForceFieldShape::get_force_field 00069 // Access: Published 00070 // Description: Returns the owning force field if this is a shape 00071 // of an include group, else NULL will be returned. 00072 //////////////////////////////////////////////////////////////////// 00073 PhysxForceField *PhysxForceFieldShape:: 00074 get_force_field() const { 00075 00076 nassertr(_error_type == ET_ok, NULL); 00077 00078 NxForceField *fieldPtr = ptr()->getForceField(); 00079 if (fieldPtr == NULL) { 00080 return NULL; 00081 } 00082 return (PhysxForceField *)(fieldPtr->userData); 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: PhysxForceFieldShape::get_shape_group 00087 // Access: Published 00088 // Description: Returns the owning force field shape group. 00089 //////////////////////////////////////////////////////////////////// 00090 PhysxForceFieldShapeGroup *PhysxForceFieldShape:: 00091 get_shape_group() const { 00092 00093 nassertr(_error_type == ET_ok, NULL); 00094 return (PhysxForceFieldShapeGroup *)(ptr()->getShapeGroup().userData); 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: PhysxForceFieldShape::set_name 00099 // Access: Published 00100 // Description: Sets a name string for this object. The name can 00101 // be retrieved again with get_name(). 00102 //////////////////////////////////////////////////////////////////// 00103 void PhysxForceFieldShape:: 00104 set_name(const char *name) { 00105 00106 nassertv(_error_type == ET_ok); 00107 00108 _name = name ? name : ""; 00109 ptr()->setName(_name.c_str()); 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: PhysxForceFieldShape::get_name 00114 // Access: Published 00115 // Description: Returns the name string. 00116 //////////////////////////////////////////////////////////////////// 00117 const char *PhysxForceFieldShape:: 00118 get_name() const { 00119 00120 nassertr(_error_type == ET_ok, ""); 00121 return ptr()->getName(); 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: PhysxForceFieldShape::set_mat 00126 // Access: Published 00127 // Description: Sets the force field shape's transform. 00128 //////////////////////////////////////////////////////////////////// 00129 void PhysxForceFieldShape:: 00130 set_mat(const LMatrix4f &mat) { 00131 00132 nassertv(_error_type == ET_ok); 00133 00134 ptr()->setPose(PhysxManager::mat4_to_nxMat34(mat)); 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: PhysxForceFieldShape::get_mat 00139 // Access: Published 00140 // Description: Returns the force field shape's transform. 00141 //////////////////////////////////////////////////////////////////// 00142 LMatrix4f PhysxForceFieldShape:: 00143 get_mat() const { 00144 00145 nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); 00146 00147 return PhysxManager::nxMat34_to_mat4(ptr()->getPose()); 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: PhysxForceFieldShape::set_pos 00152 // Access: Published 00153 // Description: Sets the force field shape's translation. 00154 //////////////////////////////////////////////////////////////////// 00155 void PhysxForceFieldShape:: 00156 set_pos(const LPoint3f &pos) { 00157 00158 nassertv(_error_type == ET_ok); 00159 00160 NxMat34 pose = ptr()->getPose(); 00161 pose.t = PhysxManager::point3_to_nxVec3(pos); 00162 ptr()->setPose(pose); 00163 } 00164 00165 //////////////////////////////////////////////////////////////////// 00166 // Function: PhysxForceFieldShape::get_pos 00167 // Access: Published 00168 // Description: Returns the force field shape's translation. 00169 //////////////////////////////////////////////////////////////////// 00170 LPoint3f PhysxForceFieldShape:: 00171 get_pos() const { 00172 00173 nassertr(_error_type == ET_ok, LPoint3f::zero()); 00174 00175 return PhysxManager::nxVec3_to_point3(ptr()->getPose().t); 00176 } 00177