Please,how I can rotate a SceneNode without know angles? ...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
jordi
Posts: 2
Joined: Tue Jun 12, 2007 10:53 am

Please,how I can rotate a SceneNode without know angles? ...

Post by jordi »

Hello to the community:

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,1,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 hope 
How does this function make the rotation?

Can somebody explain to me how to make this?.

Thanks for reading this message.
Delight
Posts: 42
Joined: Tue Jul 05, 2005 3:16 pm
Location: Muenster, Germany

Post by Delight »

Perhaps you could use the DotProduct:

C#

Code: Select all

Vector3D Vec1 = new Vector3D( 1,0,0);
Vector3D Vec2 = new Vector3D( x, y, z );

Vector3D tempVec = new Vector3D( Vec2.x, Vec2.y, 0 );
float zAngle = 90.0f - (float)(Math.Acos(-Vec1.DotProduct( tempVec ) / tempVec.Length)) * NewMath.RADTODEG;

Vec1 = new Vector3D( 0,0,1);
tempVec = new Vector3D( 0, Vec2.y, Vec2.z );
float xAngle = 90.0f - (float)(Math.Acos( Vec1.DotProduct( tempVec ) / tempVec.Length)) * NewMath.RADTODEG;

node.Rotation = new Vector3D( xAngle, 0, zAngle );

Now the Vector (0,1,0) of your untransformed mesh should be (x,y,z) after rotating
Post Reply