OpenGL中两种计算投影矩阵的函数
OpenGL无意间同时看到两种创建投影矩阵的写法,可以说它们完成的是同样的功能,但写法完全不同,可以观摩一下什么叫做异曲同工之妙...
第一种:
gltMakeShadowMatrix函数是重点
// Gets the three coefficients of a plane equation given three points on the plane.
void gltGetPlaneEquation(GLTVector3 vPoint1, GLTVector3 vPoint2, GLTVector3 vPoint3, GLTVector3 vPlane)
{
// Get normal vector from three points. The normal vector is the first three coefficients
// to the plane equation...
gltGetNormalVector(vPoint1, vPoint2, vPoint3, vPlane); // Final coefficient found by back substitution
vPlane[] = -(vPlane[] * vPoint3[] + vPlane[] * vPoint3[] + vPlane[] * vPoint3[]);
} void gltMakeShadowMatrix(GLTVector3 vPoints[], GLTVector4 vLightPos, GLTMatrix destMat)
{
GLTVector4 vPlaneEquation;
GLfloat dot; gltGetPlaneEquation(vPoints[], vPoints[], vPoints[], vPlaneEquation); // Dot product of plane and light position
dot = vPlaneEquation[]*vLightPos[] +
vPlaneEquation[]*vLightPos[] +
vPlaneEquation[]*vLightPos[] +
vPlaneEquation[]*vLightPos[]; // Now do the projection
// First column
destMat[] = dot - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[]; // Second column
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = dot - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[]; // Third Column
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = dot - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[]; // Fourth Column
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = 0.0f - vLightPos[] * vPlaneEquation[];
destMat[] = dot - vLightPos[] * vPlaneEquation[];
}
// Given three points on a plane in counter clockwise order, calculate the unit normal
void gltGetNormalVector(const GLTVector3 vP1, const GLTVector3 vP2, const GLTVector3 vP3, GLTVector3 vNormal)
{
GLTVector3 vV1, vV2; gltSubtractVectors(vP2, vP1, vV1);
gltSubtractVectors(vP3, vP1, vV2); gltVectorCrossProduct(vV1, vV2, vNormal);
gltNormalizeVector(vNormal);
}
第二种:
CreateShadowMatrix函数是重点
第二种
/** 创建投射矩阵 */
void CPlanarShadow::CreateShadowMatrix(float m[], Vector3 point, Vector3 normal, float lp[])
{
/** 计算顶点到平面的距离 */
float d = - ((normal.x * point.x) + (normal.y * point.y) + (normal.z * point.z)); /** 计算光源向量和法向量的点积 */
float dot = normal.x*lp[] + normal.y*lp[] + normal.z*lp[] + d*lp[]; /** 设置矩阵元素值 */
m[] = dot - lp[]*normal.x; m[] = -lp[]*normal.x; m[] = -lp[]*normal.x; m[] = -lp[]*normal.x;
m[] = -lp[]*normal.y; m[] = dot -lp[]*normal.y; m[] = -lp[]*normal.y; m[] = -lp[]*normal.y;
m[] = -lp[]*normal.z; m[] = -lp[]*normal.z; m[] = dot - lp[]*normal.z; m[] = -lp[]*normal.z;
m[] = -lp[]*d; m[] = -lp[]*d; m[] = -lp[]*d; m[] = dot -lp[]*d;
}
OpenGL中两种计算投影矩阵的函数的更多相关文章
- JavaScript中两种类型的全局对象/函数【转】
Snandy Stop, thinking is the essence of progress. JavaScript中两种类型的全局对象/函数 这里所说的JavaScript指浏览器环境中的包括宿 ...
- JavaScript中两种类型的全局对象/函数
这里所说的JavaScript指浏览器环境中的包括宿主环境在内的. 第一种是ECMAScript Global Object,第二种是宿主环境(Host)下的全局对象/函数. 一.核心JavaScri ...
- 两种计算Java对象大小的方法
之前想研究一下unsafe类,碰巧在网上看到了这篇文章,觉得写得很好,就转载过来.原文出处是: http://blog.csdn.net/iter_zc/article/details/4182271 ...
- jsp中两种include的区别【转】
引用文章:http://www.ibm.com/developerworks/cn/java/j-jsp04293/ http://www.cnblogs.com/lazycoding/archive ...
- OC中两种单例实现方式
OC中两种单例实现方式 写在前面 前两天探索了一下C++ 的单例,领悟深刻了许多.今天来看看OC中的单例又是怎么回事.查看相关资料,发现在OC中一般有两种实现单例的方式,一种方式是跟C++ 中类似的常 ...
- JAVA 中两种判断输入的是否是数字的方法__正则化_
JAVA 中两种判断输入的是否是数字的方法 package t0806; import java.io.*; import java.util.regex.*; public class zhengz ...
- 关于js中两种定时器的设置及清除(转载)
1.JS中的定时器有两种: window.setTimeout([function],[interval]) 设置一个定时器,并且设定了一个等待的时间[interval],当到达时间后,执行对应的方法 ...
- mybatis中两种取值方式?谈谈Spring框架理解?
1.mybatis中两种取值方式? 回答:Mybatis中取值方式有几种?各自区别是什么? Mybatis取值方式就是说在Mapper文件中获取service传过来的值的方法,总共有两种方式,通过 $ ...
- SPSS中两种重复测量资料分析过程的比较
在SPSS中,有两个过程可以对重复测量资料进行分析:一种是一般线性模型的重复度量:一种是混合线性模型,对于同样的数据资料,使用两种过程分析出的内容不大一样,注意是内容而不是结果,只要操作正确,结果应该 ...
随机推荐
- MVC在VIEW中动态控制htmlAttributes和routevalues的方法
在项目中有一个Html.DropDownListFor放在一个分部视图中,然后调用这个分部视图时需要动态控制这个DropDownList的显示方式,比如宽度.是否禁用.是否列表等,这些值的设置都在Ht ...
- Java学习-010-创建文件夹源代码
此文源码主要为应用 Java 创建文件目录的源码.若有不足之处,敬请大神指正,不胜感激! 创建文件夹源代码如下所示: /** * @function 文件操作:创建文件夹.若文件夹不存在,则级联创建文 ...
- JavaScript实现在页面上的文本框中输入小写字母自动变为大写字母
<script language="javascript" type="text/javascript"> $(function () { $(&q ...
- busybox rx 命令
rx命令使用xmodem传送文件,只需要串口线就传送. 在文件系统输入如下命令,传送文件到板子上,板子上保存文件的名称为file rx file 在secureCRT中选择Transfer->S ...
- http文件的断点续传和下载
http://www.tuicool.com/articles/ZbyymqJ Content-Disposition:inline; filename= "c501b_01_h264_sd ...
- c# 并行运算
c# 并行运算 1. Parallel.INVOKE() 看实例: private static Stopwatch watch = new Stopwatch(); private static v ...
- 构造方法后面加上了:base
今天看公司软件的代码碰到一个奇怪的方法 ,寻早了各种方法后终于明白了,在构造方法后面加上了:base(message),该类如下: public NONEDIException(string mess ...
- linux查看公网地址
curl cip.cc curl http://members.3322.org/dyndns/getip
- 音乐播放器 AVAudioPlayer、定时器、UISlider
#import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface ViewController ...
- css 正方体
<!DOCTYPE html><html lang="zh-cmn-Hans"><head><meta charset="utf ...