Panda3D

physxJointDesc.cxx

00001 // Filename: physxJointDesc.cxx
00002 // Created by:  enn0x (28Sep09)
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 "physxJointDesc.h"
00016 #include "physxManager.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //     Function: PhysxJointDesc::set_name
00020 //       Access: Published
00021 //  Description: Sets a possible debug name.
00022 ////////////////////////////////////////////////////////////////////
00023 void PhysxJointDesc::
00024 set_name(const char *name) {
00025 
00026   _name = name ? name : "";
00027   ptr()->name = _name.c_str();
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: PhysxJointDesc::set_max_force
00032 //       Access: Published
00033 //  Description: Set a possible debug name.
00034 ////////////////////////////////////////////////////////////////////
00035 void PhysxJointDesc::
00036 set_max_force(float force) {
00037 
00038   ptr()->maxForce = force;
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: PhysxJointDesc::set_max_torque
00043 //       Access: Published
00044 //  Description: Set the maximum angular force (torque) that the
00045 //               joint can withstand before breaking, must be
00046 //               positive.
00047 ////////////////////////////////////////////////////////////////////
00048 void PhysxJointDesc::
00049 set_max_torque(float torque) {
00050 
00051   ptr()->maxTorque = torque;
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: PhysxJointDesc::set_solver_extrapolation_factor
00056 //       Access: Published
00057 //  Description: Set the extrapolation factor for solving joint
00058 //               constraints.
00059 ////////////////////////////////////////////////////////////////////
00060 void PhysxJointDesc::
00061 set_solver_extrapolation_factor(float factor) {
00062 
00063   ptr()->solverExtrapolationFactor = factor;
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: PhysxJointDesc::set_actor
00068 //       Access: Published
00069 //  Description: Set the two actors connected by the joint.
00070 //               idx must be either 0 or 1.
00071 ////////////////////////////////////////////////////////////////////
00072 void PhysxJointDesc::
00073 set_actor(unsigned int idx, const PhysxActor &actor) {
00074 
00075   nassertv_always(idx < 2);
00076   ptr()->actor[idx] = actor.ptr();
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: PhysxJointDesc::set_local_normal
00081 //       Access: Published
00082 //  Description: Set the X axis of joint space, in actor[i]'s space,
00083 //               orthogonal to localAxis[i].
00084 //               idx must be either 0 or 1.
00085 ////////////////////////////////////////////////////////////////////
00086 void PhysxJointDesc::
00087 set_local_normal(unsigned int idx, const LVector3f &normal) {
00088 
00089   nassertv_always(idx < 2);
00090   ptr()->localNormal[idx] = PhysxManager::vec3_to_nxVec3(normal);
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: PhysxJointDesc::set_local_axis
00095 //       Access: Published
00096 //  Description: Set the Z axis of joint space, in actor[i]'s space.
00097 //               This is the primary axis of the joint. 
00098 //               idx must be either 0 or 1.
00099 ////////////////////////////////////////////////////////////////////
00100 void PhysxJointDesc::
00101 set_local_axis(unsigned int idx, const LVector3f &axis) {
00102 
00103   nassertv_always(idx < 2);
00104   ptr()->localAxis[idx] = PhysxManager::vec3_to_nxVec3(axis);
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: PhysxJointDesc::set_local_anchor
00109 //       Access: Published
00110 //  Description: Set the attachment point of joint in actor[i]'s
00111 //               space. idx must be either 0 or 1.
00112 ////////////////////////////////////////////////////////////////////
00113 void PhysxJointDesc::
00114 set_local_anchor(unsigned int idx, const LPoint3f &anchor) {
00115 
00116   nassertv_always(idx < 2);
00117   ptr()->localAnchor[idx] = PhysxManager::point3_to_nxVec3(anchor);
00118 }
00119 
00120 ////////////////////////////////////////////////////////////////////
00121 //     Function: PhysxJointDesc::set_joint_flag
00122 //       Access: Published
00123 //  Description: Set or clear a single JointFlag.
00124 ////////////////////////////////////////////////////////////////////
00125 void PhysxJointDesc::
00126 set_joint_flag(PhysxJointFlag flag, bool value) {
00127 
00128   if (value == true) {
00129     ptr()->jointFlags |= flag;
00130   }
00131   else {
00132     ptr()->jointFlags &= ~(flag);
00133   }
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: PhysxJointDesc::set_global_axis
00138 //       Access: Published
00139 //  Description: Set the local axis/normal using a world space axis.
00140 ////////////////////////////////////////////////////////////////////
00141 void PhysxJointDesc::
00142 set_global_axis(const LVector3f &axis) {
00143 
00144   ptr()->setGlobalAxis(PhysxManager::vec3_to_nxVec3(axis));
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: PhysxJointDesc::set_global_anchor
00149 //       Access: Published
00150 //  Description: Set the anchor using a world space point.
00151 ////////////////////////////////////////////////////////////////////
00152 void PhysxJointDesc::
00153 set_global_anchor(const LPoint3f &anchor) {
00154 
00155   ptr()->setGlobalAnchor(PhysxManager::point3_to_nxVec3(anchor));
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: PhysxJointDesc::get_name
00160 //       Access: Published
00161 //  Description: 
00162 ////////////////////////////////////////////////////////////////////
00163 const char *PhysxJointDesc::
00164 get_name() const {
00165 
00166   return ptr()->name;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: PhysxJointDesc::get_max_force
00171 //       Access: Published
00172 //  Description: 
00173 ////////////////////////////////////////////////////////////////////
00174 float PhysxJointDesc::
00175 get_max_force() const {
00176 
00177   return ptr()->maxForce;
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: PhysxJointDesc::get_max_torque
00182 //       Access: Published
00183 //  Description: 
00184 ////////////////////////////////////////////////////////////////////
00185 float PhysxJointDesc::
00186 get_max_torque() const {
00187 
00188   return ptr()->maxTorque;
00189 }
00190 
00191 ////////////////////////////////////////////////////////////////////
00192 //     Function: PhysxJointDesc::get_solver_extrapolation_factor
00193 //       Access: Published
00194 //  Description: 
00195 ////////////////////////////////////////////////////////////////////
00196 float PhysxJointDesc::
00197 get_solver_extrapolation_factor() const {
00198 
00199   return ptr()->solverExtrapolationFactor;
00200 }
00201 
00202 ////////////////////////////////////////////////////////////////////
00203 //     Function: PhysxJointDesc::get_local_normal
00204 //       Access: Published
00205 //  Description: 
00206 ////////////////////////////////////////////////////////////////////
00207 LVector3f PhysxJointDesc::
00208 get_local_normal(unsigned int idx) const {
00209 
00210   nassertr_always(idx < 2, LVector3f::zero());
00211   return PhysxManager::nxVec3_to_vec3(ptr()->localNormal[idx]);
00212 }
00213 
00214 ////////////////////////////////////////////////////////////////////
00215 //     Function: PhysxJointDesc::get_local_axis
00216 //       Access: Published
00217 //  Description: 
00218 ////////////////////////////////////////////////////////////////////
00219 LVector3f PhysxJointDesc::
00220 get_local_axis(unsigned int idx) const {
00221 
00222   nassertr_always(idx < 2, LVector3f::zero());
00223   return PhysxManager::nxVec3_to_vec3(ptr()->localAxis[idx]);
00224 }
00225 
00226 ////////////////////////////////////////////////////////////////////
00227 //     Function: PhysxJointDesc::get_local_anchor
00228 //       Access: Published
00229 //  Description: 
00230 ////////////////////////////////////////////////////////////////////
00231 LPoint3f PhysxJointDesc::
00232 get_local_anchor(unsigned int idx) const {
00233 
00234   nassertr_always(idx < 2, LPoint3f::zero());
00235   return PhysxManager::nxVec3_to_point3(ptr()->localAnchor[idx]);
00236 }
00237 
00238 ////////////////////////////////////////////////////////////////////
00239 //     Function: PhysxJointDesc::get_joint_flag
00240 //       Access: Published
00241 //  Description: 
00242 ////////////////////////////////////////////////////////////////////
00243 bool PhysxJointDesc::
00244 get_joint_flag(const PhysxJointFlag flag) const {
00245 
00246   return (ptr()->jointFlags & flag) ? true : false;
00247 }
00248 
00249 ////////////////////////////////////////////////////////////////////
00250 //     Function: PhysxJointDesc::get_actor
00251 //       Access: Published
00252 //  Description: 
00253 ////////////////////////////////////////////////////////////////////
00254 PhysxActor *PhysxJointDesc::
00255 get_actor(unsigned int idx) const {
00256 
00257   nassertr_always(idx < 2, NULL);
00258 
00259   NxActor *actorPtr = ptr()->actor[idx];
00260   if (actorPtr == NULL) {
00261     return NULL;
00262   }
00263   else {
00264     return (PhysxActor *)(actorPtr->userData);
00265   }
00266 }
00267 
 All Classes Functions Variables Enumerations