Game Development Reference
In-Depth Information
Often, we need a lighting level even when no light is present. In computer
graphics models this is the ambient level. In our very simple model we
define ambient to be 0.12. The result of the angle calculation will be a
value between 0 and
radians. We require a value between 0 and 1 so
the result of the calculation is divided by
.
void CPolygon::DrawShaded(CCanvas &buf, BOOL drawNormal){
//Only 24 bit supported a the moment
if (buf.GetBitDepth()!=24) return;
//The polygon is facing away from camera
if (!Facing()) return;
int count,min,max,mid,i;
int x[3],y[3],tri=0;
double m1, c1, m2, c2, q, xs, xe, light;
//Create a unit length lighting vector
CVector lvec(0.707,-0.707,0.0);
//We are using an ambient of 0.12 so we scale the light level
//to 1.0-ambient level=0.88 then add the ambient level
light=acos(lvec*normal)/PI*0.88+0.12;
//Set shaded colour value these values are used by HorzLine
//col stores the unshaded value of the polygon
red=(BYTE)((double)col.red*light);
green=(BYTE)((double)col.green*light);
blue=(BYTE)((double)col.blue*light);
count=1;
//Repeat for each triangle using vertices
//(0,1,2) (0,2,3) ... (0,n-2,n-1) where n is the number
//vertices in the triangle
//This technique is fast but will paint concave polygons
//incorrectly
while(count<(numverts-1)){
x[0]=pts[0].sx; x[1]=pts[count].sx; x[2]=pts[count+1].sx;
y[0]=pts[0].sy; y[1]=pts[count].sy; y[2]=pts[count+1].sy;
//Sort points by screen height
max=(y[0]<y[1])?1:0;
max=(y[max]<y[2])?2:max;
min=(y[0]<y[1])?0:1;
min=(y[min]<y[2])?min:2;
mid=3-(max+min);
q=(double)(x[max]-x[min]);
//Use EPSILON, a very small value, to avoid division by zero
//errors
Search Nedrilad ::

Custom Search