游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1214|回复: 1

(有奖励)关于ShadowSet::BuildBasisMap的问题

[复制链接]

10

主题

69

帖子

69

积分

注册会员

Rank: 2

积分
69
发表于 2006-5-1 09:34:00 | 显示全部楼层 |阅读模式
有谁能理解这个函数的意义的?给我解答,我送出小礼物
// 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++ ;
        }
    }
}

132

主题

1341

帖子

1341

积分

金牌会员

Rank: 6Rank: 6

积分
1341
发表于 2006-5-2 18:08:00 | 显示全部楼层

Re:(有奖励)关于ShadowSet::BuildBasisMap的问题

你先说什么奖励
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-24 10:07

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表