Fluently rotation of the node.

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
JaskierPL
Posts: 10
Joined: Tue Apr 03, 2012 9:36 pm

Fluently rotation of the node.

Post by JaskierPL »

Recently I have written a function, which allows you to turn the node to specified rotation by the shortest way. Angle is number of degress, so you can turn node in every loop by some degress and then rotation is fluently. I hope it will be useful for you.

Code: Select all

 
void Turn(irr::scene::ISceneNode* node,irr::core::vector3df rot,float angle)
 {
          for(;;)
          {
          if(node->getRotation().Y>360) node->setRotation(irr::core::vector3df(node->getRotation().X,node->getRotation().Y-360,node->getRotation().Z));
          else if(node->getRotation().Y<0) node->setRotation(irr::core::vector3df(node->getRotation().X,360+node->getRotation().Y,node->getRotation().Z));
          else break;
          }
 
          float start=node->getRotation().Y;
          float destin=rot.Y;
          float wk;
          float mn;
 
          if(start!=destin)
          {
          if(destin>360) destin=destin-360;
 
          if(destin>start)
          {
          wk=destin;
          mn=start;
          }
          else
          {
          wk=start;
          mn=destin;
          }
 
         if(wk-mn<=angle) node->setRotation(irr::core::vector3df(node->getRotation().X,destin,node->getRotation().Z)); 
         else
         {
        if(wk-mn<mn+360-wk)
         {
        if(mn==destin) node->turn(0,-angle,0);
        else node->turn(0,angle,0);
         }
        else
        {
              if(mn==destin) node->turn(0,angle,0);
              else node->turn(0,-angle,0);
        }
        }
        }
 }
 
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Fluently rotation of the node.

Post by REDDemon »

if(mn==destin) node->turn(0,angle,0);
Is that a recursive function? because node has no member function called "turn". So maybe you inteded to use "Turn". probably that example will not compile.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
wiedzmin112
Posts: 30
Joined: Tue Oct 18, 2011 3:48 pm

Re: Fluently rotation of the node.

Post by wiedzmin112 »

He is using my irrlicht compilation(i added 2 functions)

Code: Select all

 
                void move(float x=0.0f, float y=0.0f, float z=0.0f)
                {
                        irr::core::matrix4 new_mat;
                        new_mat.makeIdentity();
                        new_mat.setRotationDegrees(getRotation());
                        irr::core::vector3df vm(x,y,z);
                        new_mat.transformVect(vm);
                        setPosition(getPosition()+vm);
                }
                void turn(float x=0.0f, float y=0.0f, float z=0.0f)
                {
                        setRotation(getRotation() + irr::core::vector3df(x,y,z));
                }
 
Post Reply