#164342 - crazakp - Wed Oct 29, 2008 1:41 am
I looked through a couple threads about trig functions and bit shifting and fixed point numbers before deciding to post. I don't think this is an issue with any of those, but I could be wrong.
What I'd like to do is move a sprite in a circle. Starting at 0 degrees, if the user presses up, it moves up a degree, if they press down, down a degree.
So to accomplish this, I would just need to figure out the (x,y) coordinate based on the angle, radius, and center.
Since I just started learning about fixed point numbers and LUTs, I tried to make a simple example in mode 3, where I would just draw a circle.
My problem is that it draws the circle at (0,0) no matter what. Could someone help me figure out what's wrong with my code? I'm using tonc.
Since lu_cos has a range of [0,FFFFh], I divided that by 360 to come up with the multiplier for each degree (182).
EDIT:
I got around this problem by just using bresenham's circle algorithm, but I'd still like to know what I did wrong because I'm also trying to calculate projectile motion, which uses trig functions.
What I'd like to do is move a sprite in a circle. Starting at 0 degrees, if the user presses up, it moves up a degree, if they press down, down a degree.
So to accomplish this, I would just need to figure out the (x,y) coordinate based on the angle, radius, and center.
Since I just started learning about fixed point numbers and LUTs, I tried to make a simple example in mode 3, where I would just draw a circle.
My problem is that it draws the circle at (0,0) no matter what. Could someone help me figure out what's wrong with my code? I'm using tonc.
Code: |
#define MEM_VRAM 0x06000000 #define vid_mem ((COLOR*)MEM_VRAM) #define CLR_RED 0x001F int main() { COLOR clr = CLR_RED; int i,x,y,radius,cx,cy,angle; radius = 25<<8; cx = 75<<8; cy = 75<<8; REG_DISPCNT= DCNT_BG2 | DCNT_MODE3; vid_mem[(cy>>8)*M3_WIDTH+(cx>>8)]= clr; for(i=0; i<360; i++) { angle = (i * 182); x = cx + radius * lu_cos(angle)>>12; y = cy + radius * lu_sin(angle)>>12; vid_mem[(y>>8)*M3_WIDTH+(x>>8)]= clr; } while(1); return 0; } |
Since lu_cos has a range of [0,FFFFh], I divided that by 360 to come up with the multiplier for each degree (182).
EDIT:
I got around this problem by just using bresenham's circle algorithm, but I'd still like to know what I did wrong because I'm also trying to calculate projectile motion, which uses trig functions.