public void Draw() { //Light position for shadows MainLightSource.X = ScrollValue[10]; MainLightSource.Y = ScrollValue[11]; MainLightSource.Z = ScrollValue[12]; GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, MainLightSource.LightLocation()); GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, new float[] { 0f, 0f, 0f, 1f }); GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, new float[] { 1f, 1f, 1f }); GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, new float[] { 0.628281f, 0.555802f, 0.366065f }); GL.glLightfv(GL.GL_LIGHT2, GL.GL_POSITION, StaticRedLightSource.LightLocation()); GL.glLightfv(GL.GL_LIGHT2, GL.GL_AMBIENT, new float[] { 0f, 0f, 0f, 1f }); GL.glLightfv(GL.GL_LIGHT2, GL.GL_DIFFUSE, new float[] { 1f, 0f, 0f }); GL.glLightfv(GL.GL_LIGHT2, GL.GL_SPECULAR, new float[] { 0.628281f, 0.555802f, 0.366065f }); GL.glLightfv(GL.GL_LIGHT3, GL.GL_POSITION, StaticBlueLightSource.LightLocation()); GL.glLightfv(GL.GL_LIGHT3, GL.GL_AMBIENT, new float[] { 0f, 0f, 0f, 1f }); GL.glLightfv(GL.GL_LIGHT3, GL.GL_DIFFUSE, new float[] { 0f, 0f, 1f }); GL.glLightfv(GL.GL_LIGHT3, GL.GL_SPECULAR, new float[] { 0.628281f, 0.555802f, 0.366065f }); //GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, bannerLightPos); if (m_DeviceContext == 0 || m_RenderingContext == 0) { return; } GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.glLoadIdentity(); // not trivial double[] ModelVievMatrixBeforeSpecificTransforms = new double[16]; double[] CurrentRotationTraslation = new double[16]; GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2], ScrollValue[3], ScrollValue[4], ScrollValue[5], ScrollValue[6], ScrollValue[7], ScrollValue[8]); GL.glTranslatef(0.0f, 0.0f, -3.0f); DrawOldAxes(); //save current ModelView Matrix values //in ModelVievMatrixBeforeSpecificTransforms array //ModelView Matrix ========>>>>>> ModelVievMatrixBeforeSpecificTransforms GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); //ModelView Matrix was saved, so GL.glLoadIdentity(); // make it identity matrix //make transformation in accordance to KeyCode float delta; if (intOptionC != 0) { delta = 3.0f * Math.Abs(intOptionC) / intOptionC; // signed 5 switch (Math.Abs(intOptionC)) { case 1: GL.glRotatef(delta, 1, 0, 0); break; case 2: GL.glRotatef(delta, 0, 1, 0); break; case 3: GL.glRotatef(delta, 0, 0, 1); break; case 4: GL.glTranslatef(delta / 20, 0, 0); break; case 5: GL.glTranslatef(0, delta / 20, 0); break; case 6: GL.glTranslatef(0, 0, delta / 20); break; } } //as result - the ModelView Matrix now is pure representation //of KeyCode transform and only it !!! //save current ModelView Matrix values //in CurrentRotationTraslation array //ModelView Matrix =======>>>>>>> CurrentRotationTraslation GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); //The GL.glLoadMatrix function replaces the current matrix with //the one specified in its argument. //The current matrix is the //projection matrix, modelview matrix, or texture matrix, //determined by the current matrix mode (now is ModelView mode) GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix //The GL.glMultMatrix function multiplies the current matrix by //the one specified in its argument. //That is, if M is the current matrix and T is the matrix passed to //GL.glMultMatrix, then M is replaced with M • T GL.glMultMatrixd(CurrentRotationTraslation); //save the matrix product in AccumulatedRotationsTraslations GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); //replace ModelViev Matrix with stored ModelVievMatrixBeforeSpecificTransforms GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); //multiply it by KeyCode defined AccumulatedRotationsTraslations matrix GL.glMultMatrixd(AccumulatedRotationsTraslations); GL.glPushMatrix(); // save the current matrix GL.glScalef(zoom, zoom, zoom); // scale the matrix DrawAxes(); DrawFigures(); GL.glPopMatrix(); // load the unscaled matrix GL.glFlush(); WGL.wglSwapBuffers(m_DeviceContext); }
void DrawFigures() { skyBox.DrawSkyBox(); MainLightSource.DrawLightSource(new float[] { 1, 1, 0 }); StaticRedLightSource.DrawLightSource(new float[] { 1, 0, 0 }); StaticBlueLightSource.DrawLightSource(new float[] { 0, 0, 1 }); //Banner Light source GL.glTranslatef(bannerLightPos[0], bannerLightPos[1], bannerLightPos[2]); Random r = new Random(); GL.glColor3d(r.NextDouble(), r.NextDouble(), r.NextDouble()); GLUT.glutSolidSphere(0.1, 8, 8); GL.glTranslatef(-bannerLightPos[0], -bannerLightPos[1], -bannerLightPos[2]); GL.glEnd(); GL.glDisable(GL.GL_DEPTH_TEST); GL.glDisable(GL.GL_LIGHTING); // Start Drawing Floor Shadow GL.glPushMatrix(); GL.glEnable(GL.GL_BLEND); GL.glColor4d(0, 0, 0, 0.25); mainShadowManager.MakeShadowMatrix(mainShadowManager.Ground, cubeXform); GL.glMultMatrixf(cubeXform); m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, 6 }, true); m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, -6 }, true); GL.glCallList(SHADOW_LIST); //GL.glColor4d(0.05, 0, 0, 0.25); //redShadowManager.MakeShadowMatrix(redShadowManager.Ground, cubeXform); //GL.glMultMatrixf(cubeXform); //m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, 6 }, true); //m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, -6 }, true); //GL.glCallList(SHADOW_LIST); //GL.glColor4d(0, 0, 0.05, 0.25); //blueShadowManager.MakeShadowMatrix(blueShadowManager.Ground, cubeXform); //GL.glMultMatrixf(cubeXform); //m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, 6 }, true); //m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, -6 }, true); //GL.glCallList(SHADOW_LIST); GL.glDisable(GL.GL_BLEND); GL.glPopMatrix(); //for (int i = 0; i < 4; i++) //{ // GL.glPushMatrix(); // shadowManager.MakeShadowMatrix(shadowManager.Walls[i], cubeXform); // GL.glMultMatrixf(cubeXform); // m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, 6 }, true); // m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, -6 }, true); // GL.glCallList(SHADOW_LIST); // GL.glPopMatrix(); //} //End Drawing Floor Shadow GL.glEnable(GL.GL_DEPTH_TEST); GL.glEnable(GL.GL_COLOR_MATERIAL); GL.glEnable(GL.GL_LIGHT0); GL.glEnable(GL.GL_LIGHT1); GL.glEnable(GL.GL_LIGHT2); GL.glEnable(GL.GL_LIGHT3); GL.glEnable(GL.GL_LIGHTING); GL.glPushMatrix(); m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, 6 }, false); m_SideMachine.DrawSideMachines(new double[3] { 0, -0.4, -6 }, false); //toyCar.DrawToy(new double[3] { 1.4, 0.3, 0 }, new double[4] { 40, 0, 1, 0 }, false); GL.glCallList(CLAW_MACHINE_LIST); GL.glPopMatrix(); GL.glDisable(GL.GL_COLOR_MATERIAL); GL.glDisable(GL.GL_LIGHTING); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }