Rotation around global Y-axis

Hi guys,

Maybe the following question is trivial, but my brain simply ceased to function at the moment, and I need little assistance. :frowning:

Well, in short, I need a rotation around global Y-axis ( Fig.1 ). The following code demonstrates the transformation of local coordinate system, and the position of the “missing” transformation.

double modelMat[16];
OGL::Translate(modelMat, 0, 0, -R);
// Missing rotation !!! :(
OGL::Rotate(modelMat, -DeltaLat, 1.0, 0.0, 0.0);
OGL::Rotate(modelMat, DeltaLon, 0.0, cos(Theta), sin(Theta));
OGL::Translate(modelMat, 0, 0, R);

DeltaLon and DeltaLat are longitudinal and latitudinal offsets of the local coordinate system relative to the central object, but I think they are irrelevant for the missing transformation. Theta is the absolute latitude.

Thank you in advance!

As no-one else replied yet, I’ll try with my poor maths:
Don’t you just need the matrix from here

I assume it’s about finding the transformation for an object on a rotating planet, and the object is already transformed relatively to the planet’s centre, which happens to be vec3(0,0,0). (if it’s not, translate the object so that it’s centered around {0,0,0}, rotate with the simple axis thing - after doing the usual local transforms, and then do the opposite translation).

Another way - simply create a localMatrix (relative to planet) and planetMatrix (relative to whatever), and multiply.
Or am I thinking of too simple cases?

Thank you very much Ilian!
But the problem is more complicated than I described, and furthermore more than I was aware of. Local coordinate system implicitly contains transformation included in Theta.
theta = asin(cos(lat)*cos(lon));

I had some problems with coordinate system transformation caused by finite precision of DP and acos/asin function (instead of 1.0 frequently I got 1.000000000000000002 or something like this, which caused infinite values), and preserving sign of longitudinal transformation.

The transformation still doesn’t work correctly, but this is something I have to solve on my own. I posted previous question in a moment of despair. :frowning: Sorry!

Thanks again!

Just saying, I don’t know what the problem you’re having is, but I do know that rotation around the global y axis is very, very simple:

OGL::Rotate(modelMat, mytheta,0.0,1.0,0.0);

so if you do still need help… could you rephrase your question?

Thanks NeuroFuzzy for offering help, but the problem is not so trivial.
Maybe this figure illustrates the problem better.

Consider just North Pole’s cap. If the transformation is as follows:

OGL::Translate(modelMat, 0, 0, -_Rz);
OGL::Rotate(modelMat, -m_pRend->m_pCamera->m_Lon, 0.0, 0.0, 1.0);//!!!
OGL::Rotate(modelMat, -DeltaLat, 1.0, 0.0, 0.0);
OGL::Rotate(modelMat, DeltaLon, 0.0, cos(rTeta), sin(rTeta));	
OGL::Translate(modelMat, 0, 0, _Rz);

then polar cap rotates with equatorial region correctly, but is at exact position only for longitudes: 0, 90, 180, 270, etc. For other angles it depends on Theta. I just cannot figure it out how. :frowning:

Maybe the rotation around inclined axis (OGL::Rotate(modelMat, DeltaLon, 0.0, cos(rTeta), sin(rTeta))) prevents me to figure it out. Can it be decomposed into simple rotations around coordinate system axis? The worst thing is that I’ve devised the transformation, but now I cannot control the “monster”. :frowning:

It would also be useful to remark that the Polar cap is constructed against the point right below the viewer (center of the globe is always in the -z-direction).

And, yes, this is very important: rTeta = asin(-cos(lat)*cos(lon));

Thanks in advance!

Perhaps you should look at this. The quaternion stuff isn’t as important as the details about which side of the matrix you multiply on, and the effect it has on the rotation.

Thank you Alfonse for the suggestion. I’ll take a look at quaternions, but I guess I can solve the problem with a simple rotation. In fact, I already have right transformation. I just have to figure out the vector around which I have to rotate northern cap. It depends on equatorial to north coordinate system transformation (my internal transformation).