I am having problems moving an object in the direction of the angle that Its moving in. I can't see whats wrong with it, but the output is definitely wrong.
Here where I declare and create an object:
Code:
struct Sprite
{
float x, y;
int w, h;
int r, g, b;
float angle, speed;
}; typedef struct Sprite Sprite;
Sprite thing;
Here I initialize some variables:
Code:
thing.x=320; thing.y=240;
thing.w=10; thing.h=10;
thing.r=255; thing.g=0; thing.b=0;
thing.angle=90; thing.speed=2;
With an angle of 90 degrees it should move downwards, but I'm finding it moves to the left as well (as if around 110 degrees or so). Heres where I move it:
Code:
float dx, dy;
dx=cos(thing.angle);
dy=sin(thing.angle);
thing.x+=(thing.speed*dx);
thing.y+=(thing.speed*dy);
Can anyone see whats going wrong here?