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

Common quaternion operations

Like vectors, quaternions also have component-wise operations. Common

component-wise operations are adding, subtracting, multiplying, or negating

quaternions. Component-wise quaternion multiplication multiplies a quaternion

by a single scalar value.

Since these functions are component-wise, they just perform the appropriate action on similar components of the input quaternions. Implement these functions in quat.cpp and add declarations for each function in quat.h:

quat operator+(const quat& a, const quat& b) {

    return quat(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w);

}

quat operator-(const quat& a, const quat& b) {

    return quat(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w);

}

quat operator*(const quat& a, float b) {

    return quat(a.x * b, a.y * b, a.z * b, a.w * b);

}

quat operator-(const quat& q) {

    return quat(-q.x, -q.y, -q.z, -q.w);

}

These component-wise operations don't have much practical use by themselves. They are the building blocks for building the rest of the quaternion functionality on. Next, you're going to learn about the different ways to compare quaternions.

主站蜘蛛池模板: 渭南市| 嵊州市| 沂源县| 信阳市| 灌云县| 建平县| 手游| 久治县| 赫章县| 安徽省| 长白| 永川市| 泰州市| 华宁县| 南充市| 五原县| 福海县| 灯塔市| 大姚县| 霍山县| 峨眉山市| 来安县| 那坡县| 玉龙| 五原县| 沈阳市| 桃源县| 游戏| 灵石县| 宜章县| 海丰县| 黄平县| 莲花县| 枣阳市| 宁阳县| 南安市| 大渡口区| 丹凤县| 江口县| 吴旗县| 屏山县|