PDA

View Full Version : Creating shadow

enne87
04-03-2009, 02:22 PM
Hi guys!

I'd like to throw a shadow of a teacup.
I've implemented three methods: drawPlanes(), setShadowMat() and display().

drawPlanes() draws two planes: One parallel to the xy-plane and one parallel to the xz-plane respectively.

First plane (xy) is:

Gl.glVertex3f(-20.0f, -20.0f, -3.0f);
Gl.glVertex3f(20.0f, -20.0f, -3.0f);
Gl.glVertex3f(20.0f, 20.0f, -3.0f);
Gl.glVertex3f(-20.0f, 20.0f, -3.0f);

Consequently, the normalvector for the xy-plane is [0,0,1] and xz [0,1,0].

Now I'd like to create the plane equation: A*Px + B*Py + C*Pz + D = 0
A=Nx, B=Ny, C=Nz, D=-(A*Px+B*Py+C*Pz), so for the first plane A = 0, B = 0 , C = 1 and D = 3, right?

Cheers, enne

enne87
04-05-2009, 07:39 AM
Ok, I think it is not so clear what my problem is.
Anyway, I'm sure that my plane equation is ok.

I've got one problem: The teapot and the xz-plane are rendered perfectly, only my shadow makes some problems.

Instead of throwing a shadow of the teapot on the xz-plane, the whole plane is colored black.
I think it is a problem with the lighting, but I can't see any mistakes.

Here's the method where my plane and my teapot are displayed:

private static void Display()
{
float[] red={1.0f, 0.0f, 0.0f, 1.0f};
float[] planeEq=new float[4];

Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
DrawPlanes();
Gl.glPushMatrix();
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_DIFFUSE, red);
Glut.glutSolidTeapot(2);
Gl.glPopMatrix();

//use displacement for shadow projection plane
//to avoid z-buffer artifacts
//...

///test

planeEq[0] = 0;
planeEq[1] = 1;
planeEq[2] = 0;
planeEq[3] = 3;

Gl.glPushMatrix();

//Disable lighting and set shadow-color (black)

Gl.glDisable(Gl.GL_LIGHTING);
Gl.glColor3f(0f, 0f, 0f);

//re-draw objects
DrawPlanes();
Glut.glutSolidTeapot(2);

//enable lighting
Gl.glEnable(Gl.GL_LIGHTING);

Gl.glPopMatrix();

Glut.glutSwapBuffers();
}

Can anyone please tell me what I'm doing wrong?

Best regards,

enne