Panda3D

physxPulleyJoint.cxx

00001 // Filename: physxPulleyJoint.cxx
00002 // Created by:  enn0x (02Oct09)
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 "physxPulleyJoint.h"
00016 #include "physxPulleyJointDesc.h"
00017 #include "physxMotorDesc.h"
00018 
00019 TypeHandle PhysxPulleyJoint::_type_handle;
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: PhysxPulleyJoint::link
00023 //       Access: Public
00024 //  Description: 
00025 ////////////////////////////////////////////////////////////////////
00026 void PhysxPulleyJoint::
00027 link(NxJoint *jointPtr) {
00028 
00029   _ptr = jointPtr->isPulleyJoint();
00030   _ptr->userData = this;
00031   _error_type = ET_ok;
00032 
00033   set_name(jointPtr->getName());
00034 
00035   PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
00036   scene->_joints.add(this);
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: PhysxPulleyJoint::unlink
00041 //       Access: Public
00042 //  Description: 
00043 ////////////////////////////////////////////////////////////////////
00044 void PhysxPulleyJoint::
00045 unlink() {
00046 
00047   _ptr->userData = NULL;
00048   _error_type = ET_released;
00049 
00050   PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
00051   scene->_joints.remove(this);
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function : PhysxPulleyJoint::save_to_desc
00056 //       Access : Published
00057 //  Description : Saves the state of the joint object to a 
00058 //                descriptor.
00059 ////////////////////////////////////////////////////////////////////
00060 void PhysxPulleyJoint::
00061 save_to_desc(PhysxPulleyJointDesc &jointDesc) const {
00062 
00063   nassertv(_error_type == ET_ok);
00064   _ptr->saveToDesc(jointDesc._desc);
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function : PhysxPulleyJoint::load_from_desc
00069 //       Access : Published
00070 //  Description : Loads the entire state of the joint from a 
00071 //                descriptor with a single call.
00072 ////////////////////////////////////////////////////////////////////
00073 void PhysxPulleyJoint::
00074 load_from_desc(const PhysxPulleyJointDesc &jointDesc) {
00075 
00076   nassertv(_error_type == ET_ok);
00077   _ptr->loadFromDesc(jointDesc._desc);
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: PhysxPulleyJoint::set_motor
00082 //       Access: Published
00083 //  Description: Sets motor parameters for the joint. 
00084 //
00085 //               For a positive velTarget, the motor pulls the first
00086 //               body towards its pulley, for a negative velTarget,
00087 //               the motor pulls the second body towards its pulley.
00088 //
00089 //               velTarget - the relative velocity the motor is
00090 //               trying to achieve. The motor will only be able to
00091 //               reach this velocity if the maxForce is sufficiently
00092 //               large. If the joint is moving faster than this
00093 //               velocity, the motor will actually try to brake. If
00094 //               you set this to infinity then the motor will keep
00095 //               speeding up, unless there is some sort of
00096 //               resistance on the attached bodies. 
00097 //
00098 //               maxForce - the maximum force the motor can exert.
00099 //               Zero disables the motor. Default is 0, should
00100 //               be >= 0. Setting this to a very large value if
00101 //               velTarget is also very large may not be a good
00102 //               idea. 
00103 //
00104 //               freeSpin - if this flag is set, and if the joint
00105 //               is moving faster than velTarget, then neither
00106 //               braking nor additional acceleration will result.
00107 //               default: false. 
00108 //
00109 //               This automatically enables the motor.
00110 ////////////////////////////////////////////////////////////////////
00111 void PhysxPulleyJoint::
00112 set_motor(const PhysxMotorDesc &motor) {
00113 
00114   nassertv(_error_type == ET_ok);
00115   _ptr->setMotor(motor._desc);
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: PhysxPulleyJoint::set_flag
00120 //       Access: Published
00121 //  Description: Sets or clear a single pulley joint flag.
00122 ////////////////////////////////////////////////////////////////////
00123 void PhysxPulleyJoint::
00124 set_flag(PhysxPulleyJointFlag flag, bool value) {
00125 
00126   nassertv(_error_type == ET_ok);
00127   NxU32 flags = _ptr->getFlags();
00128 
00129   if (value == true) {
00130     flags |= flag;
00131   }
00132   else {
00133     flags &= ~(flag);
00134   }
00135 
00136   _ptr->setFlags(flags);
00137 }
00138 
00139 ////////////////////////////////////////////////////////////////////
00140 //     Function: PhysxPulleyJoint::get_flag
00141 //       Access: Published
00142 //  Description: Retrieves the value of a single PulleyJointFlag.
00143 ////////////////////////////////////////////////////////////////////
00144 bool PhysxPulleyJoint::
00145 get_flag(PhysxPulleyJointFlag flag) const {
00146 
00147   nassertr(_error_type == ET_ok, false);
00148   return (_ptr->getFlags() & flag) ? true : false;
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: PhysxPulleyJoint::get_motor
00153 //       Access: Published
00154 //  Description: 
00155 ////////////////////////////////////////////////////////////////////
00156 PhysxMotorDesc PhysxPulleyJoint::
00157 get_motor() const {
00158 
00159   nassertr(_error_type == ET_ok, false);
00160 
00161   PhysxMotorDesc value;
00162   _ptr->getMotor(value._desc);  
00163   return value;
00164 }
00165 
 All Classes Functions Variables Enumerations