#pragma once #include namespace LinearAlgebra { class Quaternion { public: Quaternion(); Quaternion(const Quaternion& rhs) = default; explicit Quaternion(const Matrix3x3& rotationMtrx); explicit Quaternion(const Matrix4x4& rotationMtrx); // @note The input data is not normalized after construction, this has to be done manually. Quaternion(float x, float y, float z, float w); // Constructs this quaternion by specifying a rotation axis and the amount of rotation to be performed about that axis // @param rotationAxis The normalized rotation axis to rotate about. If using Vector4 version of the constructor, the w component of this vector must be 0. Quaternion(const Vector3& rotationAxis, float rotationAngleBetween) { SetFromAxisAngle(rotationAxis, rotationAngleBetween); } Quaternion(const Vector4& rotationAxis, float rotationAngleBetween) { SetFromAxisAngle(rotationAxis, rotationAngleBetween); } //void Inverse(); Quaternion Inverse() const; //void Normalize(); Quaternion Normalize() const; Vector3 GetWorldX() const; Vector3 GetWorldY() const; Vector3 GetWorldZ() const; Matrix3x3 ToMatrix3x3() const; Vector3 Transform(const Vector3& vec) const; Vector3 Transform(float X, float Y, float Z) const; // Note: We only transform the x,y,z components of 4D vectors, w is left untouched Vector4 Transform(const Vector4& vec) const; Vector4 Transform(float X, float Y, float Z, float W) const; Quaternion GetInverse() const; Quaternion Lerp(const Quaternion& b, float t) const; Quaternion Slerp(const Quaternion& target) const; void SetFromAxisAngle(const Vector3& axis, float angle); void SetFromAxisAngle(const Vector4& axis, float angle) { } static Quaternion LookAt(const Vector3& position, const Vector3& direction, const Vector3& axisUp); // Multiplies two quaternions together. // The product q1 * q2 returns a quaternion that concatenates the two orientation rotations. // The rotation q2 is applied first before q1. Quaternion operator * (const Quaternion& rhs) const; Quaternion operator * (float scalar) const; // Transforms the given vector by this Quaternion. Vector3 operator * (const Vector3& rhs) const; Vector4 operator * (const Vector4& rhs) const; // Divides a quaternion by another. Divison "a / b" results in a quaternion that rotates the orientation b to coincide with orientation of Quaternion operator / (const Quaternion& rhs) const; Quaternion operator +(const Quaternion& rhs) const; Quaternion operator +() const; Quaternion operator -() const; public: float x = 0; float y = 0; float z = 0; float w = 0; }; }