官术网_书友最值得收藏!

Conjugate and inverse

Games mostly use normalized quaternions, which comes in handy when inverting quaternions. The inverse of a normalized quaternion is its conjugate. The conjugate

of a quaternion flips its axis of rotation:

  1. Implement the conjugate function in quat.cpp and remember to declare the function in quat.h:

    quat conjugate(const quat& q) {

        return quat(

            -q.x,

            -q.y,

            -q.z,

             q.w

        );

    }

  2. The proper inverse of a quaternion is the conjugate divided by the squared length of the quaternion. Implement the quaternion inverse function in quat.cpp. Add the function declaration to quat.h:

    quat inverse(const quat& q) {

       float lenSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;

       if (lenSq < QUAT_EPSILON) {

          return quat();

       }

       float recip = 1.0f / lenSq;

       return quat(-q.x * recip,

                   -q.y * recip,

                   -q.z * recip,

                    q.w * recip

       );

    }

If you need to find out whether a quaternion is normalized or not, check the squared length. The squared length of a normalized quaternion is always 1. If a quaternion is normalized, its conjugate and inverse are the same. This means you can use the faster conjugate function, instead of the inverse function. In the next section, you will learn how to multiply two quaternions together.

主站蜘蛛池模板: 威远县| 信阳市| 江口县| 东乌珠穆沁旗| 拉萨市| 柳林县| 康保县| 梁河县| 永福县| 嘉兴市| 阳城县| 拉孜县| 自贡市| 苗栗县| 札达县| 松滋市| 安平县| 云龙县| 齐齐哈尔市| 富平县| 剑阁县| 安义县| 田阳县| 伽师县| 修武县| 商南县| 泉州市| 南昌市| 景宁| 大洼县| 桃园市| 台北市| 南岸区| 怀远县| 迁西县| 信丰县| 昔阳县| 西宁市| 永吉县| 繁峙县| 深泽县|