Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Re: Digest Number 1241   Message List  
Reply | Forward Message #14598 of 15019 |
On Saturday, November 8, 2003, at 04:57 AM, gbadev@yahoogroups.com
wrote:

> BTW, do to weird round off, when we rotate/scale a multi-part sprite
> around, the sprite tends to break up a little. Have you guys
> figured out the trick to fixing this?

If it is, in fact, round-off that is causing your error, you can make
sure that your fixed-point calculations are rounded to the nearest
value instead of truncated when you shift off any of the fractional
portion.

For example, say I multiply two 24.8 numbers:

c = a * b; // c is now 16.16

In order to reduce it back to 24.8, I would normally do the following:

c >>= 8;

To make sure the number is rounded instead of just truncated, I can
mask out everything except the 7th bit of the number, and then add it
to the original number before shifting:

c += (c & (1 << 7)); // (1 << 7) is (0000 0000 0000 0000 0000 0000 1000
0000)b
c >>= 8;

If you round off your calculations as you go instead of just
truncating, I find it tends to significantly reduce those minor screen
errors. Now the only trick is figuring out which calculations can
benefit from the rounding process and which calculations it is wasted
cycles for. (This shouldn't have to be a consideration if you are only
doing it once per frame, but if like me you are doing these
calculations in a tight inner loop you need to be much more frugal with
your cycles.)

Dan.

--
Dan Posluns, B. Eng. & Scty. (Software Engineering and Society)
dan@... - ICQ: 35758902
http://www.danposluns.com

"Only when the last tree has been cut down, only when the last river
has been poisoned, only when the last fish has been caught - only then
will you realize that money cannot be eaten."
- Cree prophecy





Sat Nov 8, 2003 3:05 pm

poslundc
Offline Offline
Send Email Send Email

Forward
Message #14598 of 15019 |
Expand Messages Author Sort by Date

On Saturday, November 8, 2003, at 04:57 AM, gbadev@yahoogroups.com ... If it is, in fact, round-off that is causing your error, you can make sure that your...
Dan Posluns
poslundc
Offline Send Email
Nov 8, 2003
3:17 pm

i would normally just use the following to round while shifting down c = (c + (1<<7)) >> 8; mathematically, this is like 'floor(x + 0.5)', which rounds x to...
alex mole
lordBosh
Offline Send Email
Nov 8, 2003
3:41 pm

"breaking up" of rotated/scaled OBJs is not due to fixed point rounding error, it's due to the unpredictability of the pixels that get lit in the hardware...
matthew conte
whatwouldbig...
Offline Send Email
Nov 9, 2003
2:34 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help