Vector3 Quaternion_multiplyVector3(Quaternion quaternion, Vector3 vector) { Quaternion vectorQuaternion, inverseQuaternion, result; vectorQuaternion = Quaternion_fromVector(vector); inverseQuaternion = Quaternion_inverted(quaternion); result = Quaternion_multiplied(quaternion, Quaternion_multiplied(vectorQuaternion, inverseQuaternion)); return Quaternion_toVector(result); }
void Quaternion_multiply(Quaternion * quaternion1, Quaternion quaternion2) { Vector3 vector1, vector2, cross; float angle; vector1 = Quaternion_toVector(*quaternion1); vector2 = Quaternion_toVector(quaternion2); angle = (quaternion1->w * quaternion2.w) - Vector3_dot(vector1, vector2); cross = Vector3_cross(vector1, vector2); vector1.x *= quaternion2.w; vector1.y *= quaternion2.w; vector1.z *= quaternion2.w; vector2.x *= quaternion1->w; vector2.y *= quaternion1->w; vector2.z *= quaternion1->w; quaternion1->x = vector1.x + vector2.x + cross.x; quaternion1->y = vector1.y + vector2.y + cross.y; quaternion1->z = vector1.z + vector2.z + cross.z; quaternion1->w = angle; }
void Quaternion_multiply(Quaternion * quaternion1, Quaternion quaternion2) { vect3D vector1, vector2, cross; int32 angle; vector1 = Quaternion_toVector(*quaternion1); vector2 = Quaternion_toVector(quaternion2); angle = mulf32(quaternion1->w, quaternion2.w) - dotProduct(vector1, vector2); cross = vectProduct(vector1, vector2); vector1.x = mulf32(vector1.x, quaternion2.w); vector1.y = mulf32(vector1.y, quaternion2.w); vector1.z = mulf32(vector1.z, quaternion2.w); vector2.x = mulf32(vector2.x, quaternion1->w); vector2.y = mulf32(vector2.y, quaternion1->w); vector2.z = mulf32(vector2.z, quaternion1->w); quaternion1->x = vector1.x + vector2.x + cross.x; quaternion1->y = vector1.y + vector2.y + cross.y; quaternion1->z = vector1.z + vector2.z + cross.z; quaternion1->w = angle; }