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);
}
}
}
}