#include <sphere.h>
Inheritance diagram for sphere< T, S >:
Public Member Functions | |
sphere (double x, double y, double z, double size, int color) | |
Constructor which specifies sphere location, size and color. | |
sphere () | |
Default constructor. | |
Public Attributes | |
T | x |
x coordinate | |
T | y |
y coordinate | |
T | z |
z coordinate | |
S | size |
diameter | |
unsigned char | color |
An index which specifies a drawing list with a color. |
This file defines a sphere class and a gl_sphere class. The sphere class is the base class and is designed to use as few bytes as possible. It has been instantiated using short int coordinates and byte color and size values. In this form a sphere is stored in 8 bytes. A second instantiation uses float coordinates and size values. This form requires 17 bytes per sphere which is typically rounded up to 20 bytes.
The gl_sphere class is derived from the sphere class to allow depth sorting. Drawing transparent objects properly in OpenGL requires first drawing opaque objects and then drawing transparent or translucent objects in decreasing order of distance from the viewpoint. To make the sorting faster, it is best to store the distances in the object with the sphere values.
For simplicity and versatility animp considers each object to be translucent and sorts all the objects. This requires more time, but not very much more.
The distance values are only used in comparison to each other, so this class actually uses distances squared to avoid wasting time calling sqrt.
The distance value is a double so the gl_sphere objects are 16 bytes each compared to 8 for the sphere objects (or 28 versus 20 for the float variety).
|
Constructor which specifies sphere location, size and color.
|
|
Default constructor. This constructor is used when arrays of spheres are created. |
|
x coordinate
|
|
y coordinate
|
|
z coordinate
|
|
diameter
|
|
An index which specifies a drawing list with a color. An integer which selects a drawing list for the sphere. Each drawing list specifies a color. |