首页 > 其他 > 详细

Transform using the glm library

时间:2020-05-15 15:44:44      阅读:61      评论:0      收藏:0      [点我收藏+]
// Rotation

/* Matrix to quaternion */
    glm::quat q_from_matrix3x3{ glm::mat3{1} }; // cast operator will handle this

    glm::quat q_from_matrix4x4{ glm::mat4{1} }; // cast operator will handle this

/* Matrix to Euler rotation */
    float x, y, z; // radians
    glm::extractEulerAngleXYZ(glm::mat4{ 1 }, x, y, z);

    glm::extractEulerAngleZYX(glm::mat4{ 1 }, z, y, x); // pay attention to the parameter order, z->y->x

/* Quaternion to matrix */
    glm::mat3 matrix3x3_from_quaternion{ glm::quat{1.0f, 0, 0, 0} }; // cast operator will handle this

    glm::mat4 matrix4x4_from_quaternion{ glm::quat{1.0f, 0, 0, 0} }; // cast operator will handle this

/* Quaternion to Euler rotation */
    glm::vec3 euler_angles_zyx = glm::eulerAngles(glm::quat{ 1.0f, 0, 0, 0 }); // rotation matrices do not commute in multiplication, and the rotation around x->y->z order means z->y->x matrices order

/* Euler rotation to matrix */
    glm::mat3 matrix3x3_from_euler = glm::eulerAngleXYZ(0.0f, 0.0f, 0.0f); // rotation order is z axis -> y axis -> x axis, the equal matirces multiplication order is x->y->z

    glm::mat3 matrix4x4_from_euler = glm::eulerAngleZYX(0.0f, 0.0f, 0.0f); // rotation order is x axis -> y axis -> z axis, the equal matirces multiplication order is z->y->x

/* Euler rotation to quaternion */
    float euler_x, euler_y, euler_z; // radians
    euler_x = euler_y = euler_z = 0.0f;
    glm::quat quaternion_from_euler{ glm::vec3{euler_x, euler_y, euler_z} }; // the original rotation order is x axis ->  y axis -> z axis, matrices multip

 

Transform using the glm library

原文:https://www.cnblogs.com/wangpei0522/p/12894752.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!