Contents
Visualizing Floats
 
 
Printer-Friendly VersionPrinter-Friendly Version
 


Part of:



[More information...]
 

Latest News
spacer View All spacer
 
November 22, 2009
 
Video Game Watchdog National Institute On Media And The Family Shutting Down [11]
 
Modern Warfare 2 Infinity Ward's 'Most Successful PC Version' Yet [12]
 
New Tech, Design Details Of Project Natal To Emerge At Gamefest In February
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
November 22, 2009
 
Sucker Punch Productions
Character Artist
 
Sucker Punch Productions
3D Environment Artist
 
Sucker Punch Productions
Network Programmer
 
Sucker Punch Productions
Texture Artist
 
Sony Online Entertainment
Brand Manager
 
Monolith Productions
Sr. Software Engineer, Engine - Monolith Productions - #113767
 
Crystal Dynamics
Sr. Level Designer
 
Gargantuan Studios
Lead World Designer
spacer
Latest Features
spacer View All spacer
 
November 22, 2009
 
arrow Upping The Craft: Susan O'Connor On Games Writing [6]
 
arrow Small Developers: Minimizing Risks in Large Productions - Part II [6]
 
arrow iPhone Piracy: The Inside Story [48]
 
arrow And Yet It Grows: Analyzing the Size and Growth of the European Game Market [5]
 
arrow NPD: Behind the Numbers, October 2009 [13]
 
arrow Reflecting On Uncharted 2: How They Did It [5]
 
arrow Sponsored Feature: Rasterization on Larrabee -- Adaptive Rasterization Helps Boost Efficiency
 
arrow Postmortem: Wadjet Eye's The Blackwell Convergence [2]
spacer
Latest Blogs
spacer View All     Post     RSS spacer
 
November 22, 2009
 
Accepting the Inherent Value of Games
 
Planckogenesis, Part II: Song Structure & Gravy Train [1]
 
Designing Games Is About Matching Personalities [1]
spacer
About
spacer News Director:
Leigh Alexander
Features Director:
Christian Nutt
Editor At Large:
Chris Remo
Advertising:
John 'Malik' Watson
Recruitment/Education:
Gina Gross
 
Features
  Visualizing Floats
by Mick West
6 comments
Share RSS
 
 
January 7, 2009 Article Start Previous Page 3 of 3
 

The result of this could go two ways depending on how you implement your logic. If you started out saying, "Z>0 implies the point if to the left of the line," then all the floating point regions that are on the line (Z=0), will show up as little holes-regions where the collision fails. The quick solution here is to change the test to Z greater than or equal to 0. This eliminates the problem of holes but creates a new problem-the regions on the line (Z=0) are now shared by both triangles.

Problems can arise if the collision routine returns a list of all the triangles it detects a collision with. The logic might not be set up to deal with having contact with two different surfaces in the same logic frame, leading to problems such as sound effects being stuck on or events failing to trigger.

More commonly though, a line-environment collision test will return the closest collision point. Since both polygons will return the same point (which, as we see in the figures, is actually an overlapping region), then the polygon detected will be determined by the order in which the polygons are tested.

Historically, the polygons are tested in the same order. However, with the increasing prevalence of multi-core architectures, it's increasingly common for programmers to implement some kind of data-level parallelism, where the order in which the individual polygons are tested is not guaranteed and varies based on the way additional tasks use the cores and by the state of the memory cache, which varies from frame to frame.

The result can be that the same collision test performed on the same data might return either of two polygons in a seemingly random manner. Most likely, it will return one polygon 99.99 percent of the time, with the other polygon cropping up extremely rarely.

You might even find a Heisenbug, which can be incredibly difficult to track down, since a) it surfaces very rarely, b) the conditions can be impossible to replicate, and c) introducing test code can "fix" the problem.

There are a number of solutions. For one, you can change your multi-core data sharing algorithm so that polygons which might share an edge are always submitted in the same batch-but it would still leave you with the potential problem of two polygons being returned with the same collision point.

