• Transform using the glm library


    // 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
  • 相关阅读:
    ReentrantLock重入锁
    Java对象序列化和反序列
    echarts踩坑笔记
    金融风控之贷款违约预测笔记
    go安装模块
    vasp计算轨道吸附
    html
    css/js 小技巧
    python 调用父类方法:super && 直接使用父类名
    python 多线程
  • 原文地址:https://www.cnblogs.com/wangpei0522/p/12894752.html
Copyright © 2020-2023  润新知