Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

hingejoint.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002    this file is part of rcssserver3D
00003    Fri May 9 2003
00004    Copyright (C) 2003 Koblenz University
00005    $Id: hingejoint.cpp,v 1.6 2005/12/31 13:53:56 jboedeck Exp $
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; version 2 of the License.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 #include "hingejoint.h"
00021 #include <zeitgeist/logserver/logserver.h>
00022 
00023 using namespace oxygen;
00024 using namespace boost;
00025 using namespace salt;
00026 
00027 HingeJoint::HingeJoint() : Joint()
00028 {
00029 }
00030 
00031 HingeJoint::~HingeJoint()
00032 {
00033 }
00034 
00035 void HingeJoint::OnLink()
00036 {
00037     dWorldID world = GetWorldID();
00038     if (world == 0)
00039         {
00040             return;
00041         }
00042 
00043     mODEJoint = dJointCreateHinge(world, 0);
00044 }
00045 
00046 void HingeJoint::SetAnchor(const Vector3f& anchor)
00047 {
00048     // calculate anchor position in world coordinates
00049     Vector3f gAnchor(GetWorldTransform() * anchor);
00050     dJointSetHingeAnchor (mODEJoint, gAnchor[0], gAnchor[1], gAnchor[2]);
00051 }
00052 
00053 Vector3f HingeJoint::GetAnchor(EBodyIndex idx)
00054 {
00055     Vector3f pos(0,0,0);
00056 
00057     switch (idx)
00058         {
00059         case BI_FIRST:
00060             {
00061                 dReal anchor[3];
00062                 dJointGetHingeAnchor (mODEJoint, anchor);
00063                 pos = Vector3f(anchor[0],anchor[1],anchor[2]);
00064             }
00065 
00066         case BI_SECOND:
00067             {
00068                 dReal anchor[3];
00069                 dJointGetHingeAnchor2(mODEJoint, anchor);
00070                 pos = Vector3f(anchor[0],anchor[1],anchor[2]);
00071             }
00072 
00073         default:
00074             break;
00075         }
00076 
00077     return GetLocalPos(pos);
00078 }
00079 
00080 void HingeJoint::SetAxis(EAxisIndex idx)
00081 {
00082     switch(idx)
00083     {
00084     case AI_FIRST:
00085     {
00086         // calculate hinge axis (pos. x, relative to world transform)
00087         Vector3f right(GetWorldTransform().Rotate(Vector3f(1,0,0)));
00088         dJointSetHingeAxis(mODEJoint, right[0], right[1], right[2]);
00089         break;
00090     }
00091     case AI_SECOND:
00092     {
00093        // calculate hinge axis (pos. y, relative to world transform)
00094         Vector3f forward(GetWorldTransform().Rotate(Vector3f(0,1,0)));
00095         dJointSetHingeAxis(mODEJoint, forward[0], forward[1], forward[2]); 
00096         break;
00097     }
00098     case AI_THIRD:
00099     {
00100         // calculate hinge axis (pos. z, relative to world transform)
00101         Vector3f up(GetWorldTransform().Rotate(Vector3f(0,0,1)));
00102         dJointSetHingeAxis(mODEJoint, up[0], up[1], up[2]);
00103         break;
00104     }
00105     default:
00106         break;
00107     }
00108 }
00109 
00110 Vector3f HingeJoint::GetAxis()
00111 {
00112     dReal axis[3];
00113     dJointGetHingeAxis(mODEJoint, axis);
00114     return Vector3f (axis[0], axis[1], axis[2]);
00115 }
00116 
00117 float HingeJoint::GetAngle()
00118 {
00119     return gRadToDeg(dJointGetHingeAngle(mODEJoint));
00120 }
00121 
00122 float HingeJoint::GetAngleRate()
00123 {
00124     return gRadToDeg(dJointGetHingeAngleRate(mODEJoint));
00125 }
00126 
00127 void HingeJoint::SetParameter(int parameter, float value)
00128 {
00129     dJointSetHingeParam(mODEJoint, parameter, value);
00130 }
00131 
00132 float HingeJoint::GetParameter(int parameter)
00133 {
00134     return dJointGetHingeParam(mODEJoint, parameter);
00135 }
00136 
00137 
00138 
00139 
00140 
00141 

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4