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

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.

主站蜘蛛池模板: 河北省| 石棉县| 临湘市| 元朗区| 灵武市| 开封市| 柯坪县| 江山市| 喜德县| 壤塘县| 锡林浩特市| 云阳县| 岐山县| 大荔县| 亚东县| 陆丰市| 句容市| 高碑店市| 彭水| 察隅县| 大冶市| 南宫市| 涡阳县| 马边| 阿合奇县| 财经| 荔浦县| 西畴县| 蓬溪县| 湘潭县| 吴江市| 民县| 仙游县| 沂南县| 永靖县| 邹平县| 乌苏市| 高密市| 镇平县| 蚌埠市| 荃湾区|