I have programmed with IrrLicht about few weeks and I am satisfied with the 3d engine. Now I have a problem:
I have to compute three angles alfa,beta,gamma for make an a rotacion:
I have 2 vectors: (0,1,0) and (x,y,z).
My desire is rotate vector (0,1,0) and transform it to normalized vector (x,y,z). I will use this code for rotate a mesh of an sceneNode.
ISceneNode have a function <setRotacion>:
virtual void irr::scene::ISceneNode::setRotation ( const core::vector3df &rotationdegrees)
I need to pass the rotation <rotationdegrees> of the three euler angles for rotating (0,1,0) and accomplish the vector (x,y,z).
I tried to calculate with the atan2 function of the three planes and call <setRotation>, but I didn't accomplish my objective in many cases.
Here are my code:
Code: Select all
v3d0=vector3df(0,1,0); // v3d0=vector (0,0,0)
float alfa0,beta0,gamma0;
if (v3d0.Y >= 0) alfa0=atan2f(v3d0.Y, v3d0.X);
else alfa0=6.28+atan2f(v3d0.Y, v3d0.X);
if (v3d0.X >= 0) beta0=atan2f(v3d0.X, v3d0.Z);
else beta0=6.28+atan2f(v3d0.X, v3d0.Z);
if (v3d0.Y >= 0) gamma0=atan2f(v3d0.Y, v3d0.Z);
else gamma0=6.28+atan2f(v3d0.Y, v3d0.Z );
//---------------------------------------------------------------------
float alfa,beta,gamma;
v3d=posEsf[i+1]-posEsf[i]; // v3d=vector (x,y,z)
if (v3d!=vector3df(0,0,0)) v3d.normalize();
if (v3d.Y >= 0) alfa=atan2f(v3d.Y, v3d.X);
else alfa=6.28+atan2f(v3d.Y, v3d.X);
if (v3d.X >= 0) beta=atan2f(v3d.X, v3d.Z);
else beta=6.28+atan2f(v3d.X, v3d.Z);
if (v3d.Y >= 0) gamma=atan2f(v3d.Y, v3d.Z);
else gamma=6.28+atan2f(v3d.Y, v3d.Z );
// make angles
v3dAngles=vector3df(gamma-gamma0,beta0-beta,alfa0-alfa);
v3dAngles *= 360/6.28; // radians to degrees
node->setRotation(v3dAngles); // but the mesh rotate different that I hopeCan somebody explain to me how to make this?.
Thanks to all users for reading this message.