vrml97 object rotation ( the sfrotation format)

Hello,
Well, I’m sure this is probably a simple problem, but I just can’t crack it.
VRML97 doesn’t store rotation by simply giving the x, y, z rotations. Instead, it first stores a 3d normalized vector of the axis, then the amount of “right-handed” rotation about that axis. My question is, how do I get x, y, z rotations from that data? Any help here would be much appreciated!

Why do you need to know the x, y, and z rotations?

In OpenGL, when you call the glRotatef function, the first argument is the amount of right handed rotation, and the rest of the arguments are the rotation axis.

So it seems to me like you can just plug the values in without bothering with a conversion.

j

It’s for a project I’m working on. We’ll be doing a good deal of computations with the rotations and the objects, not just displaying them in opengl, and it would be worlds easier to have the seperate x,y, z rotations.

Although what J said is right I’ll try to find what you want. Well, I’m not sure of what I found but I’ll write it anyway:

First, you have to write a function that returns the angle from it’s sine and cosine (I don’t know if there is a ready-to-use function in C++ for this purpose, because I’m a Delphi programmer):

double Angle(double S, double C) {

double Result;
if(C==0)
if(S>0)
Result=+Pi/2;
else
Result=-Pi/2;
else {
Result=ArcTan(S/C);
if(C<0)
Result+=Pi;
}

return 180*Result/Pi;
}

You calculate the rotations like this:

AY=Angle(AxisX,AxisZ);
AZ=Angle(AxisY,Sqrt(Sqr(AxisX)+Aqr(AxisZ)));
AX=AAxis;

I’m not sure if the sequence of rotations is important, but I know that it may work if you rotate round y, then round z and finally round x:

glRotated(AX,1,0,0);
glRotated(AZ,0,0,1);
glRotated(AY,0,1,0);

glVertex(…);
glVertex(…);
.
.
.

Well, I didn’t try it so, I can’t guarantee that it will work!

Its a classical conversion from an Axis/Angle representation to an Euler representation. I can’t give some code like that off the head but you should check the GEMs, a book like the Watt or search the web for that. It should be pretty easy to find.

Thanks for the responses. I’ll give your suggestions a try!