00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00049 Vector3f gAnchor(GetWorldTransform() * anchor);
00050 dJointSetHinge2Anchor (mODEJoint, gAnchor[0], gAnchor[1], gAnchor[2]);
00051
00052
00053 Vector3f up(GetWorldTransform().Rotate(Vector3f(0,0,1)));
00054 dJointSetHinge2Axis1(mODEJoint,up[0],up[1],up[2]);
00055
00056
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
00097
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