ODE - Axis rotation nightmare (need math help)

Blitz3D Forums/Blitz3D Userlibs/ODE - Axis rotation nightmare (need math help)

Danny(Posted 2006) [#1]
Hi,

I'm in desperate need of some math help...

I have a HINGE JOINT along the X-axis (1,0,0) and uses the Lo-Stop/Hi-Stop constraints set to -1.0*pi and +1.0*pi.

This works fine, but at a certain point I need to re-set the joint (for example after the object has been moved in the editor, or a level is re-loaded). So I need to reset the joint's position and rotate it's axis relatively to the object. I use the following code - which works perfectly fine:

;reposition joint with offset relative to mesh's current position & rotation
;----------------
TFormPoint xOffset#,yOffset#,zOffset#, mesh, 0
dJointSetHingeAnchor joint, TFormedX#(),TFormedY#(),TFormedZ#()

;re-align the joint's axis (Hinge along X axis) relative to mesh's current rotation
;----------------
ax# = 1.0
ay# = 0.0
az# = 0.0
TFormNormal ax#,ay#,az#, mesh, 0
dJointSetHingeAxis joint, TFormedX#(),TFormedY#(),TFormedZ#()
BUT then I realised that the Joint's LO-STOP and HI-STOP values need to be adjusted as well!! To compensate for the Joint's Axis rotation!
Since the axis is no longer aigned at 1,0,0 the lo/histop values -1*pi and +1*pi won't give the same result ie. they need to be 'rotated' as well.

So I guess I have to rotate the axis-vector by the original lo/histop values to get the new lo/histop values. But rotating vectors around their axis and mixing degrees and pi's and.. Sorry, I have no cue how to do this! :)

Any help greatly appreciated!

Danny


VIP3R(Posted 2006) [#2]
The normal procedure for resetting stuff like joint axis angles is to build the object/joints in their default position/rotation, only then should you reposition and rotate them to their new values.

Remember that the hi/lo stops use radians, not degrees.

Hope this helps :)


Danny(Posted 2006) [#3]
Hi Vip3r,

That's exactly what that function is intended to do to 'reposition and rotate them to their new values' after having them setup from their default position.
If the object is made of 2 rigib bodies connected by a hinge, I need to move/rotate the 2 bodies AND the joint all togther - keeping their relative offsets and angles in tact. I got everything else working (the bodies, joint position & axis); just converting these lo/hi stops are giving me a headache ;)


VIP3R(Posted 2006) [#4]
Are you using radians for the lo/hi stops?

Get the angle of the hinge axis after rotating it and use the following conversions to change the angle of the hinge axis (which is in degrees) into radians for the lo/hi stops...

1 Radian = 57.2957795130823208767981548141052 Degrees
1 Degree = 0.0174532925199432957692369076848861 Radians

...then offset the default lo/hi stops values by the result of the above calculation.


Danny(Posted 2006) [#5]
Yes viper, I'm using radians.

But I think my first conclusion is wrong. When I reset two bodies connected by a joint - and make sure they are WITHIN the given lo/hi stop constrains then there's no problem.

I was expecting that the lo/hi stop would FORCE the bodies/hinge back to within the constrains, but I guess it doesn't do that when you reset all forces on the bodies...
And instead the bodies seem to be happy to intersect with each other whilst the hinge is way out of it's lo/hi stop. But not 100% sure about that statement either.. :/


VIP3R(Posted 2006) [#6]

I guess it doesn't do that when you reset all forces on the bodies...


Yeh, that sounds about right to me. You could try stepping the simulation first before resetting the forces, maybe that will work. It's difficult to say with any certainty as I've not tried doing this myself.

If you're still stuck, send me a simple demo over that illustrates the problem and I'll see if I can help.