GP2X Vector Intersection Without Floats


Incarnate

Still Fresh
Joined
Mar 11, 2006
Messages
13
I'm lookin to start a new project, and this time around I want to avoid floats as much as possible. (Armor City is pretty float intensive because I didn't realize the GP2X didn't have an FPU untill I was fairly far along, serves me right for starting to code without reading the forums first). Anyway, one of the things I'm having trouble doing without floats is my vector intersection function.

If I have a line from (x1, y1) to (x2, y2), and a bounding box, how can I determine if the line intersects the box without floats. Previously I was calculating the slope of the line, and finding the point at which it crossed vertical and horizontal lines of the bounding box, but that wont work without float slopes. Fixed point math is an option, but I'm just wondering if there are any integer based algorithms for this that I'm not aware of.
 
If you look for ClipPrimitive() in ContextRender.cpp, you'll find an implementation of the Sutherland-Hodgman algorithm. It's for 3D, but as you can see the code actually loops over the dimensions, so just set the upper bound from 3 to 2. Key ingredient is an efficient fixed point division, which you'll find in this code base, too.

Ignore the if(m_ClipPlaneEnabled) part for what you are doing here.

- HM
 
Back
Top