OpenGL inadvertently see two ways to create a projection matrix, you can say that they do the same function, but the wording is completely different, you can observe what is called the best of the same ...
The first type:
The Gltmakeshadowmatrix function is the focus
1 //Gets The three coefficients of a plane equation given three points on the plane.2 voidgltgetplaneequation (GLTVector3 vPoint1, GLTVector3 vPoint2, GLTVector3 vPoint3, GLTVector3 vplane)3 {4 //Get normal vector from three points. The normal vector is the first three coefficients5 //To the plane equation ...6 Gltgetnormalvector (VPoint1, VPoint2, VPoint3, Vplane);7 8 //Final coefficient found by substitution9vplane[3] =-(vplane[0] * vpoint3[0] + vplane[1] * vpoint3[1] + vplane[2] * vpoint3[2]);Ten } One A voidGltmakeshadowmatrix (GLTVector3 vpoints[3], GLTVector4 vlightpos, Gltmatrix Destmat) - { - GLTVector4 vplaneequation; the glfloat dot; - -Gltgetplaneequation (vpoints[0], vpoints[1], vpoints[2], vplaneequation); - + //Dot product of plane and light position -Dot = vplaneequation[0]*vlightpos[0] + +vplaneequation[1]*vlightpos[1] + Avplaneequation[2]*vlightpos[2] + atvplaneequation[3]*vlightpos[3]; - - - //Now do the projection - //First column -destmat[0] = dot-vlightpos[0] * vplaneequation[0]; indestmat[4] =0.0f-vlightpos[0] * vplaneequation[1]; -destmat[8] =0.0f-vlightpos[0] * vplaneequation[2]; todestmat[ A] =0.0f-vlightpos[0] * vplaneequation[3]; + - //Second Column thedestmat[1] =0.0f-vlightpos[1] * vplaneequation[0]; *destmat[5] = dot-vlightpos[1] * vplaneequation[1]; $destmat[9] =0.0f-vlightpos[1] * vplaneequation[2];Panax Notoginsengdestmat[ -] =0.0f-vlightpos[1] * vplaneequation[3]; - the //Third Column +destmat[2] =0.0f-vlightpos[2] * vplaneequation[0]; Adestmat[6] =0.0f-vlightpos[2] * vplaneequation[1]; thedestmat[Ten] = dot-vlightpos[2] * vplaneequation[2]; +destmat[ -] =0.0f-vlightpos[2] * vplaneequation[3]; - $ //Fourth Column $destmat[3] =0.0f-vlightpos[3] * vplaneequation[0]; -destmat[7] =0.0f-vlightpos[3] * vplaneequation[1]; -destmat[ One] =0.0f-vlightpos[3] * vplaneequation[2]; thedestmat[ the] = dot-vlightpos[3] * vplaneequation[3]; -}
View Code
1 //Given three points on a plane in counter clockwise order, calculate the unit normal2 voidGltgetnormalvector (ConstGLTVector3 vP1,ConstGLTVector3 vP2,ConstGLTVector3 vP3, GLTVector3 vnormal)3 {4 GLTVector3 vV1, vV2;5 6 gltsubtractvectors (vP2, vP1, vV1);7 gltsubtractvectors (vP3, vP1, vV2);8 9 gltvectorcrossproduct (vV1, vV2, vnormal);Ten Gltnormalizevector (vnormal); One}
View Code
The second type:
The Createshadowmatrix function is the focus
1 The second Kind2 /** Create a projection matrix*/3 voidCplanarshadow::createshadowmatrix (floatm[ -], Vector3 Point, Vector3 Normal,floatlp[4])4 {5 /** Calculate the distance from the vertex to the plane*/6 floatD =-((normal.x * point.x) + (NORMAL.Y * point.y) + (NORMAL.Z *point.z));7 8 /** Calculate dot product of light source vector and normal vector*/9 floatDot = normal.x*lp[0] + normal.y*lp[1] + normal.z*lp[2] + d*lp[3];Ten One /** Set matrix element values*/ Am[0] = dot-lp[0]*normal.x; m[1] =-lp[1]*normal.x; m[2] =-lp[2]*normal.x; m[3] =-lp[3]*normal.x; -m[4] =-lp[0]*NORMAL.Y; m[5] = dot-lp[1]*NORMAL.Y; m[6] =-lp[2]*NORMAL.Y; m[7] =-lp[3]*normal.y; -m[8] =-lp[0]*normal.z; m[9] =-lp[1]*normal.z; m[Ten] = dot-lp[2]*normal.z; m[ One] =-lp[3]*normal.z; them[ A] =-lp[0]*d; m[ -] =-lp[1]*d; m[ -] =-lp[2]*d; m[ the] = dot-lp[3]*D; -}
View Code
Two functions of calculating projection matrices in OpenGL