Pro OpenGL ES for iOS

(singke) #1

238 CHAPTER 7: Well-Rendered Miscellany^


for ( int i=0;i<16;i++ )
{
iShadowMat[i] = shadowMat_local[i];
}
}
This is actually a simplified version of the more generalized matrix given by the following:
[ dotp-l[0]*p[0], -l[1]*p[0], -l[2]*p[0], -l[3]*p[0],
-l[0]*p[1], dotp-l[1]*p[1], -l[2]*p[1], -l[3]*p[1],
-l[0]*p[2], -l[1]*p[2], dotp-l[2]*p[2], -l[3]*p[2],
-l[0]*p[3], -l[1]*p[3], -l[2]*p[3], dotp-l[3]*p[3] ]
dotp is the dot-product between the light vector and the normal to the plane, l is the
position of the light, and p is the plane (the ‘‘platform’’ in my code). Since our platform is
in the x/z plane, the plane equation looks like p=[0,1,0,0], or otherwise, p[0]=p[2]=p[3]=0.
This means most of the terms in the matrix get zeroed out. Once the matrix is
generated, multiplying it by the existing Modelview matrix maps the points to your local
space along with everything else.
Listing 7-16. The tweaked drawShadow() routine


  • (void)drawShadow
    {
    glPushMatrix();


glRotatef(m_WorldRotationX, 1.0, 0.0, 0.0); //1
glRotatef(m_WorldRotationY, 0.0, 1.0, 0.0);

glMultMatrixf( iShadowMat ); //2

//Place the shadows.

glTranslatef(0.0,m_TransY, 0.0); //3

glRotatef( m_SpinZ, 0.0, 0.0, 1.0 ); //4
glRotatef( m_SpinY, 0.0, 1.0, 0.0 );
glRotatef( m_SpinX, 1.0, 0.0, 0.0 );

//Draw them.

glDisableClientState(GL_COLOR_ARRAY);

glEnable(GL_BLEND); //5
glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_ALPHA);

glColor4f( 0.0, 0.0, 0.0, .3 ); //6

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer( 3, GL_FLOAT, 0, m_CubeVertices ); //7

glDrawElements( GL_TRIANGLE_FAN, 6 * 3, GL_UNSIGNED_BYTE, m_Tfan1);
glDrawElements( GL_TRIANGLE_FAN, 6 * 3, GL_UNSIGNED_BYTE, m_Tfan2);
Free download pdf