开发者

Converting local (=rotated) coordinates to global coordinate

开发者 https://www.devze.com 2023-02-28 11:53 出处:网络
I have a QVector3D which defines an object\'s velocity in local coordinate system (= positive Z means moving forward,...), and a QVector3D in 10th-of-degree (0..3600) steps defining the rotation of th

I have a QVector3D which defines an object's velocity in local coordinate system (= positive Z means moving forward,...), and a QVector3D in 10th-of-degree (0..3600) steps defining the rotation of the object in the global coordinate system.

now to simulate my scene, i need the object's velocity QVector3D in global coordinate system.

what i've found so far are the rotation matrices (from http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_three_dimensions):

qreal angle(qreal in){ //helper function
    return in/1开发者_StackOverflow中文版800.0f*M_PI;
}

    qreal xptr[9]={
        1,0,0,
        0,cos(angle(rotation.x())),-sin(angle(rotation.x())),
        0,sin(angle(rotation.x())),cos(angle(rotation.x()))
    };
    qreal yptr[9]={
        cos(angle(rotation.y())),0,sin(angle(rotation.y())),
        0,1,0,
        -sin(angle(rotation.y())),0,cos(angle(rotation.y()))
    };
    qreal zptr[9]={
        cos(angle(rotation.z())),-sin(angle(rotation.z())),0,
        sin(angle(rotation.z())),cos(angle(rotation.z())),0,
        0,0,1
    };

but i have no idea how to correctly use them.

EDIT: if its relevant: units, rotation direction, ... follow OpenGL standard.


Use matrix products: transfomration_matrix x original_vector = transformed_vector

0

精彩评论

暂无评论...
验证码 换一张
取 消