9 #ifndef TurtleBrains_MatrixQuaternion_hpp
10 #define TurtleBrains_MatrixQuaternion_hpp
12 #include <turtle_brains/math/tb_matrix.hpp>
13 #include <turtle_brains/math/tb_quaternion.hpp>
25 if (matrix(2, 2) < 0.0f)
27 if (matrix(0, 0) > matrix(1, 1))
29 const float t = (1.0f + matrix(0, 0) - matrix(1, 1) - matrix(2, 2));
30 Quaternion q(t, matrix(1, 0) + matrix(0, 1), matrix(0, 2) + matrix(2, 0), matrix(2, 1) - matrix(1, 2));
31 q *= (0.5f / sqrt(t));
36 const float t = (1.0f - matrix(0, 0) + matrix(1, 1) - matrix(2, 2));
37 Quaternion q(matrix(1, 0) + matrix(0, 1), t, matrix(2, 1) + matrix(1, 2), matrix(0, 2) - matrix(2, 0));
38 q *= (0.5f / sqrt(t));
44 if (matrix(0, 0) < -matrix(1, 1))
46 const float t = (1.0f - matrix(0, 0) - matrix(1, 1) + matrix(2, 2));
47 Quaternion q(matrix(0, 2) + matrix(2, 0), matrix(2, 1) + matrix(1, 2), t, matrix(1, 0) - matrix(0, 1));
48 q *= (0.5f / sqrt(t));
53 const float t = (1.0f + matrix(0, 0) + matrix(1, 1) + matrix(2, 2));
54 Quaternion q(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1), t);
55 q *= (0.5f / sqrt(t));
63 if (matrix(2, 2) < 0.0f)
65 if (matrix(0, 0) > matrix(1, 1))
67 const float t = (1.0f + matrix(0, 0) - matrix(1, 1) - matrix(2, 2));
68 Quaternion q(t, matrix(1, 0) + matrix(0, 1), matrix(0, 2) + matrix(2, 0), matrix(2, 1) - matrix(1, 2));
74 const float t = (1.0f - matrix(0, 0) + matrix(1, 1) - matrix(2, 2));
75 Quaternion q(matrix(1, 0) + matrix(0, 1), t, matrix(2, 1) + matrix(1, 2), matrix(0, 2) - matrix(2, 0));
82 if (matrix(0, 0) < -matrix(1, 1))
84 const float t = (1.0f - matrix(0, 0) - matrix(1, 1) + matrix(2, 2));
85 Quaternion q(matrix(0, 2) + matrix(2, 0), matrix(2, 1) + matrix(1, 2), t, matrix(1, 0) - matrix(0, 1));
91 const float t = (1.0f + matrix(0, 0) + matrix(1, 1) + matrix(2, 2));
92 Quaternion q(matrix(2, 1) - matrix(1, 2), matrix(0, 2) - matrix(2, 0), matrix(1, 0) - matrix(0, 1), t);
101 const float& qx(quaternion.x);
102 const float& qy(quaternion.y);
103 const float& qz(quaternion.z);
104 const float& qw(quaternion.w);
106 const float qxSq(quaternion.x * quaternion.x);
107 const float qySq(quaternion.y * quaternion.y);
108 const float qzSq(quaternion.z * quaternion.z);
113 1.0f - 2.0f * qySq - 2.0f * qzSq, 2.0f * qx * qy - 2.0f * qz * qw, 2.0f * qx * qz + 2.0f * qy * qw,
114 2.0f * qx * qy + 2.0f * qz * qw, 1.0f - 2.0f * qxSq - 2.0f * qzSq, 2.0f * qy * qz - 2.0f * qx * qw,
115 2.0f * qx * qz - 2.0f * qy * qw, 2.0f * qy * qz + 2.0f * qx * qw, 1.0f - 2.0f * qxSq - 2.0f * qySq);
128 const float& qx(quaternion.x);
129 const float& qy(quaternion.y);
130 const float& qz(quaternion.z);
131 const float& qw(quaternion.w);
133 const float qxSq(quaternion.x * quaternion.x);
134 const float qySq(quaternion.y * quaternion.y);
135 const float qzSq(quaternion.z * quaternion.z);
140 1.0f - 2.0f * qySq - 2.0f * qzSq, 2.0f * qx * qy + 2.0f * qz * qw, 2.0f * qx * qz - 2.0f * qy * qw, 0.0f,
141 2.0f * qx * qy - 2.0f * qz * qw, 1.0f - 2.0f * qxSq - 2.0f * qzSq, 2.0f * qy * qz + 2.0f * qx * qw, 0.0f,
142 2.0f * qx * qz + 2.0f * qy * qw, 2.0f * qy * qz - 2.0f * qx * qw, 1.0f - 2.0f * qxSq - 2.0f * qySq, 0.0f,
143 translation.x, translation.y, translation.z, 1.0f);
Definition: tb_vector.hpp:317
Definition: tb_matrix.hpp:111
Definition: tb_quaternion.hpp:38
Definition: tb_matrix.hpp:527
Quaternion(void)
Definition: tb_quaternion.hpp:74