|
|
@@ -6,8 +6,6 @@
|
|
|
#pragma once
|
|
|
|
|
|
#include "math_types.h"
|
|
|
-#include "vector3.h"
|
|
|
-#include "quaternion.h"
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
@@ -235,83 +233,6 @@ inline void set_identity(Matrix3x3& m)
|
|
|
m.z.z = 1.0f;
|
|
|
}
|
|
|
|
|
|
-/// Returns the rotation portion of the matrix @a m as a Quaternion.
|
|
|
-inline Quaternion rotation(const Matrix3x3& m)
|
|
|
-{
|
|
|
- const float ww = m.x.x + m.y.y + m.z.z;
|
|
|
- const float xx = m.x.x - m.y.y - m.z.z;
|
|
|
- const float yy = m.y.y - m.x.x - m.z.z;
|
|
|
- const float zz = m.z.z - m.x.x - m.y.y;
|
|
|
- float max = ww;
|
|
|
- uint32_t index = 0;
|
|
|
-
|
|
|
- if (xx > max)
|
|
|
- {
|
|
|
- max = xx;
|
|
|
- index = 1;
|
|
|
- }
|
|
|
-
|
|
|
- if (yy > max)
|
|
|
- {
|
|
|
- max = yy;
|
|
|
- index = 2;
|
|
|
- }
|
|
|
-
|
|
|
- if (zz > max)
|
|
|
- {
|
|
|
- max = zz;
|
|
|
- index = 3;
|
|
|
- }
|
|
|
-
|
|
|
- const float biggest = sqrtf(max + 1.0f) * 0.5f;
|
|
|
- const float mult = 0.25f / biggest;
|
|
|
-
|
|
|
- Quaternion tmp;
|
|
|
- switch (index)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- tmp.w = biggest;
|
|
|
- tmp.x = (m.y.z - m.z.y) * mult;
|
|
|
- tmp.y = (m.z.x - m.x.z) * mult;
|
|
|
- tmp.z = (m.x.y - m.y.x) * mult;
|
|
|
- break;
|
|
|
- }
|
|
|
- case 1:
|
|
|
- {
|
|
|
- tmp.x = biggest;
|
|
|
- tmp.w = (m.y.z - m.z.y) * mult;
|
|
|
- tmp.y = (m.x.y + m.y.x) * mult;
|
|
|
- tmp.z = (m.z.x + m.x.z) * mult;
|
|
|
- break;
|
|
|
- }
|
|
|
- case 2:
|
|
|
- {
|
|
|
- tmp.y = biggest;
|
|
|
- tmp.w = (m.z.x - m.x.z) * mult;
|
|
|
- tmp.x = (m.x.y + m.y.x) * mult;
|
|
|
- tmp.z = (m.y.z + m.z.y) * mult;
|
|
|
- break;
|
|
|
- }
|
|
|
- case 3:
|
|
|
- {
|
|
|
- tmp.z = biggest;
|
|
|
- tmp.w = (m.x.y - m.y.x) * mult;
|
|
|
- tmp.x = (m.z.x + m.x.z) * mult;
|
|
|
- tmp.y = (m.y.z + m.z.y) * mult;
|
|
|
- break;
|
|
|
- }
|
|
|
- default:
|
|
|
- {
|
|
|
- CE_FATAL("You should not be here");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- normalize(tmp);
|
|
|
- return tmp;
|
|
|
-}
|
|
|
-
|
|
|
/// Returns the scale of the matrix @a m.
|
|
|
inline Vector3 scale(const Matrix3x3& m)
|
|
|
{
|