OpenGL的OpenTK旋转问题 [英] OpenGL-OpenTK rotation problems

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

问题描述

我是谁刚开始学习3D编程一个真正的菜鸟,我有一个很艰难的时间来学习在3D空间中旋转。我的问题是,我似乎无法弄清楚如何使用它的本地坐标旋转对象。

I'm a real noob who just started learning 3d programming and i have a really hard time learning about rotation in 3D space. My problem is that I can't seem to figure out how to rotate an object using it's local coordinates.

我有一个基本的类3D物体,首先,我要实现的功能,将旋转对象在某个轴X度。到目前为止,我有以下几点:

I have a basic class for 3d objects and, for starters, i want to implement functions that will rotate the object on a certain axis with x degrees. So far i have the following:

 public void RollDeg(float angle)
    {
        this.rotation = Matrix4.Mult(rotation, 
            Matrix4.CreateRotationX(MyMath.Conversions.DegToRad(angle)));
    }

    public void PitchDeg(float angle)
    {
        this.rotation = Matrix4.Mult(rotation, 
             Matrix4.CreateRotationY(MyMath.Conversions.DegToRad(angle)));
    }

    public void YawDeg(float angle)
    {
        this.rotation = Matrix4.Mult(rotation,
             Matrix4.CreateRotationZ(MyMath.Conversions.DegToRad(angle)));
    }

旋转是开始为单位矩阵4x4矩阵。每次我想滚/俯仰/偏航对象,我调用上面的功能之一。

'rotation' is a 4x4 matrix which starts as the identity matrix. Each time i want to roll/pitch/yaw the object, i call one of the functions above.

有关图纸,我用另外一个功能是推动一个矩阵到模型视图堆栈,与对象的平移,旋转和缩放矩阵相乘(按顺序),并开始绘制顶点。 ofcourse,我终于弹出矩阵堆栈。

for drawing, i use another function that pushes a matrix onto the ModelView stack, multiplies it with the translation, rotation and scale matrices of the object (in this order) and begins drawing the vertices. ofcourse, finally i pop the matrix off the stack.

问题是,上述功能旋转对象上全球轴,不在本地的,即使从我的理解,每次旋转一个物体时,本地系统更改它的轴,然后,当一个新的旋转applyied在他人的顶部,本地轴被用于新的一个。

the problem is that the functions above rotate the object on the GLOBAL axis, not on the LOCAL ones, even if, from my understanding, every time you rotate an object, the local system changes it's axis and then, when a new rotation is applyied on top of the others, the local axis are used for the new one.

我读到它,以及如何背后的数学旋转的物体不同的教程,但我无法找到一个可以帮助我。

i read different tutorials about the math behind it and how to rotate objects, but i couldn't find one the could help me.

如果有人有时间,我会很AP preciate是否可以帮助我了解如何绕局部轴和,也许更重要的是,我做错了什么对我目前的执行情况。

if anyone has the time, i would really appreciate if he could help me understand HOW to rotate around local axis and, maybe even more important, what i did wrong on my current implementation.

推荐答案

如果您要执行的变换顺序是:翻译 - >旋转 - >规模(这使得完全意义上来说,什么是想要的通常情况下),你必须按相反的顺序乘以你的矩阵。

If you want to perform your transformations in this order : translation -> rotation -> scale (which makes perfectly sense, it's what's wanted usually), you have to multiply your matrices in the reverse order.

在右手坐标系统(例如:一个openGL的使用),矩阵乘法必须从右到左进行的。这就是为什么:

In a right-handed coordinate system (i.e. the one openGL uses), matrix multiplication must be performed from right to left. This is why :

ModelViewTransform =变换*查看*型号//< - 你开始通过模型,对吧?所以它是这样

ModelViewTransform = Transform * View * Model // <- you begin by the model, right ? so it's this way

请注意,在DirectX的,他们使用左手坐标系。它有他的缺点,但它更直观。

Note that in directX they use a left-handed coordinate system. It has his shortcomings, but it's more intuitive.

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

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