Esempio n. 1
0
void Lighting::gltMakeShadowMatrix(GLTVector3 vPoints[3], GLTVector4 vLightPos, GLTMatrix destMat)
{
	  GLTVector4 vPlaneEquation;
	  GLfloat dot;
  
	  gltGetPlaneEquation(vPoints[0], vPoints[1], vPoints[2], vPlaneEquation);
  
	  dot =  vPlaneEquation[0]*vLightPos[0] + 
			 vPlaneEquation[1]*vLightPos[1] + 
			 vPlaneEquation[2]*vLightPos[2] + 
			 vPlaneEquation[3]*vLightPos[3];
  
	  destMat[0]  = dot  - vLightPos[0] * vPlaneEquation[0];
	  destMat[4]  = 0.0f - vLightPos[0] * vPlaneEquation[1];
	  destMat[8]  = 0.0f - vLightPos[0] * vPlaneEquation[2];
	  destMat[12] = 0.0f - vLightPos[0] * vPlaneEquation[3];
  
	  destMat[1]  = 0.0f - vLightPos[1] * vPlaneEquation[0];
	  destMat[5]  = dot  - vLightPos[1] * vPlaneEquation[1];
	  destMat[9]  = 0.0f - vLightPos[1] * vPlaneEquation[2];
	  destMat[13] = 0.0f - vLightPos[1] * vPlaneEquation[3];
  
	  destMat[2]  = 0.0f - vLightPos[2] * vPlaneEquation[0];
	  destMat[6]  = 0.0f - vLightPos[2] * vPlaneEquation[1];
	  destMat[10] = dot  - vLightPos[2] * vPlaneEquation[2];
	  destMat[14] = 0.0f - vLightPos[2] * vPlaneEquation[3];
  
	  destMat[3]  = 0.0f - vLightPos[3] * vPlaneEquation[0];
	  destMat[7]  = 0.0f - vLightPos[3] * vPlaneEquation[1];
	  destMat[11] = 0.0f - vLightPos[3] * vPlaneEquation[2];
	  destMat[15] = dot  - vLightPos[3] * vPlaneEquation[3];
}
Esempio n. 2
0
// Creates a shadow projection matrix out of the plane equation
// coefficients and the position of the light. The return value is stored
// in destMat
void gltMakeShadowMatrix(GLTVector3 vPoints[3], GLTVector4 vLightPos, GLTMatrix destMat)
    {
    GLTVector4 vPlaneEquation;
    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] + 
            vPlaneEquation[2]*vLightPos[2] + 
            vPlaneEquation[3]*vLightPos[3];

    
    // Now do the projection
    // First column
    destMat[0] = dot - vLightPos[0] * vPlaneEquation[0];
    destMat[4] = 0.0f - vLightPos[0] * vPlaneEquation[1];
    destMat[8] = 0.0f - vLightPos[0] * vPlaneEquation[2];
    destMat[12] = 0.0f - vLightPos[0] * vPlaneEquation[3];

    // Second column
    destMat[1] = 0.0f - vLightPos[1] * vPlaneEquation[0];
    destMat[5] = dot - vLightPos[1] * vPlaneEquation[1];
    destMat[9] = 0.0f - vLightPos[1] * vPlaneEquation[2];
    destMat[13] = 0.0f - vLightPos[1] * vPlaneEquation[3];

    // Third Column
    destMat[2] = 0.0f - vLightPos[2] * vPlaneEquation[0];
    destMat[6] = 0.0f - vLightPos[2] * vPlaneEquation[1];
    destMat[10] = dot - vLightPos[2] * vPlaneEquation[2];
    destMat[14] = 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[11] = 0.0f - vLightPos[3] * vPlaneEquation[2];
    destMat[15] = dot - vLightPos[3] * vPlaneEquation[3];
    }