[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Fwded Post
Hi all,
David Clark wrote:
> sprite separately using floating point values, then use those values
> to create a rect for blitting, collision and updating. For example, my
[...]
> Good luck with your game.
>
> David Clark
Talking about floating point values, my background (game,demo) is the Amiga, the little
one that did not come with a MMU nor a FPU. So floating point computations were VERY
expensive and we would most of the time do 32 bits fixed point arithmetics for that.
Basically
If you need a 16 bit precision for some info (coordinates), then you represent your
coordinates on 32 bits.
ex
if you want
x=1
then define it
(C notation for hex do not know in python)
x=0x10000
In fact you use the negative power of 2.
x=1*2^0+0*2^0+0*2^0+0*2^0+0*2^0
You want to represent 1,25 EASY!
1.25 = 1 (2^0) + 0.25 (1/4=2^-2)
But it does not come so easily for everything.
In the original post, the user wanted the precision of 1/10 pixel
(decimal notation) 0.1 =~ (binary notation) 0,0001100101000010 (0.09994384765625)
=~ 0x1942
To do a step of ~0.1 you will just need to use 32 bits fixed point precision
xprecise += 0x00001942
and when you want to ACTUALLY use the coordinates, you just have to do
x_tobedisplayed= (xprecise / 65536)
and that is all!
Nobody uses this technique apart from me?
Guillaume
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org