Find final world coordinates from model matrix or quaternion

巧了我就是萌 提交于 2019-12-04 21:10:03

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

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.

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

where

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

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.

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];

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

Re-implement gluProject() and apply everything but the viewport transform.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!