游戏开发论坛

 找回密码
 立即注册
搜索
查看: 952|回复: 0

请问关于 hl2 SDK vrad 的代码的问题

[复制链接]

1

主题

3

帖子

9

积分

新手上路

Rank: 1

积分
9
发表于 2007-7-5 14:18:00 | 显示全部楼层 |阅读模式
下面的代码是vrad.dll 中的 lightmap.cpp 中的代码片断,那位朋友能详细帮忙解释下吗?

特别是 luxelToWorldSpace的计算,谢谢了
void CalcFaceVectors(lightinfo_t *l)
{
        texinfo_t        *tex;
        int                        i, j;

        tex = &texinfo[l->face->texinfo];
       
    // move into lightinfo_t
        for (i=0 ; i<2 ; i++)
        {
                for (j=0 ; j<3 ; j++)
                {
                        l->worldToLuxelSpace[j] = tex->lightmapVecsLuxelsPerWorldUnits[j];
                }
        }

        //Solve[ { x * w00 + y * w01 + z * w02 - s == 0, x * w10 + y * w11 + z * w12 - t == 0, A * x + B * y + C * z + D == 0 }, { x, y, z } ]
        //Rule(x,(  C*s*w11 - B*s*w12 + B*t*w02 - C*t*w01 + D*w02*w11 - D*w01*w12) / (+ A*w01*w12 - A*w02*w11 + B*w02*w10 - B*w00*w12 + C*w00*w11 - C*w01*w10 )),
        //Rule(y,(  A*s*w12 - C*s*w10 + C*t*w00 - A*t*w02 + D*w00*w12 - D*w02*w10) / (+ A*w01*w12 - A*w02*w11 + B*w02*w10 - B*w00*w12 + C*w00*w11 - C*w01*w10 )),
        //Rule(z,(  B*s*w10 - A*s*w11 + A*t*w01 - B*t*w00 + D*w01*w10 - D*w00*w11) / (+ A*w01*w12 - A*w02*w11 + B*w02*w10 - B*w00*w12 + C*w00*w11 - C*w01*w10 ))))

        Vector luxelSpaceCross;

        luxelSpaceCross[0] =
                tex->lightmapVecsLuxelsPerWorldUnits[1][1] * tex->lightmapVecsLuxelsPerWorldUnits[0][2] -
                tex->lightmapVecsLuxelsPerWorldUnits[1][2] * tex->lightmapVecsLuxelsPerWorldUnits[0][1];
        luxelSpaceCross[1] =
                tex->lightmapVecsLuxelsPerWorldUnits[1][2] * tex->lightmapVecsLuxelsPerWorldUnits[0][0] -
                tex->lightmapVecsLuxelsPerWorldUnits[1][0] * tex->lightmapVecsLuxelsPerWorldUnits[0][2];
        luxelSpaceCross[2] =
                tex->lightmapVecsLuxelsPerWorldUnits[1][0] * tex->lightmapVecsLuxelsPerWorldUnits[0][1] -
                tex->lightmapVecsLuxelsPerWorldUnits[1][1] * tex->lightmapVecsLuxelsPerWorldUnits[0][0];

        float det = -DotProduct( l->facenormal, luxelSpaceCross );

        // invert the matrix
        l->luxelToWorldSpace[0][0]        = (l->facenormal[2] * l->worldToLuxelSpace[1][1] - l->facenormal[1] * l->worldToLuxelSpace[1][2]) / det;
        l->luxelToWorldSpace[1][0]        = (l->facenormal[1] * l->worldToLuxelSpace[0][2] - l->facenormal[2] * l->worldToLuxelSpace[0][1]) / det;
        l->luxelOrigin[0]                        = -(l->facedist * luxelSpaceCross[0]) / det;
        l->luxelToWorldSpace[0][1]  = (l->facenormal[0] * l->worldToLuxelSpace[1][2] - l->facenormal[2] * l->worldToLuxelSpace[1][0]) / det;
        l->luxelToWorldSpace[1][1]  = (l->facenormal[2] * l->worldToLuxelSpace[0][0] - l->facenormal[0] * l->worldToLuxelSpace[0][2]) / det;
        l->luxelOrigin[1]                        = -(l->facedist * luxelSpaceCross[1]) / det;
        l->luxelToWorldSpace[0][2]  = (l->facenormal[1] * l->worldToLuxelSpace[1][0] - l->facenormal[0] * l->worldToLuxelSpace[1][1]) / det;
        l->luxelToWorldSpace[1][2]  = (l->facenormal[0] * l->worldToLuxelSpace[0][1] - l->facenormal[1] * l->worldToLuxelSpace[0][0]) / det;
        l->luxelOrigin[2]                        = -(l->facedist * luxelSpaceCross[2]) / det;

        // adjust for luxel offset
        VectorMA( l->luxelOrigin, -tex->lightmapVecsLuxelsPerWorldUnits[0][3], l->luxelToWorldSpace[0], l->luxelOrigin );
        VectorMA( l->luxelOrigin, -tex->lightmapVecsLuxelsPerWorldUnits[1][3], l->luxelToWorldSpace[1], l->luxelOrigin );

        // compensate for org'd bmodels
        VectorAdd (l->luxelOrigin, l->modelorg, l->luxelOrigin);
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-25 22:14

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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