views:

1437

answers:

3

I have a 3D Model (OpenGL ES 1.1 iPhone SDK v3.0) that is somewhat complex (i.e. Thousands of Vertexes and Faces) and I'd like to rotate this model around the Y-axis at or near the center of the Model. The problem is that glRotate rotates my model around a point at/near the center of one of its bottom edges, NOT near the center of the Model. Imagine a car driving very tight circles around a light-post, and that is basically what I've got. I want the car to be impaled on the light-post and be rotated around it. (Some source below)

// BLUE BLOCK----------------------------------------------

glPushMatrix(); {

glTranslatef(blueLocation[0], blueLocation[1], blueLocation[2]); glRotatef(blueRotAngle, 0.0, 0.0, 1.0);

THE QUESTION:
Is there an EASY way to change the Center of Rotation in OpenGL?

+4  A: 

Sure. Translate the object down. THEN rotate it.

Goz
I'm unable to re-position the model due to constraints in the game. So, I cannot translate. I'll UPDATE with some source in a sec..
RexOnRoids
Translate it so that the point you want to rotate around is at the origin, then rotate, then translate it to the location you want it at.
John Burton
@John, that will make it orbit the new origin, not rotate around "itself" (think year instead of day).
Martinho Fernandes
Translate >> ROTATE >> Translate Back WORKED. Thanks!
RexOnRoids
+1  A: 

You should use your model API to change the model origin. If you could tell which one you're using, maybe I could help some more.

If you have access to software that can edit your model, you can fix that directly in the model file and remove any hacks from your code.

Martinho Fernandes
A: 

It's worth remembering that all operations in OpenGL are carried out relative to the origin. You can't "change the Center of Rotation in OpenGL". You move the world relative to that origin.

Henry
His talking about the center of rotation of a mesh, you can definitely translate that and then rotate around the new "origin" of the mesh. (see accepted answer)
Grant Peters
Accepted answer is saying translate relative to the world origin, rotate and then translate back. Exactly what I was saying. If you don't understand how OpenGL works then I can't help you.
Henry