Unexpected results for projection on to plane
        Posted  
        
            by 
                ravenspoint
            
        on Game Development
        
        See other posts from Game Development
        
            or by ravenspoint
        
        
        
        Published on 2012-11-27T18:36:36Z
        Indexed on 
            2012/11/27
            23:32 UTC
        
        
        Read the original article
        Hit count: 380
        
opengl
I want to use this projection matrix:
GLfloat shadow[] = { 
    -1,0,0,0,
    1,0,-1,1,
    0,0,-1,0,
    0,0,0,-1 };
It should cast object shadows onto the y = 0 plane from a point light at 1,1,-1.
I create a rectangle in the x = 0.5 plane
    glBegin( GL_QUADS );
    glVertex3f( 0.5,0.2,-0.5);
    glVertex3f( 0.5,0.2,-1.5);
    glVertex3f( 0.5,0.5,-1.5);
    glVertex3f( 0.5,0.5,-0.5);
    glEnd();
Now if I manually multiply these vertices with the matrix, I get.
    glBegin( GL_QUADS );
    glVertex3f( 0.375,0,-0.375);
    glVertex3f( 0.375,0,-1.625);
    glVertex3f( 0,0,-2);
    glVertex3f( 0,0,0);
    glEnd();
Which produces a reasonable display ( camera at 0,5,0 looking down y axis )

So rather than do the calculation manually, I should be able to use the opengl model transormation. I write this code:
    glMatrixMode (GL_MODELVIEW);
      GLfloat shadow[] = { 
    -1,0,0,0,
    1,0,-1,1,
    0,0,-1,0,
    0,0,0,-1 };
    glLoadMatrixf( shadow );
    glBegin( GL_QUADS );
    glVertex3f( 0.5,0.2,-0.5);
    glVertex3f( 0.5,0.2,-1.5);
    glVertex3f( 0.5,0.5,-1.5);
    glVertex3f( 0.5,0.5,-0.5);
    glEnd();
But this produces a blank screen!
What am I doing wrong?
Is there some debug mode where I can print out the transformed vertices, so I can see where they are ending up?
Note: People have suggested that using glMultMatrixf() might make a difference. It doesn't. Replacing
glLoadMatrixf( shadow );
with
     glLoadIdentity();
     glMultMatrixf( shadow );
gives the identical result ( of course! )
© Game Development or respective owner