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中,有两个过程可以对重复测量资料进行分析:一种是一般线性模型的重复度量:一种是混合线性模型,对于同样的数据资料,使用两种过程分析出的内容不大一样,注意是内容而不是结果,只要操作正确,结果应该 ...
随机推荐
- Fiddler-007-修改HTTP请求响应数据
前文简述了如何通过 Fiddler 修改 HTTP请求 的请求参数,详情请参阅:Fiddler-006-修改HTTP请求参数. 在进行 App 测试时,经常需要修改请求参数,以获得不同的显示效果,以查 ...
- chem01- 添加商品到购物车
1. package selleck.web.cart; import java.io.InputStream; import java.math.BigDecimal; import java.sq ...
- saltstack之(三)认证管理
salt-master和salt-minion之间需要进行认证,认证之后salt-master才能管理salt-minion. 1.在node1:[root@node1 ~]# egrep -v '^ ...
- Android 利用ListView制作带竖线的多彩表格
1.listview与GridView 其实Android本身是有表格控件(GridView)的,但是GridView的每一列的宽度被限定为一样宽,有时设计表格时,列宽不可能为同一宽度,所有可以用Li ...
- H3C交换机配置
h3c 交换机的配置命令 通过 console 连接到交换机 交换机所使用的 console 接口看上去像是一个普通的 RJ45 网卡接口,但是并不能使用普通的网线与 PC 连接 ^_^ .它要通过 ...
- Java开发遇到的问题及解决方案
一.java.lang.OutOfMemoryError 问题:myeclipse 内存不足,又显示内存溢出等问题怎么回事?( java.lang.OutOfMemoryError: PermGen ...
- RTOS
1. http://www.nuttx.org/ 2. http://www.rt-thread.org/page/73.html
- 第十篇 Replication:故障排除
本篇文章是SQL Server Replication系列的第十篇,详细内容请参考原文. 复制故障排除是一项艰巨的任务.在任何复制设置中,都涉及到很多移动部件,而可用的工具并不总是很容易识别问题.Th ...
- Emacs 列编辑
copy from http://chandlewei.blogbus.com/logs/15583440.html 不敢独享,与大家分享.也可以在Emacs中用C-x C-h列出全部命令,查找C-x ...
- 【转】Tomcat7启动的总过程 (有时间自己写下tomcat8的)
首先,说明tomcat8和tomcat7的启动过程不一样,这篇是针对tomcat7的. Tomcat启动的总过程 通过上面的介绍,我们总体上清楚了各个组件的生命周期的各个阶段具体都是如何运作的.接下来 ...