OpenGL Super Bible! Page 343 The code in (Web hosting bandwidth)

OpenGL Super Bible! Page 343 The code in Listing 9-11 shows how the shadow projection matrix was created for this example. Note that we create the matrix once in SetupRC() and save it in a global variable. Listing 9-11 Setting up the shadow projection matrix GLfloat lightPos[] = { -75.0f, 150.0f, -50.0f, 0.0f }; // Transformation matrix to project shadow GLfloat shadowMat[4][4]; // This function does any needed initialization on the rendering // context. Here it sets up and initializes the lighting for // the scene. void SetupRC() { // Any three points on the ground (counterclockwise order) GLfloat points[3][3] = {{ -30.0f, -149.0f, -20.0f }, { -30.0f, -149.0f, 20.0f }, {40.0f, -149.0f, 20.0f }}; glEnable(GL_DEPTH_TEST); // Hidden surface removal glFrontFace(GL_CCW); // Counterclockwise polygons face out glEnable(GL_CULL_FACE); // Do not calculate inside of jet // Enable lighting glEnable(GL_LIGHTING); // Code to setup lighting, etc. // Light blue background glClearColor(0.0f, 0.0f, 1.0f, 1.0f ); // Calculate projection matrix to draw shadow on the ground MakeShadowMatrix(points, lightPos, shadowMat); } Listing 9-12 shows the rendering code for the SHADOW example. We first draw the jet as we normally would; then we restore the Modelview matrix and multiply it by the shadow matrix. This creates our squish Projection matrix. Then we draw the jet again (we ve modified our code to accept a flag telling the DrawJet function to render in color or black). After restoring the Modelview matrix once again, we draw a small yellow sphere to approximate the position of the light, and then draw a plane below the jet to indicate the ground. This rectangle lies in the same plane in which our shadow will be drawn.
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply