# 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.

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.

As no-one else replied yet, Iāll try with my poor maths:
Donāt you just need the matrix from here
http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml

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. 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.

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ā.

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));