PDA

View Full Version : Casting a shadow on X-Y plane



Lindie
04-08-2012, 04:05 AM
I am trying to cast in my program a shadow from a character on X-Y plane on which I added a texture, however the shadow does not show up. Is it possible that the texture used for the surface is replacing the shadow?

X is directed to the right, Z is down and Y is directed to me

I wonder if I have something wrong in my code.

void draw_lights ()
{
float Xs = 0.0, Ys=800.0, Zs=-1300.0;
GLfloat light1PosType[] = {Xs, Ys, Zs, 1.0};
glLightfv(GL_LIGHT1, GL_POSITION, light1PosType);
glEnable(GL_LIGHT1);


GLfloat M[4][4];
for (int i=0; i<4; i++)
for (int j=0; j<4; j++)
M[i][j] = 0;
M[0][0]=M[1][1]=M[2][2]=1;
M[2][3]=-1.0/Zs;

glPushMatrix ();

glTranslatef(Xs, Ys, Zs); //Mwc<-s
glMultMatrixf(M[4]); // perspective character
glTranslatef(-Xs, -Ys, -Zs); //Ms<-wc

glColor3ub(55, 47, 37);
draw_character ();

glPopMatrix ();
}

void draw_scene (){

...

////////////////////////////////////////////////////////////////////////
/// Setting Character //////
////////////////////////////////////////////////////////////////////////

glTranslatef(0.0, 0.0, -(240.0+48.5+16.5));
draw_character ();


////////////////////////////////////////////////////////////////////////
/// Setting Floor parameters //////
////////////////////////////////////////////////////////////////////////
glTranslatef(0.0, 0.0, 240.0+48.5+16.5); // positioned at Z=0
drawing_floor ( );

////////////////////////////////////////////////////////////////////////
/// Setting Lights and shadows //////
////////////////////////////////////////////////////////////////////////
draw_lights ();
...
}

Thank you for your time !! OpenGL is so great that's why I really want to know more !!