gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Fixed point + Velocity

#28822 - wiz - Sun Nov 07, 2004 3:34 am

Hi!

Very simple this one,

On the PC I used to use sprites with velocity as a float, to slow the velocity I would simply v *= 0.7; this would obviously make value v increment/decrement to 0.

with fixed point this cant be done the same way... is there a good way to do this, at the moment I have ugly if statements that dont even work correctly ;)

Thanks for reading!

#28825 - tepples - Sun Nov 07, 2004 4:06 am

To implement velocity decay such as air drag, multiply by a fraction with a power-of-two denominator. This way you multiply (fast on the GBA's ARM7TDMI processor) and then divide by a power of 2 (also fast, implemented with a shift). For v *= 0.7; try v = v * 179 / 256;
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#28835 - identitycrisisuk - Sun Nov 07, 2004 2:24 pm

I'm new to this as well so I was just wondering, does that mean when v is 1 will it become 1 or 0? (I assume it would be 0 through truncation) I'd guess you'd have to be dealing with quite large velocities for this to be of much use but I guess unless you shift these before use stuff would fly all over the place.

#28840 - wiz - Sun Nov 07, 2004 4:04 pm

Brilliant! Thanks Tepples!

This fixed point math technique takes some getting used to....

identitycrisisuk, Im not sure I follow sorry, but v will become 0

#28866 - identitycrisisuk - Mon Nov 08, 2004 12:59 am

Ignore the second part, I was thinking about using it for standard integer numbers but then realised you meant fixed point.