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); }...