Page 1 of 1

Sinus/Cosinus for movement

Posted: Wed Aug 08, 2007 8:07 pm
by gencosman
I wanted to make a model move freely in 360°, but when changing direction (+/-45°) the directions change a little. As an example on O° it gets up, +45° and back, the movement goes up with a little to the right.


In class MyEventReceiver : public IEventReceiver:

Code: Select all

case KEY_KEY_Q:
player->angle-=45;
break;
case KEY_KEY_D:
player->angle+=45;
break;
In update()

Code: Select all

myPos.x +=  cos(angle) /10.;
myPos.z +=  sin(angle) /10.;


anms->setRotation ( core::vector3df ( 0,angle,0 ) );
anms->setPosition ( core::vector3df ( myPos.x,myPos.y,myPos.z ) );
What can the problem be?
myPos is a struct with floats.

Posted: Wed Aug 08, 2007 8:37 pm
by evo
The (co)sinus functions require an argument in radials. Convert with:
radials = degrees * Pi / 180
Or use constant core::GRAD_PI2

Also, maybe your variable angle is not the same one as player->angle

Posted: Thu Aug 09, 2007 1:18 am
by gencosman
Ok it works ;), thanks.

The example I copied from was some vector math.