从模型矩阵或四元数中寻找最终世界坐标 [英] Find final world coordinates from model matrix or quaternion

查看:270
本文介绍了从模型矩阵或四元数中寻找最终世界坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用对象的模型矩阵在OpenGL中显示一个对象,我从我预先存储的对象位置和一个应用于旋转的四元数构建。我需要在应用旋转和变换(对象出现在屏幕上的坐标)后,找到我的对象的最终笛卡尔坐标在3D

I am displaying an object in OpenGL using a model matrix for the object, which I build from my pre-stored object location AND a quaternion applied to the rotation. I need to find the final cartesian coordinates in 3D of my object AFTER the rotations and transformations applied (the coordinates that the object appears at on the screen). How can I get the plain coordinates?

推荐答案

如果我理解正确,你有一个对象;如果您在未应用任何变换的情况下呈现,则其中心位于 [0,0,0]

If I understand correctly, you have an object; if you rendered it without applying any transformation, its center would be at [0,0,0].

您在3D空间中有一个点 [a,b,c] 。您将转换应用于modelview矩阵。现在,如果你渲染了对象,它的中心将是在世界空间坐标中 [a,b,c]

You have a point, [a,b,c], in 3D space. You apply a translation to the modelview matrix. Now, if you rendered the object, its center would be at [a,b,c] in world space coordinates.

四元数, [qw,qx,qy,qz] 。您创建旋转矩阵 M ,并从中应用它到modelview矩阵。现在,您想要知道对象在世界空间中心的新坐标, [a',b',c']

You have a quaternion, [qw,qx,qy,qz]. You create a rotation matrix, M, from this and apply it to the modelview matrix. Now you want to know the new coordinates, [a',b',c'], of the object's center in world space.

如果这是真的,那么最简单的方法是自己做矩阵乘法:

If this is true, then the easiest way is to just do the matrix multiplication yourself:

a' = m11*a + m12*b + m13*c
b' = m21*a + m22*b + m23*c
c' = m31*a + m32*b + m33*c

其中

    [m11 m12 m13]
M = [m21 m22 m23]
    [m31 m32 m33]

但也许你实际上并不是建立 M 。另一种方法是直接使用四元数,虽然基本上涉及到构建旋转矩阵然后使用它。

But perhaps you're not actually building M. Another way would be to use the quaternion directly, although that essentially involves building the rotation matrix and then using it.

应该不需要实际使用 gluProject 。当将旋转应用到modelview矩阵时,矩阵乘法在那里完成。所以你可以从矩阵本身得到值:

There should be no need to actually use gluProject. When you apply the rotation to the modelview matrix, the matrix multiply is done there. So you could just get the values from the matrix itself:

double mv[16];
glGetDoublev(GL_MODELVIEW_MATRIX,mv);
a' = mv[13];
b' = mv[14];
c' = mv[15];

这告诉你modelview矩阵在哪里移动模型的原点。

This tells you where the modelview matrix is moving the model's origin.

这篇关于从模型矩阵或四元数中寻找最终世界坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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