Here's a picture:

The red line represents the end of the map. Now the map could go on almost infinitely so it's important that we stop drawing at some distance. This distance is the field of vision and is represented in the following image as a blue line.

To implement field of vision simply do a check:

Blogger is messing up my code, Trying to fix it soon

if((a.z+b.z+c.z)/3 <>

This doesn't look quite so good so we try to blend it out with fog:

The green line represents the FogDistance, this is so that the fog doesn't start right in front of our eyes. That could get annoying, but sometimes it is wanted so just set the distance to 1 when needed. We simply add a little bit more black each time the triangle gets farther away from FogDistance:

Blogger is messing up my code, Trying to fix it soon

int r,b,g; // Color values of triangle

if((a.z+b.z+c.z)/3 > FogDistance) // Check if greater than distance

{

// Make Darker by distance to fogdistance*fogintensity

r = r-(FogIntensity*a.z+b.z+c.z)/3-FogDistance);

b = b-(FogIntensity*a.z+b.z+c.z)/3-FogDistance);

g = g-(FogIntensity*a.z+b.z+c.z)/3-FogDistance);

}

// Very important check if color values are acceptable:

if(r > 255) r = 255;

if(r < r =" 0;"> 255) b = 255;

if(b < b =" 0;"> 255) g = 255;

if(g < g =" 0">

int r,b,g // Color values of triangle

if((a.z+b.z+c.z)/3 > FogDistance) // Check if greater than distance

{

// Make Darker by distance to fogdistance*fogintensity

r-(FogIntensity*a.z+b.z+c.z)/3-FogDistance);

b-(FogIntensity*a.z+b.z+c.z)/3-FogDistance);

g-(FogIntensity*a.z+b.z+c.z)/3-FogDistance);

}

// Very important check if color values are acceptable:

if(r > 255) r = 255;

if(r < r =" 0;"> if(b > 255) b = 255;

if(b < b =" 0;"> if(g > 255) g = 255;

if(g < g =" 0;">

FogIntensity should be very small, just try it out. Something like: 0.0001

That's it for today, I'll hopefully implement colors next.

## No comments:

Post a Comment