How to change the Center-of-Rotation in OpenGL

喜欢而已 提交于 2019-12-12 11:14:43

问题


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:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1130520/how-to-change-the-center-of-rotation-in-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!