1 #ifndef KYRA_ISOGEN_EDGES_INCLUDED
2 #define KYRA_ISOGEN_EDGES_INCLUDED
3 
4 class Edge
5 {
6   public:
~Edge()7 	virtual ~Edge()	{}
8 
X()9 	int X() { return x; }
Y()10 	int Y()	{ return y; }
11 	virtual bool Next() = 0;
NoTouch()12 	bool NoTouch()	{ return noTouch; }
13 
SetNoTouch()14 	void SetNoTouch() { noTouch = true; }
15 
16   protected:
Edge(int x,int y,int yMax)17 	Edge( int x, int y, int yMax )	{
18 		this->x = x;
19 		this->y = y;
20 		this->yMax = yMax;
21 		noTouch = false;
22 
23 		GLASSERT( this->y <= this->yMax );
24 	}
25 	int x, y, yMax;
26 
27   private:
28 	bool noTouch;
29 };
30 
31 
32 class IsoEdgeNeg : public Edge
33 {
34   public:
IsoEdgeNeg(int x,int y,int yMax)35 	IsoEdgeNeg( int x, int y, int yMax ) : Edge( x, y, yMax )	{}
36 
Next()37 	virtual bool Next() {
38 		y++;
39 		x -= 2;
40 		return ( y <= yMax );
41 	}
42 };
43 
44 
45 class IsoEdgePos : public Edge
46 {
47   public:
IsoEdgePos(int x,int y,int yMax)48 	IsoEdgePos( int x, int y, int yMax ) : Edge( x, y, yMax )
49 	{}
50 
Next()51 	virtual bool Next() {
52 		y++;
53 		x += 2;
54 		return ( y <= yMax );
55 	}
56 };
57 
58 
59 class VEdge : public Edge
60 {
61   public:
VEdge(int x,int y,int yMax)62 	VEdge( int x, int y, int yMax ) : Edge( x, y, yMax ) {}
63 
Next()64 	virtual bool Next() {
65 		y++;
66 		return ( y <= yMax );
67 	}
68 };
69 
70 
71 // Implements half of a Bresenham line algorithm to render an arbitrary edge.
72 // Should only be used for internal edges, not the iso edges at seams.
73 class LineEdge : public Edge
74 {
75   public:
LineEdge(int x0,int y0,int x1,int y1)76 	LineEdge( int x0, int y0, int x1, int y1 ) : Edge( x0, y0, y1 )
77 	{
78 		deltaX = abs( x1-x0 );
79 		deltaY = y1-y0;
80 		GLASSERT( deltaX <= deltaY );
81 		bias = ( x1 > x0 ) ? 1 : -1;
82 
83 		error = deltaX*2 - deltaY;
84 	}
85 
Next()86 	virtual bool Next() {
87 		y++;
88 
89 		// Check to advance the X:
90 		if ( error >= 0 )
91 		{
92 			x += bias;
93 			error += ( deltaX*2 - deltaY*2 );
94 		}
95 		else
96 		{
97 			error += deltaX*2;
98 		}
99 		return ( y <= yMax );
100 	}
101 
102 	int deltaX, deltaY, error, bias;
103 };
104 
105 #endif
106