# The Industry's Foundation for High Performance Graphics

1. ## Translating an object

My OpenGL graphics engine allows a user to load an object that is specified relative to its own internal origin. The object may also be rotated about any of the three major axis. The object can then be painted (with texturing) at any model view location.

My problem is that the new origin say (vx,vy,vz) must also be rotated. I have done this by using the modelview matrix and multiplying it against the aforementioned vector (new origin). However this does not seem to rotate it properly. The following is the algorithm used:

1. rotate to the worlds rotation (rx, ry, rz)
2. translate to (0.0, 0.0, 0.0)
3. get the modelview matrix
4. multiply the matrix against the position
vector (vx,vy,vz) (Mv = p)
5. reset the modelview matrix to identity
6. rotate the object by its internal rotation
and the worlds rotation (three axis)
7. translate to the new previously
calculated position vector p.
8. If the object is inside the frustum then
paint it.

This does not seem to plave the object correctly with respect to the floor of my test world.

Any ideas?

Robin

2. ## Re: Translating an object

Sorry, I didn't understand you problem. Please select one of the following:

a. You want the objects to be rotated around the world's origin
b. You want them to be rotated around their internal origin, as coming from the modelling program
c. You want to rotate them around some other point
d. You need the transformed positions for frustum culling (determining what you need to draw)
e. None of the above, it's more like...

-Ilkka

3. ## Re: Translating an object

The objects are being rotated about BOTH their own internal origin and about the real modelview origin. For example lets say that my WHOLE world is rotated 45 degrees about the Y axis and 30 degrees about the X axis. AND the object itself is rotated about the Y axis. This is the same as saying I have a box in a room but the box is rotated and the box is NOT at the origin. It is translated.

Understand?

Robin.

[This message has been edited by Robin Forster (edited 02-06-2003).]

4. ## Re: Translating an object

Yeah, I think I get it.

I suppose the whole world rotation is there to simulate the camera, and then the objects just are rotated in their own coordinate systems.

I think that it's the local coordinate system in opengl that's confusing you. Luckily it also makes this kind of things very simple. Change your algorithm to this:

1. Set camera transform, for example
glRotatef(-yaw, 0, 1, 0)
glRotatef(-pitch, 1, 0, 0)
glTranslatef(-camx, -camy, -camz)

2. For each object do
glPushMatrix
glTranslatef(posx...
glRotatef(...
draw the object
glPopMatrix

All the objects get automatically rotated in their own coordinate systems, and the camera transform gets applied to them. Sorry if that was unclear, it's quite easy when you get the hang of it.

-Ilkka

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•