向 OpenGL 中的路径旋转
我在如何基于 OpenGL 旋转函数 glRotatef(..) 旋转 3D 空间中的对象时遇到问题。
glRotatef ( angle , x , y , z )
我的物体在 3D 空间中从一个点移动到另一个点。我希望我的物体沿其行进方向旋转。
如果我知道开始点和结束点,我将如何找到 glRotatef(...) 函数所需的角度 x、y、z。
I am having trouble on how to rotate an object in 3D space, based on the OpenGL rotate function glRotatef(..).
glRotatef ( angle , x , y , z )
My object is traveling from one point to another in 3D space. I want my object to rotate in the direction it is traveling.
How would I find the angle, x, y, z that is needed for the glRotatef(...) function if I know the point where I am starting and the point where I am finishing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gluLookAt
函数正是您所需要的。它将使您免于手动计算轴和角度。The
gluLookAt
function is exactly what you need here. It will save you from calculating the axis and angle manually.非常粗略地说,您需要的是获得旋转轴,该轴将垂直于行进方向和表面法线,这意味着行进方向 (T) 和表面法线 (n) 的叉积将给你一个旋转轴。因此 axis(A) 将为:
A =norm(T xn) 或 A =norm(nx T),其中之一将允许您使用正角度以正确的方向“旋转”。
然而,需要根据您使用的上述哪一种来分析旋转角度的正或负性质,但这应该让您开始了解旋转轴:)
Very crudely, what you need is to get the axis of rotation, which will be normal to both the direction of travel and the surface normal, which would mean a cross product of the direction of travel (T) and surface normal (n) would give you an axis for your rotation. Thus axis(A) would be:
A = norm(T x n) or maybe A = norm(n x T), one of which will let you use a positive angle to "rotate" in the right direction.
However, the positive or negative nature of the angle of rotation needs to be analyzed depending on which one of the above you use, but this should get you started with the axis of rotation :)