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

hinge2joint.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: hinge2joint.cpp,v 1.3 2004/05/01 11:30:31 rollmark 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 "hinge2joint.h"
00021 #include <zeitgeist/logserver/logserver.h>
00022 
00023 using namespace oxygen;
00024 using namespace boost;
00025 using namespace salt;
00026 
00027 Hinge2Joint::Hinge2Joint() : Joint()
00028 {
00029 }
00030 
00031 Hinge2Joint::~Hinge2Joint()
00032 {
00033 }
00034 
00035 void Hinge2Joint::OnLink()
00036 {
00037     dWorldID world = GetWorldID();
00038     if (world == 0)
00039         {
00040             return;
00041         }
00042 
00043     mODEJoint = dJointCreateHinge2(world, 0);
00044 }
00045 
00046 void Hinge2Joint::SetAnchor(const Vector3f& anchor)
00047 {
00048     // calculate anchor position in world coordinates
00049     Vector3f gAnchor(GetWorldTransform() * anchor);
00050     dJointSetHinge2Anchor (mODEJoint, gAnchor[0], gAnchor[1], gAnchor[2]);
00051 
00052     // relative universal hinge2 axis 1 points up
00053     Vector3f up(GetWorldTransform().Rotate(Vector3f(0,0,1)));
00054     dJointSetHinge2Axis1(mODEJoint,up[0],up[1],up[2]);
00055 
00056     // relative universal hinge2 axis 2 points right
00057     Vector3f right(GetWorldTransform().Rotate(Vector3f(1,0,0)));
00058     dJointSetHinge2Axis2(mODEJoint,right[0],right[1],right[2]);
00059 }
00060 
00061 Vector3f Hinge2Joint::GetAnchor(EBodyIndex idx)
00062 {
00063     Vector3f pos(0,0,0);
00064 
00065     switch (idx)
00066         {
00067         case BI_FIRST:
00068             {
00069                 dReal anchor[3];
00070                 dJointGetHinge2Anchor (mODEJoint, anchor);
00071                 pos = Vector3f(anchor[0],anchor[1],anchor[2]);
00072             }
00073 
00074         case BI_SECOND:
00075             {
00076                 dReal anchor[3];
00077                 dJointGetHinge2Anchor2(mODEJoint, anchor);
00078                 pos = Vector3f(anchor[0],anchor[1],anchor[2]);
00079             }
00080 
00081         default:
00082             break;
00083         }
00084 
00085     return GetLocalPos(pos);
00086 }
00087 
00088 float Hinge2Joint::GetAngle(EAxisIndex idx)
00089 {
00090     switch (idx)
00091         {
00092         case AI_FIRST:
00093             return gRadToDeg(dJointGetHinge2Angle1(mODEJoint));
00094 
00095         case AI_SECOND:
00096             // dJointGetHinge2Angle2 is undeclared in ODE 0.039
00097             // return dJointGetHinge2Angle2(mODEJoint);
00098             return 0;
00099 
00100         default:
00101             return 0;
00102         }
00103 }
00104 
00105 float Hinge2Joint::GetAngleRate(EAxisIndex idx)
00106 {
00107     switch (idx)
00108         {
00109         case AI_FIRST:
00110             return gRadToDeg(dJointGetHinge2Angle1Rate(mODEJoint));
00111 
00112         case AI_SECOND:
00113             return gRadToDeg(dJointGetHinge2Angle2Rate(mODEJoint));
00114 
00115         default:
00116             return 0;
00117         }
00118 }
00119 
00120 void Hinge2Joint::SetParameter(int parameter, float value)
00121 {
00122     dJointSetHinge2Param(mODEJoint, parameter, value);
00123 }
00124 
00125 float Hinge2Joint::GetParameter(int parameter)
00126 {
00127     return dJointGetHinge2Param(mODEJoint, parameter);
00128 }
00129 
00130 
00131 
00132 
00133 

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