[A83] Re: fixed point numbers


[Prev][Next][Index][Thread]

[A83] Re: fixed point numbers




At 04:56 PM 4/29/01 +0200, you wrote:
>I have a sprite that moves around the screne with a certain speedvector.  So
>every frame i have to increase my x and y coordinates using the sinus and
>cosinus of that speedvector
>Last week i was talking to Crashman, and he told me to do it with a look up
>table for sinus and cosinus.  He told me also to work with fixed point
>numbers (so i would place the part after the comma in that look up table
>(the part before the comma is most of the time zero, so i don't have to put
>it in another table)). But i'm not sure how to work with those fixed point
>numbers, here's the two options i've come up with (maybe there's a better,
>that's way i ask you guys)
>1.	Say you have the number 0.531287 as a sinus, then you have to put 53 (if
>you want to use 1 byte) or 531 (if you want to use 2 bytes) in that look up
>table: so that would be .db ...,53,... ( '...' stands for other values in
>the table). Then you recall 53 and put it in h for example, you multiply it
>with 3 (for example) and then....?  i think you would have to divide it by
>100 and round it so you get an integer ('cause i need integers for my
>coordinates for my sprite)  But with this first method, you would still have
>a fp number when you divide by 100 and can you put a fp number in a register
>to round it? (also is there a routine to round a fp number to an integer?)
>2.	A second option would be to just put fp numbers in the table (if that's
>possible) so you would get something like this: .db ...,0.531287,...
>(This would also be more precise) and then you load that number directly in
>a register (ld hl,(sintable+5) for example), but then i have another
>problem: how do you multiply a register pair with a certain number? (with
>single registers i would use (_htimesl))
>      3.  Maybe the third option is for you guys?

By multiplying the values by 100 and placing them in the registers, you
simply have a unit curcle 100 units in radius.  You might want to multiply
by a power of two, so that you can use bit shifting to divide back to a 1
unit circle.




References: