|
|
有谁能理解这个函数的意义的?给我解答,我送出小礼物
// this builds a basis map
// the basis maps will be interleaved, or we will pack 3 of them into one texture
// (we could pack 4, but we can't use the alpha channel in our dot multiplies)
// but we will assume that the u,v represent the angle with respect to the center of the
// of the texture (.5,.5), So if we want the basis function for the light vector
// (1,.5) we'd look at the point (1,.75)
VOID ShadowSet::BuildBasisMap(BYTE *pBasis,FLOAT PrimAngle,FLOAT fAngle2)
{
INT x,y;
FLOAT fEndX,fEndY,fAngle,fPercent;
FLOAT u,v,dot,nx,ny,fsq;
BYTE *pCurLine;
u = cosf(PrimAngle);
v = sinf(PrimAngle);
for(y = 0;y < BASISMAPSIZE;y++)
{
pCurLine = &pBasis[y*BASISMAPSIZE];
for(x = 0;x < BASISMAPSIZE;x++)
{
fEndX = x - .5f*BASISMAPSIZE;
fEndY = y - .5f*BASISMAPSIZE;
//take the dot product of the normalized vectors
fsq = sqrtf(fEndX*fEndX+fEndY*fEndY);
if(fsq == 0)
{
fPercent = 255;//128;
}
else
{
// we remember our definiton of dot product,
// cos(Angle) = DotProduct of Normalzed vectors
// so Angle = acos(DotProduct)
nx = fEndX/fsq;
ny = fEndY/fsq;
dot = nx*u + ny*v;
if( dot < -1.0f )
dot = -1.0f;
if( dot > 1.0f )
dot = 1.0f;
fAngle = acosf(dot);
if(fabs(fAngle) < fAngle2)
{
/*
//if (fAngle==0)
fPercent = 128 + fabsf(fAngle-fAngle2)*127/fAngle2;
if(fPercent>255)
fPercent=255;
*/
//fPercent = 128;
}
else
{
fPercent = 128;
}
}
*pCurLine = (BYTE)fPercent;
pCurLine++ ;
}
}
}
|
|