游戏开发论坛

 找回密码
 立即注册
搜索
查看: 5426|回复: 10

问题:图形学中的影子 OGL描述

[复制链接]

37

主题

727

帖子

740

积分

高级会员

Rank: 4

积分
740
发表于 2005-2-27 12:23:00 | 显示全部楼层 |阅读模式
今天看OGL超级宝典时遇到困难
求3D飞机的2D影子
书上没多加描述,只有代码
我没有图形知识,请各位朋友指导一下

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];
        }

这是求影子的代码
destMat是什么
DOT应该是x轴上的偏移
它又是怎么求的
planeCoeff[3]是什么

谢谢~

37

主题

727

帖子

740

积分

高级会员

Rank: 4

积分
740
 楼主| 发表于 2005-2-27 12:24:00 | 显示全部楼层

Re: 问题:图形学中的影子 OGL描述

代码

PS:能讲详细点最好,谢谢

sf_200522712242.rar

3.74 KB, 下载次数:

63

主题

871

帖子

891

积分

高级会员

Rank: 4

积分
891
QQ
发表于 2005-2-27 13:23:00 | 显示全部楼层

Re:问题:图形学中的影子 OGL描述

呵呵,头像都改了

59

主题

1104

帖子

1199

积分

金牌会员

Rank: 6Rank: 6

积分
1199
发表于 2005-2-27 14:04:00 | 显示全部楼层

Re:问题:图形学中的影子 OGL描述

这是阴影矩阵的推倒,在D3D里面有封装好的。
原理是根据一个点和一个面的法线来确定一个平面,然后根据光的位置来生成一个矩阵,目的是让空间内的任意点乘过这个矩阵之后都会落在同一个平面上。

37

主题

727

帖子

740

积分

高级会员

Rank: 4

积分
740
 楼主| 发表于 2005-2-27 16:08:00 | 显示全部楼层

Re:问题:图形学中的影子 OGL描述

to tarkey:

谢谢,看来我还要去学学线性代数和图形学


to Quest:

我的人也随着我的头像,变了....

37

主题

727

帖子

740

积分

高级会员

Rank: 4

积分
740
 楼主| 发表于 2005-2-27 16:24:00 | 显示全部楼层

Re:问题:图形学中的影子 OGL描述

对了
还要多谢次tarkey....

只因你一句话....恩....
Bless you...

31

主题

630

帖子

635

积分

高级会员

Rank: 4

积分
635
发表于 2005-2-27 17:47:00 | 显示全部楼层

Re:问题:图形学中的影子 OGL描述

qingbuyaobianchengjiangou

31

主题

630

帖子

635

积分

高级会员

Rank: 4

积分
635
发表于 2005-2-27 21:10:00 | 显示全部楼层

Re:问题:图形学中的影子 OGL描述

欢迎你!!!

可是改一下图标吧,好别扭呀!

37

主题

727

帖子

740

积分

高级会员

Rank: 4

积分
740
 楼主| 发表于 2005-2-27 21:39:00 | 显示全部楼层

Re: Re:问题:图形学中的影子 OGL描述

fujingqiu: Re:问题:图形学中的影子 OGL描述

欢迎你!!!

可是改一下图标吧,好别扭呀!


我变了

其实做一条好狗,比做一个人难,难很多

59

主题

1104

帖子

1199

积分

金牌会员

Rank: 6Rank: 6

积分
1199
发表于 2005-2-27 21:56:00 | 显示全部楼层

Re:问题:图形学中的影子 OGL描述

唉,最近呆得郁闷,哪位知道还有什么公司在招人的,麻烦告诉我一下,打算换地儿工作了。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-12-24 12:49

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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