#6815 - hnager - Tue Jun 03, 2003 2:56 am
What do most find as the best approach to sin and cos? I'm working on a mini tank game where left and right rotate the tank and up and down move the tank...so I need a lookup table of sorts to calculate the x and y position - I have one now (which takes forever to build). Curious to see if anybody has any other techniques?
#6816 - tepples - Tue Jun 03, 2003 3:00 am
hnager wrote: |
so I need a lookup table of sorts to calculate the x and y position - I have one now (which takes forever to build). |
If you build a 256-entry cosine table on the PC, write it as a .c file, and compile it into your project, it won't take forever to build.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#6817 - hnager - Tue Jun 03, 2003 3:10 am
good point - the most obvious/best solution...
#7057 - philip - Sat Jun 07, 2003 1:08 pm
Yeah, that's what I do in my game, but, as has been said so many times before, you should use fixed point maths where ever possible. I multiply all the values by 4096 (bitshift left 12) and write them out as integers to a file. This then forms the lookup array. Once you've used the lookup values in your calculations, bitshift back again to remove the multiplication of the lookup array.
#7141 - hnager - Tue Jun 10, 2003 1:47 pm
Thanks - I was reading about that last night...how large of a lookup are you creating?
#7150 - tepples - Tue Jun 10, 2003 5:48 pm
Because it needs precision for small values of theta, Tetanus On Drugs uses a lookup table of 1024 entries for one quadrant. I could probably reduce this to 64 and get the same accuracy by using linear interpolation between entries; it's just a space-time tradeoff.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#7200 - hnager - Thu Jun 12, 2003 3:00 am
Does that chew up a lot of available memory? It doesn;t seem to be an issue as the game runs well and isn't 'simple'.
On a similar note - if I had a game which needed more than the alotted number of sprites and/or maps/tiles where are those stored and accessed? I haven't seen any examples so far that load images or maps from the cart, they've all been included as part of the compiled C.
#7223 - niltsair - Thu Jun 12, 2003 2:20 pm
They are stored in the cart's rom. Everything declared as const means that it is stored along in Rom. No memory used.
#7226 - hnager - Thu Jun 12, 2003 2:26 pm
aha - I thought I had seen that once before - when working with sin/cos lookup tables. thanks.