1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include "Vlib.h"
void
VSetVisibility(double d)
{
int i;
double k;
_VDefaultWorkContext->visibility = d;
if (_VDefaultWorkContext->visTable) {
free((char *) _VDefaultWorkContext->visTable);
}
_VDefaultWorkContext->visTable = (double *) Vmalloc(sizeof(double) *
_VDefaultWorkContext->depthCueSteps);
k = log(1.0 / (double) _VDefaultWorkContext->depthCueSteps) /
_VDefaultWorkContext->visibility;
#ifdef DEBUG
fprintf(stderr, "k = %lg\n", k);
#endif
for (i = 0; i < _VDefaultWorkContext->depthCueSteps - 1; ++i) {
_VDefaultWorkContext->visTable[i] =
log(1.0 - (double) (i + 1) /
(double) _VDefaultWorkContext->depthCueSteps) / k;
#ifdef DEBUG
fprintf(stderr, "next threshold is %lg units\n",
_VDefaultWorkContext->visTable[i]);
#endif
}
}
int
VComputePolygonColor(Viewport * v, VPolygon * poly)
{
VColor *c;
VPoint *p;
int i;
double d;
/*
* First, are we seeing the front or the back of this polygon?
*/
if (poly->flags & PolyUseBackColor) {
c = poly->backColor;
}
else {
c = poly->color;
}
/*
* If depth queueing isn't turned on, or this color is not a depth-cueued
* color, then simply return the color index.
*/
if ((v->flags & VPDepthCueing) == 0 ||
(c->flags & ColorEnableDepthCueing) == 0) {
return v->pixel[c->cIndex];
}
/*
* Okay, it is a depth cueued color. Check this polygon's distance against
* the different cutoff points for the current world visibility value. If the
* distance is greater than any of the cutoff values, then render the object
* as a pure "haze" color.
*/
else {
if ((i = poly->assignedDepth) > -1) {
return v->pixel[(i < _VDefaultWorkContext->depthCueSteps - 1) ?
c->cIndex + i :
_VDefaultWorkContext->depthCueColor->cIndex];
}
p = &poly->vertex[0];
d = sqrt(p->x * p->x + p->y * p->y + p->z * p->z);
for (i = 0; i < _VDefaultWorkContext->depthCueSteps - 1; ++i) {
if (d < _VDefaultWorkContext->visTable[i]) {
return v->pixel[c->cIndex + i];
}
}
return v->pixel[_VDefaultWorkContext->depthCueColor->cIndex];
}
}
|