Vector Graphics
Algorithms
Site Map Feedback
Up gCoord Points Vectors PV Planes

Fundamentals

The code in this section is designed to allow you to store and draw lines, arcs and splines which may represent three-dimensional objects.

People used to worry about speed differences in using integers or floating-point arithmetic for graphics. Modern processors and graphics boards mean that whatever is most natural can often be used, so floating-point arithmetic is used here and rounding errors dealt with by specifying a "Tolerance". This Tolerance is the core of the whole system on these pages and, consequently, discussed in depth later. Using floating-point arithmetic allows you to debug and see real values. Conversion from double to integer still needs some thought though, because current floating point processors clear the processor pipeline when setting the rounding mode. Methods Floor and Round provided in Global.h work around this.

The Graphics Primitive structures are all prefixed with "g" (for "graphic") and a number representing the number of Dimensions the structure will handle (2 or 3). So the three-dimensional Point structure is a g3Point. Two and three dimensional structures are presented for each concept and abuse the whole idea of object orientation by defining the structures in terms of the data they will hold rather than the object they represent. At first this seems bizarre, but when you are actually working with the classes you'll be surprised at how rarely you think about the object you're dealing with: you're almost always more concerned with the maths defining the object. So, for example, there is a class which contains a Vertex and a Vector... The word "Point" is used instead of "Vertex" so that the class for a for "PointVector" can be called "g3PV"... This class could represent a Position Vector, or a Line, or an axially-aligned Box (Point is one corner, Vector points to opposite corner). The maths for each possibility is likely to be in the primitive, so a g3PV will have a "Hit" function to to see if a point lies on the line; a "HitBox" function to see if it lies in the Box etc. That's why these structures are referred to as "Primitives": you can derive "proper" classes from them, but at this level, they are simple open boxes to hold things in.

Start with the gCoord structure and work along the sections in the top menu.

Each class has a CString Report() const; method that is great for TRACE when debugging, or passing to APIs. It's also valuable for regression testing: collect a file full of report strings and remember the MD5 checksum of the file. Next time you run the test you only need to check the MD5 against the one you remembered to see if anything changed. Once you have a difference, compare the two text files to see where things started to differ. This is good over slow connections because you can have a huge number of tests and just send a pile of MD5 strings for comparison with the server's MD5s.