Bug 1304886 - Part 7: Add mulitiplications for quaternions. r?boris, derf draft
 author Hiroyuki Ikezoe Wed, 16 Nov 2016 16:08:42 +0900 changeset 439592 73baf09ca4d87d05d96d61615a3a282f6fc2468c parent 439591 b01db0833a12235ab817f75e5bb28cb51012e728 child 439593 e7812dea7f984a2cd16de46e90b8e5ee4dcd01ae push id 36056 push user hiikezoe@mozilla-japan.org push date Wed, 16 Nov 2016 11:13:11 +0000 reviewers boris, derf bugs 1304886 milestone 53.0a1
Bug 1304886 - Part 7: Add mulitiplications for quaternions. r?boris, derf MozReview-Commit-ID: IZDnU26wj2Y
```--- a/gfx/thebes/gfxQuaternion.h
+++ b/gfx/thebes/gfxQuaternion.h
@@ -67,16 +67,39 @@ struct gfxQuaternion : public mozilla::g
gfxQuaternion right = aOther;

left *= cos(aCoeff*theta) - dot*rightWeight;
right *= rightWeight;

return left + right;
}

+    using Super::operator*=;
+
+    // Quaternion multiplication
+    // Reference:
+    // https://en.wikipedia.org/wiki/Quaternion#Ordered_list_form
+    //
+    // (w1, x1, y1, z1)(w2, x2, y2, z2) = (w1w2 - x1x2 - y1y2 - z1z2,
+    //                                     w1x2 + x1w2 + y1z2 - z1y2,
+    //                                     w1y2 - x1z2 + y1w2 + z1x2,
+    //                                     w1z2 + x1y2 - y1x2 + z1w2)
+    gfxQuaternion operator*(const gfxQuaternion& aOther) const {
+        return gfxQuaternion(
+          w * aOther.x + x * aOther.w + y * aOther.z - z * aOther.y,
+          w * aOther.y - x * aOther.z + y * aOther.w + z * aOther.x,
+          w * aOther.z + x * aOther.y - y * aOther.x + z * aOther.w,
+          w * aOther.w - x * aOther.x - y * aOther.y - z * aOther.z
+        );
+    }
+    gfxQuaternion& operator*=(const gfxQuaternion& aOther) {
+        *this = *this * aOther;
+        return *this;
+    }
+
mozilla::gfx::Matrix4x4 ToMatrix() const {
mozilla::gfx::Matrix4x4 temp;

temp[0][0] = 1 - 2 * (y * y + z * z);
temp[0][1] = 2 * (x * y + w * z);
temp[0][2] = 2 * (x * z - w * y);
temp[1][0] = 2 * (x * y - w * z);
temp[1][1] = 1 - 2 * (x * x + z * z);```