Panda3D

bulletGenericConstraint.cxx

00001 // Filename: bulletGenericConstraint.cxx
00002 // Created by:  enn0x (02Mar10)
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 "bulletGenericConstraint.h"
00016 #include "bulletRigidBodyNode.h"
00017 
00018 TypeHandle BulletGenericConstraint::_type_handle;
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: BulletGenericConstraint::Constructor
00022 //       Access: Published
00023 //  Description:
00024 ////////////////////////////////////////////////////////////////////
00025 BulletGenericConstraint::
00026 BulletGenericConstraint(const BulletRigidBodyNode *node_a, 
00027                         CPT(TransformState) frame_a,
00028                         bool use_frame_a) {
00029 
00030   btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
00031   btTransform trans_a = TransformState_to_btTrans(frame_a);
00032 
00033   _constraint = new btGeneric6DofConstraint(*ptr_a, trans_a, use_frame_a);
00034 }
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: BulletGenericConstraint::Constructor
00038 //       Access: Published
00039 //  Description:
00040 ////////////////////////////////////////////////////////////////////
00041 BulletGenericConstraint::
00042 BulletGenericConstraint(const BulletRigidBodyNode *node_a,
00043                         const BulletRigidBodyNode *node_b,
00044                         CPT(TransformState) frame_a,
00045                         CPT(TransformState) frame_b,
00046                         bool use_frame_a) {
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 btGeneric6DofConstraint(*ptr_a, *ptr_b, trans_a, trans_b, use_frame_a);
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: BulletGenericConstraint::ptr
00059 //       Access: Public
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 btTypedConstraint *BulletGenericConstraint::
00063 ptr() const {
00064 
00065   return _constraint;
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: BulletGenericConstraint::get_axis
00070 //       Access: Published
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 LVector3 BulletGenericConstraint::
00074 get_axis(int axis) const {
00075 
00076   nassertr(axis >= 0, LVector3::zero());
00077   nassertr(axis <= 3, LVector3::zero());
00078 
00079   _constraint->buildJacobian();
00080   return btVector3_to_LVector3(_constraint->getAxis(axis));
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: BulletGenericConstraint::get_pivot
00085 //       Access: Published
00086 //  Description:
00087 ////////////////////////////////////////////////////////////////////
00088 PN_stdfloat BulletGenericConstraint::
00089 get_pivot(int axis) const {
00090 
00091   nassertr(axis >= 0, 0.0f);
00092   nassertr(axis <= 3, 0.0f);
00093 
00094   _constraint->buildJacobian();
00095   return _constraint->getRelativePivotPosition(axis);
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: BulletGenericConstraint::get_angle
00100 //       Access: Published
00101 //  Description:
00102 ////////////////////////////////////////////////////////////////////
00103 PN_stdfloat BulletGenericConstraint::
00104 get_angle(int axis) const {
00105 
00106   nassertr(axis >= 0, 0.0f);
00107   nassertr(axis <= 3, 0.0f);
00108 
00109   _constraint->buildJacobian();
00110   return _constraint->getAngle(axis);
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //     Function: BulletGenericConstraint::set_linear_limit
00115 //       Access: Published
00116 //  Description:
00117 ////////////////////////////////////////////////////////////////////
00118 void BulletGenericConstraint::
00119 set_linear_limit(int axis, PN_stdfloat low, PN_stdfloat high) {
00120 
00121   nassertv(axis >= 0);
00122   nassertv(axis <= 3);
00123 
00124   _constraint->buildJacobian();
00125   _constraint->setLimit(axis, low, high);
00126 }
00127 
00128 ////////////////////////////////////////////////////////////////////
00129 //     Function: BulletGenericConstraint::set_angular_limit
00130 //       Access: Published
00131 //  Description:
00132 ////////////////////////////////////////////////////////////////////
00133 void BulletGenericConstraint::
00134 set_angular_limit(int axis, PN_stdfloat low, PN_stdfloat high) {
00135 
00136   nassertv(axis >= 0);
00137   nassertv(axis <= 3);
00138 
00139   low  = deg_2_rad(low);
00140   high = deg_2_rad(high);
00141 
00142   _constraint->buildJacobian();
00143   _constraint->setLimit(axis + 3, low, high);
00144 }
00145 
 All Classes Functions Variables Enumerations