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.

Fluently rotation of the node.

Postby JaskierPL » Wed Apr 04, 2012 5:07 pm

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.

cpp 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);
        }
        }
        }
 }
 
JaskierPL
 
Posts: 10
Joined: Tue Apr 03, 2012 9:36 pm

Re: Fluently rotation of the node.

Postby REDDemon » Sun Apr 15, 2012 9:48 am

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.
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Fluently rotation of the node.

Postby wiedzmin112 » Mon Apr 16, 2012 3:14 pm

He is using my irrlicht compilation(i added 2 functions)
cpp 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));
                }
 
wiedzmin112
 
Posts: 30
Joined: Tue Oct 18, 2011 3:48 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron