diff --git a/Engine/Source/Runtime/Core/Math/Quaternion.hpp b/Engine/Source/Runtime/Core/Math/Quaternion.hpp new file mode 100644 index 0000000..d1200b2 --- /dev/null +++ b/Engine/Source/Runtime/Core/Math/Quaternion.hpp @@ -0,0 +1,85 @@ +#pragma once + +#include "Core/Math/Boilerplate.h" + +#include "Core/Math/MathFwd.h" +#include "Core/Math/SIMD/PhanesSIMDTypes.h" +#include "Core/Math/SIMD/Storage.h" +#include "Core/Math/Vector3.hpp" +#include "Core/Math/Vector4.hpp" + +#ifndef QUATERNION_H +# define QUATERNION_H + +namespace Phanes::Core::Math +{ + // Quaternion + template + struct TQuaternion + { + using Real = T; + + public: + union + { + struct + { + float x; + float y; + float z; + float w; + }; + union + { + typename SIMD::Storage<4, Real, SIMD::use_simd::value>::type comp; + typename SIMD::Storage<4, Real, SIMD::use_simd::value>::type data; + }; + }; + + public: + /// Default constructor + TQuaternion() = default; + + /** + * Construct quaternion from vector4. + * v.w is the scalar part of the quaternion (q.w). + */ + explicit TQuaternion(const TVector4& v); + + /** + * Construct quaternion from vector (x,y,z) and scalar part (w). + * + * @param x X + * @param y Y + * @param z Z + * @param w W + */ + TQuaternion(Real x, Real y, Real z, Real w); + + /** + * Construct vector from vector part and scalar part. + */ + TQuaternion(const TVector3& v, Real w); + + /** + * Construct quaternion from array of length >= four. + * + * @note If used with SIMD the array will is assumed to be aligned. + */ + explicit TQuaternion(const Real* comp); + + /** + * Construct from euler angles (yaw, pitch, roll) + */ + explicit TQuaternion(const TVector3& euler_angels); + + /** + * Construct from Transformation + */ + + explicit TQuaternion(const TTransform& t); + explicit TQuaternion(const TMatrix4& t); + }; +} // namespace Phanes::Core::Math + +#endif // QUATERNION_H