14 constexpr Quatf() :
w(std::numeric_limits<f32>::signaling_NaN()) {}
38 return *
this = *
this + rhs;
48 return Quatf(
w * scalar,
v * scalar);
52 return *
this = *
this * scalar;
63 return Quatf(_w, _x, _y, _z);
67 return *
this = *
this * q;
71 return w == rhs.
w &&
v == rhs.
v;
75 return !(*
this == rhs);
79 [[nodiscard]]
explicit operator std::string()
const {
80 return std::format(
"[0x{:08X}, 0x{:08X}, 0x{:08X}, 0x{:08X}] | [{}, {}, {}, {}]", f2u(
v.
x),
92 const f32 cy = Mathf::cos(y * 0.5f);
93 const f32 cp = Mathf::cos(p * 0.5f);
94 const f32 cr = Mathf::cos(r * 0.5f);
95 const f32 sy = Mathf::sin(y * 0.5f);
96 const f32 sp = Mathf::sin(p * 0.5f);
97 const f32 sr = Mathf::sin(r * 0.5f);
99 w = cy * cp * cr + sy * sp * sr;
100 v.
x = cy * cp * sr - sy * sp * cr;
101 v.
y = cy * sp * cr + sy * cp * sr;
102 v.
z = sy * cp * cr - cy * sp * sr;
111 f32 inv = 1.0f / len;
120 f32 t0 = std::max(0.0f, (from.
dot(to) + 1) * 2.0f);
121 t0 = Mathf::sqrt(t0);
123 if (t0 <= std::numeric_limits<f32>::epsilon()) {
126 const f32 inv = 1.0f / t0;
141 Quatf res = *
this * vec;
144 ret.
v.
x = (res.
v.
y * conj.
v.
z + (res.
v.
x * conj.
w + res.
w * conj.
v.
x)) - res.
v.
z * conj.
v.
y;
145 ret.
v.
y = (res.
v.
z * conj.
v.
x + (res.
v.
y * conj.
w + res.
w * conj.
v.
y)) - res.
v.
x * conj.
v.
z;
146 ret.
v.
z = (res.
v.
x * conj.
v.
y + (res.
v.
z * conj.
w + res.
w * conj.
v.
z)) - res.
v.
y * conj.
v.
x;
155 Quatf res = conj * vec;
169 f32 dot_ = std::clamp(
dot(q1), -1.0f, 1.0f);
170 bool bDot = dot_ < 0.0f;
171 dot_ = Mathf::abs(dot_);
173 f32 acos = Mathf::acos(dot_);
174 f32 sin = Mathf::sin(acos);
177 if (Mathf::abs(sin) < 0.00001f) {
180 f32 invSin = 1.0f / sin;
182 s = invSin * Mathf::sin(acos - tmp0);
183 t = invSin * Mathf::sin(tmp0);
190 return Quatf(s *
w + t * q1.
w, s *
v + t * q1.
v);
212 const f32 half_angle = angle * 0.5f;
213 const f32 c = Mathf::cos(half_angle);
214 const f32 s = Mathf::sin(half_angle);
226 return Quatf(_w, _x, _y, _z);
235 return Quatf(_w, _x, _y, _z);
A stream of data, abstracted to allow for continuous seeking.
A quaternion, used to represent 3D rotation.
constexpr Quatf & operator=(const Quatf &q)
constexpr void setRPY(f32 r, f32 p, f32 y)
Helper function to avoid unnecessary Vector3f construction.
void read(Stream &stream)
constexpr f32 norm() const
constexpr bool operator==(const Quatf &rhs) const
constexpr f32 dot(const Quatf &q) const
Computes .
constexpr void setAxisRotation(f32 angle, const EGG::Vector3f &axis)
Set the quat given angle and axis.
constexpr void makeVectorRotation(const Vector3f &from, const Vector3f &to)
Captures rotation between two vectors.
constexpr void normalise()
Scales the quaternion to a unit length.
constexpr Quatf operator+(const Quatf &rhs) const
constexpr Quatf operator*(const Quatf &rhs) const
constexpr Quatf & operator*=(const Quatf &q)
constexpr Vector3f rotateVector(const Vector3f &vec) const
Rotates a vector based on the quat.
static constexpr Quatf FromRPY(const EGG::Vector3f &rpy)
constexpr void setRPY(const Vector3f &rpy)
Sets roll, pitch, and yaw.
constexpr ~Quatf()=default
constexpr Quatf(f32 w_, const Vector3f &v_)
constexpr f32 squaredNorm() const
Computes .
constexpr Quatf multSwap(const Vector3f &vec) const
constexpr Quatf slerpTo(const Quatf &q1, f32 t) const
Performs spherical linear interpolation.
constexpr Quatf & operator+=(const Quatf &rhs)
constexpr Quatf multSwap(const Quatf &q) const
constexpr bool operator!=(const Quatf &rhs) const
constexpr Vector3f rotateVectorInv(const Vector3f &vec) const
Rotates a vector on the inverse quat.
constexpr Quatf(f32 w_, f32 x_, f32 y_, f32 z_)
static constexpr Quatf FromRPY(f32 r, f32 p, f32 y)
Helper function to avoid unnecessary Vector3f construction.
constexpr Quatf operator*(f32 scalar) const
constexpr Quatf operator*(const Vector3f &vec) const
constexpr Quatf()=default
constexpr Quatf & operator*=(f32 scalar)
constexpr Quatf conjugate() const
Computes .
constexpr Quatf(const Quatf &q)=default
constexpr f32 squaredLength() const
The dot product between the vector and itself.
void read(Stream &stream)
Initializes a Vector3f by reading 12 bytes from the stream.
static const Vector3f zero
constexpr f32 dot(const Vector3f &rhs) const
The dot product between two vectors.
constexpr Vector3f cross(const Vector3f &rhs) const