## QUESTION: 3D transform matrices

### QUESTION: 3D transform matrices

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?

thanks

************
void MakeShadowMatrix(GLfloat points, GLfloat lightPos, GLfloat
destMat)
{
GLfloat planeCoeff;
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 = - (
(planeCoeff*points) +
(planeCoeff*points) +
(planeCoeff*points)
);

// Dot product of plane and light position
dot = planeCoeff * lightPos +
planeCoeff * lightPos +
planeCoeff * lightPos +
planeCoeff * lightPos;

// Now do the projection
// First column
destMat = dot - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;

// Second column
destMat = 0.0f - lightPos * planeCoeff;
destMat = dot - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;

// Third Column
destMat = 0.0f - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;
destMat = dot - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;

// Fourth Column
destMat = 0.0f - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;
destMat = 0.0f - lightPos * planeCoeff;
destMat = dot - lightPos * planeCoeff;

Quote:}

### QUESTION: 3D transform matrices

Better than absolutely any book is experience.
I suggest you do the following, which tought me
a great deal on how these things work.

set up a window and its callbacks for keyboard input
( glutCreateWindow and glutKeyboardFunc etc )

have a global matrix GLfloat mat;
initially set it to Identity,( you may want to set the ' I ' key to do
this )
and lock 16 other keys to the values of the matrix.
f.i. 'q' = mat-=0.01; 'Q' = mat-=0.01; 'a' = mat-=0.01; etc.
and print out the values of the matrix on each change into the console.

then on idle callback, draw a cube through this matrix like

glMatrixMode(GL_PROJECTION)
glutSolidCube(1.0);

and you can interactively see what happens.
sort of empirical programming, this is. : )

Jonathan

Quote:

> 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?

> thanks

> ************
> void MakeShadowMatrix(GLfloat points, GLfloat lightPos, GLfloat
> destMat)
> {
> GLfloat planeCoeff;
> 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 = - (
> (planeCoeff*points) +
> (planeCoeff*points) +
> (planeCoeff*points)
> );

> // Dot product of plane and light position
> dot = planeCoeff * lightPos +
> planeCoeff * lightPos +
> planeCoeff * lightPos +
> planeCoeff * lightPos;

> // Now do the projection
> // First column
> destMat = dot - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;

> // Second column
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = dot - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;

> // Third Column
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = dot - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;

> // Fourth Column
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = 0.0f - lightPos * planeCoeff;
> destMat = dot - lightPos * planeCoeff;
> }