|
|
今天看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]是什么
谢谢~ |
|