#pragma once
#include <math.h>
#include "VectorFloat.h"
#include "OAGMatrix4x4.h"
#include "..\..\OpenGL\include\rglModel\aiQuaternion.h"
// ----------------------------------------------------------------------------------------
inline void Matrix4x4Decompose (const oag::Matrix4x4& matSource, oag::CVectorFloat& scaling, aiQuaternion& rotation,
oag::CVectorFloat& position)
{
//const oag::Matrix4x4& _this = *this;
// extract translation
//position.x = _this[0][3];
//position.y = _this[1][3];
//position.z = _this[2][3];
//// extract the rows of the matrix
//aiVector3D vRows[3] = {
// aiVector3D(_this[0][0],_this[1][0],_this[2][0]),
// aiVector3D(_this[0][1],_this[1][1],_this[2][1]),
// aiVector3D(_this[0][2],_this[1][2],_this[2][2])
//};
//// extract the scaling factors
//scaling.x = vRows[0].Length();
//scaling.y = vRows[1].Length();
//scaling.z = vRows[2].Length();
//// and remove all scaling from the matrix
//if(scaling.x)
//{
// vRows[0] /= scaling.x;
//}
//if(scaling.y)
//{
// vRows[1] /= scaling.y;
//}
//if(scaling.z)
//{
// vRows[2] /= scaling.z;
//}
//// build a 3x3 rotation matrix
//aiMatrix3x3 m(vRows[0].x,vRows[1].x,vRows[2].x,
// vRows[0].y,vRows[1].y,vRows[2].y,
// vRows[0].z,vRows[1].z,vRows[2].z);
//// and generate the rotation quaternion from it
//rotation = aiQuaternion(m);
}
inline oag::Matrix4x4 RotationZ(float a, oag::Matrix4x4& out)
{
/*
| cos(A) -sin(A) 0 0 |
M = | sin(A) cos(A) 0 0 |
| 0 0 1 0 |
| 0 0 0 1 | */
oag::Matrix4x4 localMat;
out = localMat;
out.MakeIdentity();
out.m00 = out.m11 = cos(a); //out.a1 = out.b2 = cos(a);
out.m01 = -(out.m10 = sin(a) ); //out.a2 = -(out.b1 = sin(a));
return out;
}
/** Transformation of a vector by a 3x3 matrix */
inline oag::CVectorFloat MultiplyMatrix3x3ByVector(const oag::Matrix3x3& pMatrix, const oag::CVectorFloat& pVector)
{
oag::CVectorFloat res;
res.m_X = (pMatrix.m00 * pVector.m_X) + (pMatrix.m01 * pVector.m_Y) + (pMatrix.m02 * pVector.m_Z);
res.m_Y = (pMatrix.m10 * pVector.m_X) + (pMatrix.m11 * pVector.m_Y) + (pMatrix.m12 * pVector.m_Z);
res.m_Z = (pMatrix.m20 * pVector.m_X) + (pMatrix.m21 * pVector.m_Y) + (pMatrix.m22 * pVector.m_Z);
return res;
}
inline oag::CVectorFloat MultiplyMatrix4x4ByVectorFloat(const oag::Matrix4x4* pMatrix, const oag::CVectorFloat pVector)
{
oag::CVectorFloat res;
res.m_X = (pMatrix->m00 * pVector.m_X) + (pMatrix->m01 * pVector.m_Y) + (pMatrix->m02 * pVector.m_Z + pMatrix->m03);
res.m_Y = (pMatrix->m10 * pVector.m_X) + (pMatrix->m11 * pVector.m_Y) + (pMatrix->m12 * pVector.m_Z + pMatrix->m13);
res.m_Z = (pMatrix->m20 * pVector.m_X) + (pMatrix->m21 * pVector.m_Y) + (pMatrix->m22 * pVector.m_Z + pMatrix->m23);
return res;
}