25 const float sin_a =
sin(aa.
angle / 2);
26 const float cos_a =
cos(aa.
angle / 2);
37 const auto cy =
cos(yaw * 0.5);
38 const auto sy =
sin(yaw * 0.5);
39 const auto cp =
cos(pitch * 0.5);
40 const auto sp =
sin(pitch * 0.5);
41 const auto cr =
cos(roll * 0.5);
42 const auto sr =
sin(roll * 0.5);
46 cr * cp * cy + sr * sp * sy,
48 sr * cp * cy - cr * sp * sy,
49 cr * sp * cy + sr * cp * sy,
50 cr * cp * sy - sr * sp * cy
84 const float cos_a =
w;
85 const auto angle =
acos(cos_a) * 2;
86 const auto sin_a = get_default_if_close_to_zero<float>(
87 sqrt(1.0f - cos_a * cos_a), 1, 0.0005f);
155 return x *
x +
y *
y +
z *
z +
w *
w;
206 const quatf pure = {0, v};
207 const quatf a = *
this * pure;
216 return f * (1 - scale) + t * scale;
226 const float cos_half_theta = qa.
w * qb.
w + qa.
x * qb.
x + qa.
y * qb.
y + qa.
z * qb.
z;
228 if(
abs(cos_half_theta) >= 1.0f)
233 const auto half_theta =
acos(cos_half_theta);
234 const auto sin_half_theta =
sqrt(1.0f - cos_half_theta * cos_half_theta);
235 if(
abs(sin_half_theta) < 0.001f)
239 const quatf qt = qa + qb;
251 const float ratio_a =
sin((1 - t) * half_theta) / sin_half_theta;
252 const float ratio_b =
sin(t * half_theta) / sin_half_theta;
253 return qa * ratio_a + qb * ratio_b;
260 if(
dot(from, to) < 0)
304 #define VAR(a, b) const float a##1##b##2 = a * rhs.b
326 w = w1w2 - x1x2 - y1y2 - z1z2;
327 x = w1x2 + x1w2 + y1z2 - z1y2;
328 y = w1y2 + y1w2 + z1x2 - x1z2;
329 z = w1z2 + z1w2 + x1y2 - y1x2;
335 float dot_value =
in.
dot(dir);
337 if (
abs(dot_value - (-1.0f)) < 0.000001f)
340 return {3.1415926535897932f, up};
342 if (
abs(dot_value - (1.0f)) < 0.000001f)
347 const auto rot_angle =
acos(dot_value);
358 return fmt::format(
"({} ({}, {}, {}))", v.w, v.x, v.y, v.z);
365 return lhs.
x * rhs.
x + lhs.
y * rhs.
y + lhs.
z * rhs.
z + lhs.
w * rhs.
w;
Angle operator+(const Angle &lhs, const Angle &rhs)
constexpr quatf q_identity
Angle operator-(const Angle &lhs, const Angle &rhs)
quatf slerp_fast(const quatf &qa, const float t, const quatf &qb)
constexpr float abs(float r)
quatf lerp_quatf(const quatf &f, const float scale, const quatf &t)
std::string to_string(const Aabb &a)
bool is_equal(int lhs, int rhs)
unit3f get_random_unit3(Random *random)
float cos(const Angle &ang)
quatf slerp_shortway(const quatf &from, const float scale, const quatf &to)
Angle get_random_angle(::eu::Random *random)
float sin(const Angle &ang)
Angle operator*(const Angle &lhs, float rhs)
float dot(const quatf &lhs, const quatf &rhs)
Angle angle
rotation according to right-hand rule
static AxisAngle from_right_hand_around(const unit3f &axis, const Angle &angle)
WEL512 Random Number Generator.
static mat4f from_axis_angle(const AxisAngle &aa)
static quatf look_in_direction(const unit3f &dir, const unit3f &up)
AxisAngle to_axis_angle() const
quatf get_conjugate() const
float get_length_squared() const
static quatf from_random(Random *random)
quatf get_identity() const
static quatf from_to(const quatf &from, const quatf &to)
static quatf from_axis_angle(const AxisAngle &aa)
void operator-=(const quatf &rhs)
vec3f get_vec_part() const
unit3f rotate_around_origo(const unit3f &v) const
quatf get_normalized() const
quatf get_negated() const
void operator*=(float rhs)
static quatf from_ypr(const Angle &yaw, const Angle &pitch, const Angle &roll)
vec3f create_from_right_up_in(const vec3f &v) const
returns In*Z + Right*X + Up*Y
quatf get_rotated(const quatf &q) const
void operator+=(const quatf &rhs)
static quatf look_at(const vec3f &from, const vec3f &to, const unit3f &up)
quatf get_inverse() const
unit3f get_normalized() const
vec3f cross(const vec3f &u) const
static vec3f from_to(const vec3f &from, const vec3f &to)
float dot(const vec3f &rhs) const