在opengl中围绕固定点旋转对象 [英] Rotating an object around a fixed point in opengl

查看:121
本文介绍了在opengl中围绕固定点旋转对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个openGL代码有疑问:

I have a problem with this openGL code:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix(); // put current matrix on stack

//glTranslatef(0.0f, 0.0f, 0.0f);   
//glTranslatef(-4*1.5, 0.0, 4*1.5);

glRotatef(rotationAngle, 0.0f, 1.0f, 0.0f); // rotate the robot on its y-axis
glTranslatef(xpos, ypos, zpos);
DrawRobot(xpos, ypos, zpos); // draw the robot
glPopMatrix();

我该怎么做才能使机器人绕过当前位置而不是绕原点旋转?我认为问题出在这个摘要中.

What should I do to make my robot turn around the point at which it is currently situated and not around the origin? I think the problem lies in this snippet.

推荐答案

仅在翻译后进行轮换.顺序很重要.

Simply do the rotation after the translation. The order matters.

glTranslatef(xpos, ypos, zpos);
glRotatef(rotationAngle, 0.0f, 1.0f, 0.0f);

这篇关于在opengl中围绕固定点旋转对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