旋转对象有关的OpenGL 3轴 [英] Rotate object about 3 axes in OpenGL

查看:148
本文介绍了旋转对象有关的OpenGL 3轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过增加旋转角度的值,轴达到目的绕3轴,并显示这些轴,使下一个旋转方向predictable为观看者。但经过几次轮换,只有Z轴旋转符合显示的轴进行。是否有一个机会,它可以简单地完成,而无需钻研四元?

I'm trying to achieve an object rotation about 3 axes by incrementing values of rotation angles for axes, and displaying those axes to make next rotation direction predictable for the viewer. But after a few rotations, only rotation about Z-axis is performed in accord with displayed axis. Is there a chance it can be done simply, without poring over quaternions?

glPushMatrix ();
glRotatef (angleX, 1.0, 0.0, 0.0);
glRotatef (angleY, 0.0, 1.0, 0.0);
glRotatef (angleZ, 0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(80.0, 0.0, 0.0);   //x axis
glVertex3f(-80.0, 0.0, 0.0);
glVertex3f(0.0, 80.0,  0.0);  //y axis
glVertex3f(0.0, -80.0,  0.0);
glVertex3f( 0.0, 0.0, 80.0);  //z axis
glVertex3f( 0.0, 0.0, -80.0);
//here is some code for drawing arrows at axes ends
glEnd();
glPopMatrix();

编辑: 我有这样的轴: http://img841.imageshack.us/i/arrowsx.jpg/ 的AngleX,angleY​​,angleZ是全局递增键preSS - 如:之后pressing'A'的AngleX由10增加,我预计X轴后,将不动轴和Y和Z将绕X轴,但它是真实的,只有当我只改变一个角度变量。有关更多然后一个轴旋转后,当我改变,例如:的AngleX - 从画面中的所有轴会改变他们的立场。

I have axes like those: http://img841.imageshack.us/i/arrowsx.jpg/ angleX, angleY, angleZ are globals incremented on key press - e.g. after pressing 'A' angleX is incremented by 10, and I expect axis X won't move after that and axes Y and Z will rotate about axis X. But it is true only when I change only one of angle variables. After rotation about more then one axis, when I change, e.g. angleX - all axes from picture will change their positions.

推荐答案

你基本上肿块发布你所有的关于每个轴的旋转成左右的轴线旋转一周的code。当你注意,它工作得很好,只要你正在做的是关于一个单一轴增量旋转。从您的更新,它也出现你想要的关键笔划为显示的旋转应用于图像,而不是总为您codeD。实现你要找的行为的一种方法是存储在一个队列或可调整大小的矢量(性病::载体,或std ::队列或其他容器中,如果你使用的是C ++)每个应用的旋转。每次用户presses一个键,添加固定角度尺寸的另​​一个绕所需的轴到列表中。在播放过程中,运用旋转中,他们输入的顺序(也许逆序,我得给它更多的思考)。这将适用的旋转所显示的几何形状,而不是规范(即未旋转)几何

The code you posted essentially lumps all of your rotations about each axis into a single rotation about that axis. As you note, it works well as long as all you're doing is incremental rotations about a single axis. From your update, it also appears that you want the key strokes to apply rotations to the image as displayed, rather than in aggregate as you have coded. One way to achieve the behavior you're looking for is to store in a queue or resizable vector (std::vector, or std::queue or some other container if you're using C++) each of the rotations that you apply. Each time the user presses a key, add another rotation of the fixed angle size about the desired axis to the list. During playback, apply the rotations in the order they were entered (maybe reverse order, I'll have to give it more thought). This will then apply the rotations to the displayed geometry, rather than to the canonical (i.e. un-rotated) geometry.

有可能是一个更容易,更内存密集型的方式使用四元数来做到这一点;这是一个领域,我真的需要得到更好的熟悉上。给我所知道的现在,虽然,这是我的样子会去实现我觉得你以后的行为。

There might be an easier and less memory intensive way to do this using quaternions; that's one area that I really need to get better versed on. Give what I know right now, though, this is the way I'd go about achieving the behavior I think you're after.

这篇关于旋转对象有关的OpenGL 3轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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