mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 10:14:35 +00:00
Added eulerAnglesX tests
This commit is contained in:
parent
6409e4135a
commit
12cde2bf75
@ -11,33 +11,148 @@
|
||||
|
||||
#define GLM_FORCE_RADIANS
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <glm/gtx/euler_angles.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace glm;
|
||||
|
||||
int main()
|
||||
namespace test_eulerAngleX
|
||||
{
|
||||
f32 first = 1.046f;
|
||||
f32 second = 0.52f;
|
||||
f32 third = -0.785f;
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
fmat4 rotationEuler = eulerAngleYXZ(first, second, third);
|
||||
float const Angle(glm::pi<float>() * 0.5f);
|
||||
glm::vec3 const X(1.0f, 0.0f, 0.0f);
|
||||
|
||||
fmat4 rotationInvertedY = eulerAngleY(-1.f*first) * eulerAngleX(second) * eulerAngleZ(third);
|
||||
fmat4 rotationDumb = glm::fmat4();
|
||||
rotationDumb = rotate(rotationDumb, first, glm::fvec3(0,1,0));
|
||||
rotationDumb = rotate(rotationDumb, second, glm::fvec3(1,0,0));
|
||||
rotationDumb = rotate(rotationDumb, third, glm::fvec3(0,0,1));
|
||||
glm::vec4 const Y(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
glm::vec4 const Y1 = glm::rotate(glm::mat4(1.0f), Angle, X) * Y;
|
||||
glm::vec4 const Y2 = glm::eulerAngleX(Angle) * Y;
|
||||
glm::vec4 const Y3 = glm::eulerAngleXY(Angle, 0.0f) * Y;
|
||||
glm::vec4 const Y4 = glm::eulerAngleYX(0.0f, Angle) * Y;
|
||||
glm::vec4 const Y5 = glm::eulerAngleXZ(Angle, 0.0f) * Y;
|
||||
glm::vec4 const Y6 = glm::eulerAngleZX(0.0f, Angle) * Y;
|
||||
glm::vec4 const Y7 = glm::eulerAngleYXZ(0.0f, Angle, 0.0f) * Y;
|
||||
Error += glm::all(glm::epsilonEqual(Y1, Y2, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Y1, Y3, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Y1, Y4, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Y1, Y5, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Y1, Y6, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Y1, Y7, 0.00001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 const Z(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
glm::vec4 const Z1 = glm::rotate(glm::mat4(1.0f), Angle, X) * Z;
|
||||
glm::vec4 const Z2 = glm::eulerAngleX(Angle) * Z;
|
||||
glm::vec4 const Z3 = glm::eulerAngleXY(Angle, 0.0f) * Z;
|
||||
glm::vec4 const Z4 = glm::eulerAngleYX(0.0f, Angle) * Z;
|
||||
glm::vec4 const Z5 = glm::eulerAngleXZ(Angle, 0.0f) * Z;
|
||||
glm::vec4 const Z6 = glm::eulerAngleZX(0.0f, Angle) * Z;
|
||||
glm::vec4 const Z7 = glm::eulerAngleYXZ(0.0f, Angle, 0.0f) * Z;
|
||||
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Z1, Z3, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Z1, Z4, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Z1, Z5, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Z1, Z6, 0.00001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(Z1, Z7, 0.00001f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace test_eulerAngleX
|
||||
|
||||
namespace test_eulerAngleY
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float const Angle(glm::pi<float>() * 0.5f);
|
||||
glm::vec3 const Y(0.0f, 1.0f, 0.0f);
|
||||
|
||||
glm::vec4 const X(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glm::vec4 const X1 = glm::eulerAngleY(Angle) * X;
|
||||
glm::vec4 const X2 = glm::rotate(glm::mat4(1.0f), Angle, Y) * X;
|
||||
Error += glm::all(glm::epsilonEqual(X1, X2, 0.00001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 const Z(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glm::vec4 const Z1 = glm::eulerAngleY(Angle) * Z;
|
||||
glm::vec4 const Z2 = glm::rotate(glm::mat4(1.0f), Angle, Y) * Z;
|
||||
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace test_eulerAngleY
|
||||
|
||||
namespace test_eulerAngleZ
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float const Angle(glm::pi<float>() * 0.5f);
|
||||
glm::vec3 const Z(0.0f, 0.0f, 1.0f);
|
||||
|
||||
glm::vec4 const X(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glm::vec4 const X1 = glm::eulerAngleZ(Angle) * X;
|
||||
glm::vec4 const X2 = glm::rotate(glm::mat4(1.0f), Angle, Z) * X;
|
||||
Error += glm::all(glm::epsilonEqual(X1, X2, 0.00001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 const Y(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glm::vec4 const Y1 = glm::eulerAngleZ(Angle) * Y;
|
||||
glm::vec4 const Y2 = glm::rotate(glm::mat4(1.0f), Angle, Z) * Y;
|
||||
Error += glm::all(glm::epsilonEqual(Y1, Y2, 0.00001f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace test_eulerAngleZ
|
||||
|
||||
namespace test_eulerAngleXY
|
||||
{
|
||||
int test()
|
||||
{
|
||||
|
||||
std::cout << glm::to_string(fmat3(rotationEuler)) << std::endl;
|
||||
std::cout << glm::to_string(fmat3(rotationDumb)) << std::endl;
|
||||
std::cout << glm::to_string(fmat3(rotationInvertedY )) << std::endl;
|
||||
|
||||
std::cout <<"\nRESIDUAL\n";
|
||||
std::cout << glm::to_string(fmat3(rotationEuler-(rotationDumb))) << std::endl;
|
||||
std::cout << glm::to_string(fmat3(rotationEuler-(rotationInvertedY ))) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}//namespace eulerAngleXY
|
||||
|
||||
namespace test_eulerAngleYXZ
|
||||
{
|
||||
int test()
|
||||
{
|
||||
glm::f32 first = 1.046f;
|
||||
glm::f32 second = 0.52f;
|
||||
glm::f32 third = -0.785f;
|
||||
|
||||
glm::fmat4 rotationEuler = glm::eulerAngleYXZ(first, second, third);
|
||||
|
||||
glm::fmat4 rotationInvertedY = glm::eulerAngleY(-1.f*first) * glm::eulerAngleX(second) * glm::eulerAngleZ(third);
|
||||
glm::fmat4 rotationDumb = glm::fmat4();
|
||||
rotationDumb = glm::rotate(rotationDumb, first, glm::fvec3(0,1,0));
|
||||
rotationDumb = glm::rotate(rotationDumb, second, glm::fvec3(1,0,0));
|
||||
rotationDumb = glm::rotate(rotationDumb, third, glm::fvec3(0,0,1));
|
||||
|
||||
std::cout << glm::to_string(glm::fmat3(rotationEuler)) << std::endl;
|
||||
std::cout << glm::to_string(glm::fmat3(rotationDumb)) << std::endl;
|
||||
std::cout << glm::to_string(glm::fmat3(rotationInvertedY )) << std::endl;
|
||||
|
||||
std::cout <<"\nRESIDUAL\n";
|
||||
std::cout << glm::to_string(glm::fmat3(rotationEuler-(rotationDumb))) << std::endl;
|
||||
std::cout << glm::to_string(glm::fmat3(rotationEuler-(rotationInvertedY ))) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}//namespace eulerAngleYXZ
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_eulerAngleX::test();
|
||||
Error += test_eulerAngleY::test();
|
||||
Error += test_eulerAngleZ::test();
|
||||
Error += test_eulerAngleXY::test();
|
||||
Error += test_eulerAngleYXZ::test();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user