Home Page
Compass Module
FSM Module
Floating Point Checker Module
Zref Module
Project Page
SourceForge goodness!
Class API
Doxygen goodness!
File Vault
Browse the source!
Roadmap
Know where we're headed!

Compass Module


Detailed Description

Image rotation is an essential, time-critical operation in real-time two-dimensional games. In a real-time strategy game based on World War II, for example, a tank turret must appear to be aiming at the enemy unit the tank is targeting as it moves into position (or while it is in a running battle).

Today's graphics libraries are very advanced and offer decent performance even within a pure software-rendering environment. However, the image rotation functions they provide either run too slowly, output unacceptable pixellation of the image, or require too many resources. (Two 3D triangles for a 2D sprite? Come on.)

A popular workaround is to fake image rotation with a handcrafted function based on a decision tree. Each entity owns an image array, and based on the current orientation of the entity, the function returns an index into the entity's image array, and the proper image is displayed. With an optimal decision tree and memory allocator for the image array, this results in much better performance.

The major drawback is scalability. What happens when game testers notice that a certain sprite's rotation is too "discrete" or jerky? How many more images are required in the array? Each such change brings about a major rewrite of the image "rotation" function, contributing to the loss of possibly many man-hours of work.

The Compass class addresses the scalability problem by dynamically adjusting its internal decision tree every time the number of possible rotation outputs changes. In our image rotation faking application, the correct index into the image array can be obtained by calling Compass::getDirection(). If and when the array size changes, pass the new size in a call to Compass::setDirectionCount(). This works for all sizes, even zero!


Classes

class  sgdk::ZeroDirection
 North, South, East, or West. More...
class  sgdk::PositiveRotation
 Clockwise or Counterclockwise. More...
class  sgdk::Compass<>
 The main class in the Compass Module. More...


Hosted by SourceForge.net.

This page is Valid HTML 4.01 Transitional! This page uses valid CSS!