16 const auto roll = euler_angles.
data.at(0);
17 const auto pitch = euler_angles.
data.at(1);
18 const auto yaw = euler_angles.
data.at(2);
20 const auto cr = std::cos(roll * 0.5f);
21 const auto sr = std::sin(roll * 0.5f);
22 const auto cp = std::cos(pitch * 0.5f);
23 const auto sp = std::sin(pitch * 0.5f);
24 const auto cy = std::cos(yaw * 0.5f);
25 const auto sy = std::sin(yaw * 0.5f);
27 data.
at(0) = sr * cp * cy - cr * sp * sy;
28 data.
at(1) = cr * sp * cy + sr * cp * sy;
29 data.
at(2) = cr * cp * sy - sr * sp * cy;
30 data.
at(3) = cr * cp * cy + sr * sp * sy;
33 [[nodiscard]]
auto x()
const {
return data.
at(0); }
35 [[nodiscard]]
auto y()
const {
return data.
at(1); }
36 [[nodiscard]]
auto z()
const {
return data.
at(2); }
37 [[nodiscard]]
auto w()
const {
return data.
at(3); }
44 const auto w = vec.at(3);
45 const auto x = vec.at(0);
46 const auto y = vec.at(1);
47 const auto z = vec.at(2);
49 const auto xx =
x *
x;
50 const auto yy =
y *
y;
51 const auto zz =
z *
z;
54 result.at(0, 0) = 1 - 2 * (yy + zz);
55 result.at(1, 0) = 2 * (
x *
y +
w *
z);
56 result.at(2, 0) = 2 * (
x *
z -
w *
y);
58 result.at(0, 1) = 2 * (
x *
y -
w *
z);
59 result.at(1, 1) = 1 - 2 * (xx + zz);
60 result.at(2, 1) = 2 * (
y *
z +
w *
x);
62 result.at(0, 2) = 2 * (
x *
z +
w *
y);
63 result.at(1, 2) = 2 * (
y *
z -
w *
x);
64 result.at(2, 2) = 1 - 2 * (xx + yy);
static constexpr auto identity()
Definition matrix.hpp:18
Definition geometry.hpp:8
Definition quaternion.hpp:9
Quaternion(Vec< T, 3 > euler_angles)
Definition quaternion.hpp:15
static auto identity()
Definition quaternion.hpp:10
Quaternion()
Definition quaternion.hpp:12
auto normalized() const
Definition quaternion.hpp:40
auto w() const
Definition quaternion.hpp:37
auto normalize()
Definition quaternion.hpp:39
auto to_mat()
Definition quaternion.hpp:42
Quaternion(T x, T y, T z, T w)
Definition quaternion.hpp:13
auto x(T x)
Definition quaternion.hpp:34
auto y() const
Definition quaternion.hpp:35
auto z() const
Definition quaternion.hpp:36
Vec< T, 4 > data
Definition quaternion.hpp:69
auto x() const
Definition quaternion.hpp:33
std::array< T, N > data
Definition vector.hpp:112
auto normalized() const
Definition vector.hpp:110
auto at(std::size_t i) -> T &
Definition vector.hpp:28