Panda3D

bulletConeTwistConstraint.cxx

00001 // Filename: bulletConeTwistConstraint.cxx
00002 // Created by:  enn0x (01Mar10)
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 "bulletConeTwistConstraint.h"
00016 #include "bulletRigidBodyNode.h"
00017 
00018 #include "deg_2_rad.h"
00019 
00020 TypeHandle BulletConeTwistConstraint::_type_handle;
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: BulletConeTwistConstraint::Constructor
00024 //       Access: Published
00025 //  Description:
00026 ////////////////////////////////////////////////////////////////////
00027 BulletConeTwistConstraint::
00028 BulletConeTwistConstraint(const BulletRigidBodyNode *node_a, 
00029                           CPT(TransformState) frame_a) {
00030 
00031   btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
00032   btTransform trans_a = TransformState_to_btTrans(frame_a);
00033 
00034   _constraint = new btConeTwistConstraint(*ptr_a, trans_a);
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: BulletConeTwistConstraint::Constructor
00039 //       Access: Published
00040 //  Description:
00041 ////////////////////////////////////////////////////////////////////
00042 BulletConeTwistConstraint::
00043 BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
00044                           const BulletRigidBodyNode *node_b,
00045                           CPT(TransformState) frame_a,
00046                           CPT(TransformState) frame_b) {
00047 
00048   btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
00049   btTransform trans_a = TransformState_to_btTrans(frame_a);
00050 
00051   btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
00052   btTransform trans_b = TransformState_to_btTrans(frame_b);
00053 
00054   _constraint = new btConeTwistConstraint(*ptr_a, *ptr_b, trans_a, trans_b);
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: BulletConeTwistConstraint::ptr
00059 //       Access: Public
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 btTypedConstraint *BulletConeTwistConstraint::
00063 ptr() const {
00064 
00065   return _constraint;
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: BulletConeTwistConstraint::set_limit
00070 //       Access: Published
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 void BulletConeTwistConstraint::
00074 set_limit(int index, PN_stdfloat value) {
00075  
00076   value = deg_2_rad(value);
00077 
00078   _constraint->setLimit(index, value);
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: BulletConeTwistConstraint::set_limit
00083 //       Access: Published
00084 //  Description:
00085 ////////////////////////////////////////////////////////////////////
00086 void BulletConeTwistConstraint::
00087 set_limit(PN_stdfloat swing1, PN_stdfloat swing2, PN_stdfloat twist, PN_stdfloat softness, PN_stdfloat bias, PN_stdfloat relaxation) {
00088 
00089   swing1 = deg_2_rad(swing1);
00090   swing2 = deg_2_rad(swing2);
00091   twist  = deg_2_rad(twist);
00092 
00093   _constraint->setLimit(swing1, swing2, twist, softness, bias, relaxation);
00094 }
00095 
00096 ////////////////////////////////////////////////////////////////////
00097 //     Function: BulletConeTwistConstraint::set_damping
00098 //       Access: Published
00099 //  Description:
00100 ////////////////////////////////////////////////////////////////////
00101 void BulletConeTwistConstraint::
00102 set_damping(PN_stdfloat damping) {
00103  
00104   _constraint->setDamping(damping);
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: BulletConeTwistConstraint::get_fix_threshold
00109 //       Access: Published
00110 //  Description:
00111 ////////////////////////////////////////////////////////////////////
00112 PN_stdfloat BulletConeTwistConstraint::
00113 get_fix_threshold() const {
00114  
00115   return _constraint->getFixThresh();
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: BulletConeTwistConstraint::set_fix_threshold
00120 //       Access: Published
00121 //  Description:
00122 ////////////////////////////////////////////////////////////////////
00123 void BulletConeTwistConstraint::
00124 set_fix_threshold(PN_stdfloat threshold) {
00125  
00126   _constraint->setFixThresh(threshold);
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: BulletConeTwistConstraint::enable_motor
00131 //       Access: Published
00132 //  Description:
00133 ////////////////////////////////////////////////////////////////////
00134 void BulletConeTwistConstraint::
00135 enable_motor(bool enable) {
00136  
00137   _constraint->enableMotor(enable);
00138 }
00139 
00140 ////////////////////////////////////////////////////////////////////
00141 //     Function: BulletConeTwistConstraint::set_max_motor_impulse
00142 //       Access: Published
00143 //  Description:
00144 ////////////////////////////////////////////////////////////////////
00145 void BulletConeTwistConstraint::
00146 set_max_motor_impulse(PN_stdfloat max_impulse) {
00147  
00148   _constraint->setMaxMotorImpulse(max_impulse);
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: BulletConeTwistConstraint::set_max_motor_impulse_normalized
00153 //       Access: Published
00154 //  Description:
00155 ////////////////////////////////////////////////////////////////////
00156 void BulletConeTwistConstraint::
00157 set_max_motor_impulse_normalized(PN_stdfloat max_impulse) {
00158  
00159   _constraint->setMaxMotorImpulseNormalized(max_impulse);
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: BulletConeTwistConstraint::set_motor_target
00164 //       Access: Published
00165 //  Description:
00166 ////////////////////////////////////////////////////////////////////
00167 void BulletConeTwistConstraint::
00168 set_motor_target(const LQuaternion &quat) {
00169  
00170   _constraint->setMotorTarget(LQuaternion_to_btQuat(quat));
00171 }
00172 
00173 ////////////////////////////////////////////////////////////////////
00174 //     Function: BulletConeTwistConstraint::set_motor_target_in_constraint_space
00175 //       Access: Published
00176 //  Description:
00177 ////////////////////////////////////////////////////////////////////
00178 void BulletConeTwistConstraint::
00179 set_motor_target_in_constraint_space(const LQuaternion &quat) {
00180  
00181   _constraint->setMotorTargetInConstraintSpace(LQuaternion_to_btQuat(quat));
00182 }
00183 
 All Classes Functions Variables Enumerations