OpenGL中的轨迹球旋转 [英] Trackball Rotation in OpenGL

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

问题描述

我无法在OpenGL上实现轨迹球旋转.当我使用轨迹球沿X轴向右旋转90度来旋转立方体(在屏幕上从左向右拖动鼠标),然后尝试旋转它,将鼠标从屏幕的顶部拖动到屏幕的底部时,我希望立方体沿我的透视图的y轴旋转.相反,它在旋转后沿ITS y轴旋转,从我的角度来看向侧面旋转.

I am having trouble implementing a trackball rotation on OpenGL. When I rotate my cube using the trackball rotation 90 degrees to the right along the X axis (dragging mouse left to right on screen) and then try rotating it dragging my mouse from the top to the bottom of the screen, I expect the cube to rotate along my perspective's y-axis. Instead it rotates along ITS y-axis after rotation, rotating sideways from my perspective.

有人可以告诉我我可能做错了什么吗?

Can someone show me what I may be doing wrong?

推荐答案

听起来您没有使用四元数来表示旋转.如果您使用Google搜索"Arcball Graphics Gems",那么您应该可以在Kenshoemake的Graphic Gems IV中找到代码.

It sounds like you're not using quaternions to represent the rotation. If you Google for "Arcball Graphics Gems" you should be able to find code by Ken Shoemake’s in Graphic Gems IV.

或者,如果您只想要代码,请转到此处.

Or, if you just want the code, go here.

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

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