I know a bit about 3D transformation matrices (scale, rotation,

rotation) already. But as I study OpenGL, I found in the text book a

matrix transform that creates the shadow of any 3D shape against a plane.

In other words, this computes a perspective projection against an

oblique projection plane. What surprises me is that the transformed

object is flat (2D).

Below is the function that derives the matrix. The points parameters

represent the projection plane. Parameter lightPos is the position of

the spotlight (last parameter is the output matrix).

The question is: how does that work? Any references?

(answer by Email)

thanks

************

void MakeShadowMatrix(GLfloat points[3][3], GLfloat lightPos[4], GLfloat

destMat[4][4])

{

GLfloat planeCoeff[4];

GLfloat dot;

// Find the plane equation coefficients

// (plane normal as a unit vector)

calcNormal(points,planeCoeff);

// the equation of a plane passing through P(x0,y0,z0)

// with a normal N(a,b,c) is

// a(x) + b(y) + c(z) = (a(x0)+b(y0)+c(z0))

// 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];

Quote:}