You could also try to guarantee that the regions on the line Z=0 always belong to one polygon of the other, which you could do by flagging the edges of a polygon so one side uses Z<0 and the other effectively uses Z greater than or equal to 0.

Pinning Down Drifters

Floats are a very useful way of representing numbers, but keep in mind that they do not perfectly represent the mathematical world that you use when creating algorithms. Floating point coordinates represent regions in space rather than points.

Those regions get a lot bigger as you move farther from the origin and eventually create noticeable artifacts such as jittering and visible seams. This is an important consideration if you are attempting to scale an existing engine to one that supports a much large world.

Floating point inaccuracies can lead to indeterminate boundary regions of variable size, and these need to be dealt with explicitly to avoid Heisenbugs.

References

Ericson, Christer. "Numerical Robustness" in Real-Time Collision Detection. San Francisco: Morgan Kaufmann, 2004.

Freese, Peter. "Solving Accuracy Problems in Large World Coordinates" in Game Programming Gems 4, Hingham, Mass.: Charles River Media, 2004.

[EDITOR'S NOTE: This article was independently published by Gamasutra's editors, since it was deemed of value to the community. Its publishing has been made possible by Intel, as a platform and vendor-agnostic part of Intel's Visual Computing microsite.]

 
Article Start Previous Page 3 of 3
 
Comments

Thibault Jochem
profile image
232 bit patterns in a 32bit ?? wtf ....

I guess something went wrong with the "^"

Ann-Marie Ratcliffe
profile image
Ah, I see someone got there first, so I'll just second the comment.

Not sure if the formatting got corrupted by the Content Management, but all your '2 to the power of' numbers got squashed into one, so 2^32 became 232, and so on.

Peter Freese
profile image
This is a great article, reposted from Mick's blog: http://cowboyprogramming.com/2007/01/05/visualizing-floats/comment-page-1/

One point of correction (which I noted on Mick's blog page) is that changing the scale of units doesn't solve (or change) the accuracy. Using the example of Los Angeles to New York, it doesn’t make a bit of difference whether 1.0 represents 1 meter, 1 kilometer, or 1 parsec. Accuracy will still only be +/- 0.5 meters at the distance of New York to LA from the origin. The issue here is that accuracy is limited by precision at that range, regardless of the units.

Another way of thinking about this is that changing from meters to kilometers may decrease the numerical error from 0.5 to 0.0005, but the units of the error change as well, i.e. 0.5 meters is still equivalent to 0.0005 kilometers.

Simon Carless
profile image
Thanks, guys - this is actually originally reposted from Game Developer magazine (where it first appeared). We fixed the typo with 2^32, incidentally, and the other inaccuracy.

Raymond Grier
profile image
I don' think this article properly explained the actual source of the problems with floating point arithmetic:
There are only a limited number of values that can be represented by 32 bits but an infinite number of decimal values between 0.0 and 1.0, therefore each value is some decimal value less than the next biggest one with the same bit combination in it's 8-bit power section. To make things worse, the distance between 2 consecutive values is different depending on what the 8-bit combination is, which makes it hard toi anticipate the amount of error when performing an operation on 2 floats.
Everyone whoi studied science in school knows that the source of error at the end of an operation is at least as big as the biggest source of error of the 2 operands, if not bigger. if you then use that result in another operation with a another float (and so on....), the source of error keeps compounding and this is why flaoting point math has accuracy problems. The examples in the article are ultimately a result of this problem.

Vojislav Stojkovic
profile image
Another typical problem with floats -- one that stems from the issues addressed in this article -- is the comparison. If we're talking about results of computation with several steps in it, then comparing two such floats directly is always risky business. Likewise, comparing a result of floating point computation to zero is also risky. Instead, of direct comparisons, programmers should calculate the error and compare it to a predefined epsilon value.


none
 
Comment:
 


Submit Comment