游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2704|回复: 6

[求助]关于阴影最基本算法: 压扁物体到一个平面上 的理解

[复制链接]

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2006-8-16 13:29:00 | 显示全部楼层 |阅读模式
本人是初学者 最近在看超级宝典 的第六章里面对阴影的产生的介绍  对里面的用矩阵求系数的方法不是很理解  希望能得到帮助  原码如下


// Creates a shadow projection matrix out of the plane equation
// coefficients and the position of the light. The return value is stored
// in destMat[][]
void MakeShadowMatrix(GLfloat points[3][3], GLfloat lightPos[4], GLfloat destMat[4][4])
        {
        GLfloat planeCoeff[4];
        GLfloat dot;

        // Find the plane equation coefficients
        // Find the first three coefficients the same way we
        // find a normal.
        calcNormal(points,planeCoeff);

        // Find the last coefficient by back substitutions
        planeCoeff[3] = - (
                (planeCoeff[0]*points[2][0]) + (planeCoeff[1]*points[2][1]) +
                (planeCoeff[2]*points[2][2]));


        // Dot product of plane and light position
        dot = planeCoeff[0] * lightPos[0] +
                        planeCoeff[1] * lightPos[1] +
                        planeCoeff[2] * lightPos[2] +
                        planeCoeff[3] * lightPos[3];

        // Now do the projection
        // First column
    destMat[0][0] = dot - lightPos[0] * planeCoeff[0];
    destMat[1][0] = 0.0f - lightPos[0] * planeCoeff[1];
    destMat[2][0] = 0.0f - lightPos[0] * planeCoeff[2];
    destMat[3][0] = 0.0f - lightPos[0] * planeCoeff[3];

        // Second column
        destMat[0][1] = 0.0f - lightPos[1] * planeCoeff[0];
        destMat[1][1] = dot - lightPos[1] * planeCoeff[1];
        destMat[2][1] = 0.0f - lightPos[1] * planeCoeff[2];
        destMat[3][1] = 0.0f - lightPos[1] * planeCoeff[3];

        // Third Column
        destMat[0][2] = 0.0f - lightPos[2] * planeCoeff[0];
        destMat[1][2] = 0.0f - lightPos[2] * planeCoeff[1];
        destMat[2][2] = dot - lightPos[2] * planeCoeff[2];
        destMat[3][2] = 0.0f - lightPos[2] * planeCoeff[3];

        // Fourth Column
        destMat[0][3] = 0.0f - lightPos[3] * planeCoeff[0];
        destMat[1][3] = 0.0f - lightPos[3] * planeCoeff[1];
        destMat[2][3] = 0.0f - lightPos[3] * planeCoeff[2];
        destMat[3][3] = dot - lightPos[3] * planeCoeff[3];
        }

18

主题

971

帖子

982

积分

高级会员

Rank: 4

积分
982
发表于 2006-8-16 14:20:00 | 显示全部楼层

Re:[求助]关于阴影最基本算法: 压扁物体到一个平面上 的

平面阴影,意义不太大.

54

主题

2916

帖子

3765

积分

论坛元老

Rank: 8Rank: 8

积分
3765
QQ
发表于 2006-8-16 17:11:00 | 显示全部楼层

Re:[求助]关于阴影最基本算法: 压扁物体到一个平面上 的

这样的阴影不好。

89

主题

4036

帖子

4132

积分

论坛元老

Rank: 8Rank: 8

积分
4132
发表于 2006-8-16 17:44:00 | 显示全部楼层

Re:[求助]关于阴影最基本算法: 压扁物体到一个平面上 的

是不好。

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2006-8-17 12:55:00 | 显示全部楼层

Re:[求助]关于阴影最基本算法: 压扁物体到一个平面上 的

只是想搞清楚 里面包含的线性代数与几何学 的原理    谁能 解释 一下

89

主题

4036

帖子

4132

积分

论坛元老

Rank: 8Rank: 8

积分
4132
发表于 2006-8-17 13:35:00 | 显示全部楼层

Re:[求助]关于阴影最基本算法: 压扁物体到一个平面上 的

那个matrix自己去推导一下就可以了。谁有功夫把他写出来啊。

5

主题

686

帖子

697

积分

高级会员

Rank: 4

积分
697
QQ
发表于 2006-8-18 17:38:00 | 显示全部楼层

Re:[求助]关于阴影最基本算法: 压扁物体到一个平面上 的

几何原理无非就是计算光源到顶点向量,与指定平面相交于何处,推导出计算公式之后就可以写成矩阵形式了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-25 03:44

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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