#76483 - Ultima2876 - Wed Mar 22, 2006 2:01 am
Code: |
void affinec(int affine_no, int angle, int scalex, int scaley, s16 *x, s16 *y, s16 xcentre, s16 ycentre)
{ signed int tempx = 0; //variable declerations signed int tempy = 0; signed int rotx = 0; signed int roty = 0; s16 pa = 0; s16 pb = 0; s16 pc = 0; s16 pd = 0; affine(affine_no, angle, scalex, scaley); //this fills the affine matrix with correct values - it is pre-tested and fills them correctly pa = sprites[(affine_no << 2)].attribute3; //set pa, pb, pc, pd (just to make the code below clearer) pb = sprites[(affine_no << 2) + 1].attribute3; pc = sprites[(affine_no << 2) + 2].attribute3; pd = sprites[(affine_no << 2) + 3].attribute3; relative_x = *x - xcentre; //the main bit relative_y = *y - ycentre; rotx = ((pa * relative_x) >> 8) + ((pb * relative_y) >> 8); roty = ((pc * relative_x) >> 8) + ((pd * relative_y) >> 8); *x = rotx + xcentre; *y = roty + ycentre; } |
That's the code I'm using for this. My aim to have a sprite rotating around a given centrepoint. I saw code very similar to mine in another topic, and with a very similar problem - however, I have combed through the words in that topic for hours now looking for something I've missed.
The problem is, the sprite simply flies around the screen, flashing everywhere. After hours and hours of fiddling, I've decided that I can't find my mistake, and hopefully someone here will be able to help..
The affine function fills the affine matrices, and I use it a lot. It works perfectly - so that's not the problem. I've also tested various things - it seems that if I take away the *x and *y from the setting of relative_x/y I can get it to rotate correctly around centrepoint 0, 0 (that is, screen co-ordinate) - and it treats the xcentre and ycentre as if they were he sprite's co-ordinates... but I want to be able to specify the centrepoint!
Thanks in advance =P