Page 1 of 1

Spherical to Euler Conversions

Posted: Mon Jul 16, 2007 3:15 pm
by CarlS
Hi all, :)

I’m trying to use Irrlicht to view the results of simulation runs.
The simulation outputs a file containing time, position in North/East/Down, and attitude in Azimuth, Elevation, and Roll. I built a driver that reads in the file and interpolates to find the current position and attitude, then applies those values to a scene node with a 3d model attached. There are no problems with the position of the model, but the rotation is another story.

Right now, the attitudes are being derived from the inertial velocity vectors as follows:
Azimuth = atan2(vely,velx) // 0 degrees is north, increasing CW is positive
Elevation = asin(velz/velmag) // 0 degrees is horizontal, increasing down is positive
Roll = 0.0 // to be calculated later

What I need to do is find the Euler angles which, when added up in Irrlicht, will result in the same inertial orientation that is in the file
To find the Euler angles, I can take a set of reference axes, and rotate the set around one axis at a time until the orientation matches the desired attitude, but what order would I need to do that in?

Any advice or tips would be appreciated. I’ve already done some searching here, but the combination of the rotation order questions and the reference system differences between the simulation and Irrlicht has got me stymied.

--Carl

Posted: Mon Jul 16, 2007 4:03 pm
by kendric
If you are doing what I think your saying, then these 2 helper functions may work for you. You will have to reindent them in your editor

vector3df convertRotationToFacing(vector3df rotation)
{
matrix4 mat;
mat.setRotationDegrees(vector3df( rotation.X, rotation.Y,0));
vector3df t(0,0,1);
mat.transformVect(t);
return t;
}

vector3df convertFacingToRotation(vector3df facing)
{
vector3df rotation(0,0,0);
rotation.Y = atan2( facing.X, facing.Z ) * 180.f / PI;
rotation.X = -atan2( facing.Y, sqrt( facing.X * facing.X + facing.Z * facing.Z ) ) * 180.f / PI;
return rotation;
}

Posted: Mon Jul 16, 2007 7:51 pm
by CarlS
Thanks Kendric, it looks like that did the trick :D

--Carl