Game Development Reference
In-Depth Information
we add m to the incremental value d . If it tips over the value for dx then
we need to increase y . When we increase y we decrease the incremental
value d by c and adjust our memory pointer to point to another line. The
operation for the y -axis works in the same way. So now we can draw
arbitrary lines on our memory bitmap using integer arithmetic alone.
A simple class to implement a polygon
Now we have an off-screen buffer in the form of CCanvas and the ability
to draw an arbitrary line on this buffer defined by two points. The next step
is to implement a class to store and display a polygon. This class is
defined as:
class CPolygon
{
public:
//Member variables
POINT3D pts[4];//Stores the vertex data
CVector normal;//The unit length normal
int numverts;//Number of vertices in polygon
doubleh,p,b;//Euler angle rotation
COLOUR col;//RGB values for the unshaded colour of the polygon
BYTE red,green,blue;//Used for all drawing operations
CTexture *tex;//Bitmap texture pointer
CPolygon *next;//Used if the polygon is one of a list
//Functions
CPolygon();//Constructor
CPolygon(int total, CVector *pts);//Constructor
~CPolygon();//Standard destructor
BOOL Facing();//True if screen coordinates of vertices
//are in counter clockwise order
void SetColour(int red,int green, int blue);
void AveragePointNormal(CVector &norm);//Define normal from an
//average of the vertex
//normals
void SetNormal();//Calculates normal from vertex positions
void HorzLine(CCanvas &canvas, int x1, int x2,
int y, double light=1.0, double ambient=0.0);
BOOL SetPoints(int total, CVector *pts);//Set the vertex values
void SetColour(COLOUR col);//Set the colour value
void SetTexture(CString &filename);//Set texture from bitmap
//filename