[ODE] initializing Hinge joint with a given angle that is not zero by default

dussane dussane at voila.fr
Fri Apr 23 12:56:42 MST 2004


Hello again,

I found the solution to my problem so here it is for those
interested (Andrew?). 

This is a little hack I'm afraid, and it may look dirty but
it was the quickest way to achieve what I wanted :-)
Modifications follows :


*** STEP 1
*** in ode/src/joint.cpp
*** add this function
***

// [!n200404221900]
// this method gives the ability to reinitialize the angle value without implying any physical action in the world.
extern "C" void dJointSetHingeAngleValue (dxJointHinge *joint, float ax, float ay, float az, float newAngle)  
{
  dAASSERT(joint);
  dUASSERT(joint->vtable == &__dhinge_vtable,"joint is not a hinge");
  if (joint->node[0].body) 
	dQFromAxisAndAngle (joint->qrel, ax, ay, az, newAngle);
}

*** STEP 2
*** in include/ode/objects.h
*** add this prototype
***

void dJointSetHingeAngleValue (dJointID, float ax, float ay, float az, float newAngle);


***
*** EXAMPLE OF USE
*** 

(...)
anchorJoint[0] = dJointCreateHinge (world,0);
dJointAttach (anchorJoint[0],wall_bodies[0],wall_bodies[1]);
dJointSetHingeAnchor (anchorJoint[0],x0+WBOXSIZE/2,y0,z0+WBOXSIZE/2);
dJointSetHingeAxis (anchorJoint[0],0,1,0);		
dJointSetHingeAngleValue(anchorJoint[0], 0, 1, 0, -M_PI/2);  


---> just after creating the joint and constraining it on the y axis, I set the initial value on this axis to be -PI/2
---> of course you can call this function whenever you want.

Since this is a more or less dirty hack, maybe it would be nice to have an expert comment about this and its implication within ODE.
At least for my application, it seems to work perfectly...

Hope this help :-)
-nicolas


------------------------------------------

Faites un voeu et puis Voila ! www.voila.fr 




More information about the ODE mailing list