I'm trying to use NewtonSetEulerAngle and NewtonGetEulerAngle to pass my Euler angles to the matrix, but the results are strange.
here is my code
- Code: Select all
#include <iostream>
#include "Newton.h"
using namespace std;
// Structure matrix
struct matrix
{
float matrice [4][4];
bool operator== ( const matrix & other)
{
if ( (matrice[0][0] == other.matrice[0][0]) &&
(matrice[0][1] == other.matrice[0][1]) &&
(matrice[0][2] == other.matrice[0][2]) &&
(matrice[0][3] == other.matrice[0][3]) &&
(matrice[1][0] == other.matrice[1][0]) &&
(matrice[1][1] == other.matrice[1][1]) &&
(matrice[1][2] == other.matrice[1][2]) &&
(matrice[1][3] == other.matrice[1][3]) &&
(matrice[2][0] == other.matrice[2][0]) &&
(matrice[2][1] == other.matrice[2][1]) &&
(matrice[2][2] == other.matrice[2][2]) &&
(matrice[2][3] == other.matrice[2][3]) &&
(matrice[3][0] == other.matrice[3][0]) &&
(matrice[3][1] == other.matrice[3][1]) &&
(matrice[3][2] == other.matrice[3][2]) &&
(matrice[3][3] == other.matrice[3][3]) )
return true;
else
return false;
}
static matrix getIdentity ()
{
matrix matrice;
for (int x = 0 ; x < 4 ; ++x)
for (int y = 0 ; y < 4 ; y++)
{
if (x == y)
matrice.matrice [x][y] = 1.0f;
else
matrice.matrice [x][y] = 0.0f;
}
return matrice;
}
void show ()
{
std::cout << "[" << matrice[0][0] << "] [" << matrice[0][1] << "] [" << matrice[0][2] << "] [" << matrice[0][3] << "]\n";
std::cout << "[" << matrice[1][0] << "] [" << matrice[1][1] << "] [" << matrice[1][2] << "] [" << matrice[1][3] << "]\n";
std::cout << "[" << matrice[2][0] << "] [" << matrice[2][1] << "] [" << matrice[2][2] << "] [" << matrice[2][3] << "]\n";
std::cout << "[" << matrice[3][0] << "] [" << matrice[3][1] << "] [" << matrice[3][2] << "] [" << matrice[3][3] << "]\n";
}
};
int main()
{
matrix mat4 = matrix::getIdentity ();
float angles[3] = { 0, -1.6, 0 };
NewtonSetEulerAngle( &angles[0], &mat4.matrice[0][0]);
mat4.show ();
float anglesRep[3];
NewtonGetEulerAngle( &mat4.matrice[0][0], &anglesRep[0]);
cout << "anglesRep[0]= " << anglesRep[0] << endl;
cout << "anglesRep[1]= " << anglesRep[1] << endl;
cout << "anglesRep[2]= " << anglesRep[2] << endl;
return 0;
}
I don't get the same angles before and after
In fact everything is ok if angles are less than 1.57 (pi/2) or greater than -1.57 (-pi/2). It seems that these functions work in a [-pi/2, pi/2] range.
Can you explain me how to use these functions and where i made a mistake.
Thank's for reading.
bye.

