I am working on my own, so I do not have anybody to discuss my issues with opengl, so I would appreciate if somebody could give my thoughts a push in the right direction.

The object I am working on is a piece of the earths surface and the horizontal coords are the utm-coords of this location and z is the elevation. Therefore (0,0,0) is very far away from my object. Now I want to keep my camera trained on a certain point while I move it right and left or up and down.

This involves rotation of my object around an axis that is offset from (0,0,0) - how to do this ?

With XC, YC, Z being the coords of the point my camera is trained on dis translate this first

glMatrixMode (GL_MODELVIEW)

glLoadIdentity()

glTranslateF (-xc, -yc, -z)

Then rotate the object

glRotatef (Angle, 1.0, 0.0, 0.0)

and zoom out

glTranslateF (0.0, 0.0, - CamDistance)

But this seems to rotate my object around its original x-axis (which is 5000 kilometers to the south) - and of course out of my projection. Which is the point I overlooked ?

Thanks in advance for a friendly (!) push in the right direction.

Norbert

Correct me if I’m wrong, but couldn’t you just do something like this in immediate mode OpenGL?

```
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// before any transformations, reset it to origin
glTranslatef(0.0f, 0.0f, 0.0f);
// rotate about origin:
glRotatef(Angle, 1.0, 0.0, 0.0);
// move rotated obj to desired position:
glTranslatef(-xc, -yc, -z);
```

Eddy,

that is about what I wanted to do (except that I understood that glTranslatef (0.0,0.0,0.0) would not move the object.) My first line was intended to do just that. But I never could persuade OpenGL to use any other axis than one passing through (0.0, 0.0, 0.0) of the original object coordinates. Of course I can change the direction of the axis - but I could not offset it.

Meanwhile I solved my problem by reorganising my data (was quite a job) so that the origin is right in the middle of my object. But I am not really satisfied with this work around solution.

Norbert

I’m not sure if you’re doing this right now, but have you looked at glPushMatrix and glPopMatrix?

```
// set world xforms here, etc.
// Stop affecting the world matrix, but take a copy of
// it and make it current to base the new xform
// off of that coordinate system:
glPushMatrix();
// Set xforms for the object you wish to draw:
glRotatef(x, y, x);
glTranslatef(x, y, z);
// etc.
// Draw your object:
DrawMyObject();
// Remove or "pop" the copy, and make the previous
// matrix current again.
glPopMatrix();
// Xforms apply to world again
```

Sorry (and thanks for your support), but I do not really get it.

Where is the difference, if I start anew (glLoadIdentity) or push a prior existing non-identity matrix down the stack ? I mean, with respect to my object, of course. In fact, as of now I have only this one object to place (I am near the beginning of my project), so I did not bother to save a copy of the matrix.

Norbert

glPushMatrix preserves the current matrix, so that the next call to glPopMatrix will restore it.

glLoadIdentity will destroy the current matrix, setting it to identity.

These functions do the exact opposite things.

Yes, I understand that perfectly.

But I want to place just one object, so there is no prior matrix I want to save for further use - at least that is what I understand. That is why I started with loading identity, tried to translate my object into focus and rotate it around an axis parallel to the object’s x-axis.

Well, I solved the problem by reorganising my data so 0,0,0 is right in the center of my object and achieve my target by rotation and translation.

Thanks folks

Norbert

But I want to place just one object, so there is no prior matrix I want to save for further use

But there is a prior matrix: the camera matrix. The one you built with gluLookAt.

World space is the space where everything, including the camera, is relative to the same coordinate system. The modelview matrix transforms to camera/eye space, where everything is relative to the camera. Therefore, you need to have the camera matrix as part of any object’s transform if you want all of your objects to be relative to the same camera.

Okay, I understand I got to review this superbilble of mine…

Norbert