Hi everyone,
I try to make shadow cast of an object. I started with a simple element of the shadow casting method - trying to draw the objects projection on a plane. But something is going wrong. The scene is total mess with arbitrary directed planes stretching to infinity which obviously is not expected.
//Here is my code that retrieves the shadow matrix:
void shadowMatrix(GLfloat m[][4],
GLfloat plane[],
GLfloat light[])
{
GLfloat dot = plane[0]*light[0] + plane[1]*light[1] +
plane[2]*light[2] + plane[3]*light[3];
m[0][0] = dot - light[0]*plane[0];
m[1][0] = - light[0]*plane[1];
m[2][0] = - light[0]*plane[2];
m[3][0] = - light[0]*plane[3];
m[0][1] = - light[1]*plane[0];
m[1][1] = dot - light[1]*plane[1];
m[2][1] = - light[1]*plane[2];
m[3][1] = - light[1]*plane[3];
m[0][2] = - light[2]*plane[0];
m[1][2] = - light[2]*plane[1];
m[2][2] = dot - light[2]*plane[2];
m[3][2] = - light[2]*plane[3];
m[0][3] = - light[3]*plane[0];
m[1][3] = - light[3]*plane[1];
m[2][3] = - light[3]*plane[2];
m[3][3] = dot - light[3]*plane[3];
}
//And here is the code that draws the scene
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -20.0f);
GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
GLfloat lightColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat lightPos[] = {-2 * BOX_SIZE, BOX_SIZE, 4 * BOX_SIZE, 1.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
//glRotatef(20, 1.0, 0.0, 0.0);
glPushMatrix();
GLfloat matrix [4][4];
GLfloat groundPlaneEquation[4] = { 0.0, 1.0, 0.0, BOX_SIZE/2};
// Compute matrix based on light position and ground plane
// equation. See Appendix B.
shadowMatrix(matrix, lightPos, groundPlaneEquation);
glMultMatrixf(&matrix[0][0]);
drawCube();
//drawPlane();
glPopMatrix();
glutSwapBuffers();
}
Any help will be appreciated. Thanx