zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    安装win7和ubuntu双系统
    Jenkins的2个问题
    junit里面Test Case的执行顺序
    使用Array类处理基本数组对象
    Location对象的页面跳转方法介绍
    Javascript几种创建对象的方法
    For循环重复代码的重构
    Sonar在ant工程中读取单元测试和覆盖率报告
    Jenkins无法读取覆盖率报告的解决方法
    python之路-day08-文件操作
  • 原文地址:https://www.cnblogs.com/wangpei0522/p/12894752.html
Copyright © 2011-2022 走看看