newspeoplefor developersdocumentationdownloads

amotor.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //  physics/amotor.cc
00003 //  (C) 2005 Radon Labs GmbH
00004 //------------------------------------------------------------------------------
00005 #include "physics/amotor.h"
00006 
00007 namespace Physics
00008 {
00009 ImplementRtti(Physics::AMotor, Physics::Joint);
00010 ImplementFactory(Physics::AMotor);
00011 
00012 //------------------------------------------------------------------------------
00015 AMotor::AMotor() :
00016     Joint(Joint::AMotor)
00017 {
00018     // empty
00019 }
00020 
00021 //------------------------------------------------------------------------------
00024 AMotor::~AMotor()
00025 {
00026     // empty
00027 }
00028 
00029 //------------------------------------------------------------------------------
00034 void
00035 AMotor::Attach(dWorldID worldID, dJointGroupID groupID, const matrix44& m)
00036 {
00037     // create ODE joint
00038     this->odeJointId = dJointCreateAMotor(worldID, groupID);
00039 
00040     // configure ODE joint
00041     dJointSetAMotorMode(this->odeJointId, dAMotorUser);
00042     dJointSetAMotorNumAxes(this->odeJointId, this->GetNumAxes());
00043     int i;
00044     int num = this->GetNumAxes();
00045     for (i = 0; i < num; i++)
00046     {
00047         const JointAxis& curAxis = this->axisParams[i];
00048         dJointSetAMotorAngle(this->odeJointId, i, curAxis.GetAngle());
00049         if (curAxis.IsLoStopEnabled())
00050         {
00051             dJointSetAMotorParam(this->odeJointId, dParamLoStop + dParamGroup * i, curAxis.GetLoStop());
00052         }
00053         if (curAxis.IsHiStopEnabled())
00054         {
00055             dJointSetAMotorParam(this->odeJointId, dParamHiStop + dParamGroup * i, curAxis.GetHiStop());
00056         }
00057         dJointSetAMotorParam(this->odeJointId, dParamVel + dParamGroup * i, curAxis.GetVelocity());
00058         dJointSetAMotorParam(this->odeJointId, dParamFMax + dParamGroup * i, curAxis.GetFMax());
00059         dJointSetAMotorParam(this->odeJointId, dParamFudgeFactor + dParamGroup * i, curAxis.GetFudgeFactor());
00060         dJointSetAMotorParam(this->odeJointId, dParamBounce + dParamGroup * i, curAxis.GetBounce());
00061         dJointSetAMotorParam(this->odeJointId, dParamCFM + dParamGroup * i, curAxis.GetCFM());
00062         dJointSetAMotorParam(this->odeJointId, dParamStopERP + dParamGroup * i, curAxis.GetStopERP());
00063         dJointSetAMotorParam(this->odeJointId, dParamStopCFM + dParamGroup * i, curAxis.GetStopCFM());
00064     }
00065 
00066     // hand to parent class
00067     Joint::Attach(worldID, groupID, m);
00068 
00069     // configure ODE joint
00070     this->UpdateTransform(m);
00071 }
00072 
00073 //------------------------------------------------------------------------------
00076 void
00077 AMotor::UpdateTransform(const matrix44& m)
00078 {
00079     matrix33 m33(m.x_component(), m.y_component(), m.z_component());
00080     int i;
00081     int num = this->GetNumAxes();
00082     for (i = 0; i < num; i++)
00083     {
00084         vector3 a = m33 * this->axisParams[i].GetAxis();
00085         dJointSetAMotorAxis(this->odeJointId, i, 0, a.x, a.y, a.z);
00086     }
00087 }
00088 
00089 }; // namespace Physics

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.