How to change the Center-of-Rotation in OpenGL

2019-06-26 07:20发布

问题:

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?

回答1:

Sure. Translate the object down. THEN rotate it.



回答2:

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.



回答3:

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.