public void DrawFigures() { GL.glPushMatrix(); GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); //Draw Light Source GL.glDisable(GL.GL_LIGHTING); GL.glTranslatef(pos[0], pos[1], pos[2]); //Yellow Light source GL.glColor3f(1, 1, 0); GLUT.glutSolidSphere(0.05, 8, 8); GL.glTranslatef(-pos[0], -pos[1], -pos[2]); //main System draw GL.glEnable(GL.GL_LIGHTING); DrawRobot(false); drawStars(false); //end of regular show //!!!!!!!!!!!!! GL.glPopMatrix(); //!!!!!!!!!!!!! //SHADING begin //we'll define cubeXform matrix in MakeShadowMatrix Sub // Disable lighting, we'll just draw the shadow //else instead of shadow we'll see stange projection of the same objects GL.glDisable(GL.GL_LIGHTING); // wall shadow //!!!!!!!!!!!!! GL.glPushMatrix(); //!!!!!!!!!!!! MakeShadowMatrix(ground); GL.glMultMatrixf(cubeXform); DrawRobot(true); drawStars(true); //!!!!!!!!!!!!! GL.glPopMatrix(); //!!!!!!!!!!!!! }
void DrawFigures() { GL.glPushMatrix(); GL.glEnable(GL.GL_COLOR_MATERIAL); DrawLightSource(); GL.glCallList(handList); GL.glEnd(); GL.glPopMatrix(); GL.glPushMatrix(); if (enableLightSource) { MakeShadowMatrix(ground); } GL.glMultMatrixf(cubeXform); GL.glPopMatrix(); }
/********************************************************************************************************** * * * * MAIN DRAW FUNCTION * * * **********************************************************************************************************/ public void Draw() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); GL.glViewport(0, 0, Width, Height); GL.glLoadIdentity(); GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2], ScrollValue[3], ScrollValue[4], ScrollValue[5], ScrollValue[6], ScrollValue[7], ScrollValue[8]); GL.glRotatef(xAngle, 1.0f, 0.0f, 0.0f); GL.glRotatef(yAngle, 0.0f, 1.0f, 0.0f); GL.glRotatef(zAngle, 0.0f, 0.0f, 1.0f); GL.glTranslatef(xShift, yShift, zShift); pos[0] = light_position[0] = ScrollValue[9]; pos[1] = light_position[1] = ScrollValue[10]; pos[2] = light_position[2] = ScrollValue[11]; pos[3] = light_position[3] = 0; GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, light_ambient); GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, light_diffuse); GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, light_specular); GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position); GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); GL.glEnable(GL.GL_LIGHT0); /* * * Reflection * */ GL.glEnable(GL.GL_BLEND); GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); if (reflectionOn) { //draw only to STENCIL buffer GL.glEnable(GL.GL_STENCIL_TEST); GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE); GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF); GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE); GL.glDisable(GL.GL_DEPTH_TEST); drawLake(); // restore regular settings GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE); GL.glEnable(GL.GL_DEPTH_TEST); // reflection is drawn only where STENCIL buffer value equal to 1 GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF); GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); /* * * draw reflected scene * */ GL.glEnable(GL.GL_LIGHTING); for (currentTree = 0; currentTree < numOfTrees; currentTree++) { GL.glPushMatrix(); //GL.glTranslated(randX[currentTree], 0,randZ[currentTree]); GL.glTranslated(locationX[currentTree], 0, locationZ[currentTree]); GL.glRotated(locationRotateY[currentTree], 0, 1, 0); GL.glScalef(1, -1, 1); //swap on Z axis if (scullFaceOn) { GL.glEnable(GL.GL_CULL_FACE); GL.glCullFace(GL.GL_BACK); GL.glCallList(TREE_LIST + currentTree); GL.glCullFace(GL.GL_FRONT); GL.glCallList(TREE_LIST + currentTree); GL.glDisable(GL.GL_CULL_FACE); } else { GL.glCallList(TREE_LIST + currentTree); } GL.glPopMatrix(); } drawLake(); GL.glStencilFunc(GL.GL_NOTEQUAL, 1, 0xFFFFFFFF); GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); // really draw floor //( half-transparent ( see its color's alpha byte))) // in order to see reflected objects //GL.glDepthMask((byte)GL.GL_FALSE); GL.glDepthMask((byte)GL.GL_TRUE); if (!textureOn) { drawFloor(); } else { drawFloorTextured(); DrawTexturedCube(); } GL.glDisable(GL.GL_LIGHTING); GL.glDisable(GL.GL_STENCIL_TEST); } else { GL.glEnable(GL.GL_LIGHTING); drawLake(); if (!textureOn) { drawFloor(); } else { drawFloorTextured(); DrawTexturedCube(); } GL.glDisable(GL.GL_LIGHTING); } DrawLight(); /* * Draw trees */ GL.glEnable(GL.GL_LIGHTING); GL.glPushMatrix(); for (currentTree = 0; currentTree < numOfTrees; currentTree++) { GL.glPushMatrix(); //GL.glTranslated(randX[currentTree], 0, randZ[currentTree]); GL.glTranslated(locationX[currentTree], 0, locationZ[currentTree]); GL.glRotated(locationRotateY[currentTree], 0, 1, 0); GL.glCallList(TREE_LIST + currentTree); GL.glPopMatrix(); } GL.glPopMatrix(); /* * Draw trees shadows */ GL.glDisable(GL.GL_LIGHTING); GL.glColor3d(0, 0, 0); if (shadowOn) { GL.glPushMatrix(); MakeShadowMatrix(ground); GL.glMultMatrixf(cubeXform); for (currentTree = 0; currentTree < numOfTrees; currentTree++) { GL.glPushMatrix(); //GL.glTranslated(randX[currentTree], 0, randZ[currentTree]); GL.glTranslated(locationX[currentTree], 0, locationZ[currentTree]); GL.glRotated(locationRotateY[currentTree], 0, 1, 0); GL.glCallList(TREE_LIST + currentTree); GL.glPopMatrix(); } GL.glPopMatrix(); } GL.glFlush(); WGL.wglSwapBuffers(m_uint_DC); }
public void Draw() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); //TRIVIAL GL.glViewport(0, 0, Width, Height); GL.glLoadIdentity(); GL.glEnable(GL.GL_NORMALIZE); GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2], ScrollValue[3], ScrollValue[4], ScrollValue[5], ScrollValue[6], ScrollValue[7], ScrollValue[8]); pos[0] = light_position[0] = ScrollValue[9]; pos[1] = light_position[1] = ScrollValue[10]; pos[2] = light_position[2] = ScrollValue[11]; pos[3] = light_position[3] = 0; light_position_reflected[0] = -ScrollValue[9]; light_position_reflected[1] = -ScrollValue[10]; light_position_reflected[2] = -ScrollValue[11]; light_position[3] = 0; GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position); GL.glEnable(GL.GL_LIGHT0); GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, light_position); GL.glEnable(GL.GL_LIGHT1); //beascender look angle GL.glTranslatef(0.0f, -50.0f, -340.0f); //how far from the lake GL.glTranslatef(0.0f, 1.0f, 0.0f); //height from the lake GL.glRotatef(25, 1.0f, 0, 0); //look at lake angle GL.glRotatef(xAngle, 1.0f, 0.0f, 0.0f); if (checkBox) { GL.glRotatef((float)spirala * 0.018f, 0.0f, 1.0f, 0.0f); GL.glRotatef((float)speed * 0.008f, 1.0f, 1.0f, 0.0f); GL.glRotatef((float)speed * 0.008f, 0.0f, 1.0f, 1.0f); GL.glRotatef((float)speed * -0.005f, 1.0f, 0.0f, 1.0f); } GL.glRotatef(yAngle, 0.0f, 1.0f, 0.0f); GL.glRotatef(zAngle, 0.0f, 0.0f, 1.0f); if (checkBox) { GL.glTranslatef(xShift, yShift + (float)-speed * 0.18f, zShift); } GL.glTranslatef(xShift, yShift, zShift); /* * * Reflection drawing area start here * */ GL.glPushMatrix(); GL.glEnable(GL.GL_BLEND); GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); //draw only to STENCIL buffer GL.glEnable(GL.GL_STENCIL_TEST); GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE); GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF); GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE); GL.glDisable(GL.GL_DEPTH_TEST); Drawlake();//Draw area when we want to see reflect // restore regular seascendings GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE); GL.glEnable(GL.GL_DEPTH_TEST); // reflection is drawn only where STENCIL buffer value equal to 1 GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF); GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); /* * draw reflected scene */ GL.glScalef(1, -1, 1); //swap axes down GL.glPushMatrix(); DrawTexturedCube(); //reflected penguin drawPenguin(); draw_sun(); draw_moon(); GL.glPopMatrix(); GL.glPopMatrix(); GL.glEnable(GL.GL_LIGHTING); Drawlake(); GL.glDisable(GL.GL_LIGHTING); GL.glStencilFunc(GL.GL_NOTEQUAL, 1, 0xFFFFFFFF); GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); GL.glDepthMask((byte)GL.GL_FALSE); GL.glDepthMask((byte)GL.GL_TRUE); drawFloorTextured(); draw_sun(); draw_moon(); GL.glDisable(GL.GL_STENCIL_TEST); DrawTexturedCube(); //SKY BOX /* * * paint main scene area - start here * */ // drawaxe(); GL.glShadeModel(GL.GL_FLAT); GL.glEnable(GL.GL_LIGHTING); //Main Penguin drawPenguin(); ///////// GL.glDisable(GL.GL_LIGHTING); /* * * Draw shadows area - start here * */ GL.glDisable(GL.GL_LIGHTING); GL.glPushMatrix(); MakeShadowMatrix(ground); //sending fround matrix GL.glMultMatrixf(cubeXform); GL.glShadeModel(GL.GL_FLAT); GL.glColor3d(0, 0, 0);//black drawPenguinShade(); GL.glPopMatrix(); GL.glFlush(); WGL.wglSwapBuffers(m_uint_DC); }
void MakeShadow(double[] ModelVievMatrixBeforeSpecificTransforms, double[] CurrentRotationTraslation) { #region Shadow Robot floor GL.glPushMatrix(); MakeShadowMatrix(floorCoordForShadow); GL.glMultMatrixf(cubeXform); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glLoadIdentity(); // make it identity matrix GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw Robot shadow on floor GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glCullFace(GL.GL_FRONT); GL.glDisable(GL.GL_CULL_FACE); GL.glDisable(GL.GL_LIGHTING); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(true); //GL.glRotatef(180, 0, 1, 0); GL.glPopMatrix(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); GL.glPopMatrix(); #endregion #region Shadow Robot back wall GL.glPushMatrix(); MakeShadowMatrix(backWallCoordForShadow); GL.glMultMatrixf(cubeXform); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glLoadIdentity(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw Robot shadow on back wall GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glCullFace(GL.GL_FRONT); GL.glDisable(GL.GL_CULL_FACE); GL.glDisable(GL.GL_LIGHTING); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(true); GL.glPopMatrix(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); GL.glPopMatrix(); #endregion #region Shadow Robot front wall GL.glPushMatrix(); MakeShadowMatrix(frontWallCoordForShadow); GL.glMultMatrixf(cubeXform); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glLoadIdentity(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw Robot shadow on front wall GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glCullFace(GL.GL_FRONT); GL.glDisable(GL.GL_CULL_FACE); GL.glDisable(GL.GL_LIGHTING); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(true); GL.glPopMatrix(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); GL.glPopMatrix(); #endregion #region Shadow Robot right wall GL.glPushMatrix(); MakeShadowMatrix(rightWallCoordForShadow); GL.glMultMatrixf(cubeXform); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glLoadIdentity(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw Robot shadow on right wall GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glCullFace(GL.GL_FRONT); GL.glDisable(GL.GL_CULL_FACE); GL.glDisable(GL.GL_LIGHTING); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(true); GL.glPopMatrix(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); GL.glPopMatrix(); #endregion #region Shadow Robot left wall GL.glPushMatrix(); MakeShadowMatrix(leftWallCoordForShadow); GL.glMultMatrixf(cubeXform); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glLoadIdentity(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw Robot shadow on left wall GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glCullFace(GL.GL_FRONT); GL.glDisable(GL.GL_CULL_FACE); GL.glDisable(GL.GL_LIGHTING); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(true); GL.glPopMatrix(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); GL.glPopMatrix(); #endregion #region Shadow Robot roof GL.glPushMatrix(); MakeShadowMatrix(ceilingCoordForShadow); GL.glMultMatrixf(cubeXform); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glLoadIdentity(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw Robot shadow on roof GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glCullFace(GL.GL_FRONT); GL.glDisable(GL.GL_CULL_FACE); GL.glDisable(GL.GL_LIGHTING); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(true); GL.glPopMatrix(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); GL.glPopMatrix(); #endregion }
public void Draw() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); GL.glLoadIdentity(); if (Weaponchanged) { //if WeaponIndex changed create lists again! Robot.PrepareAndDraw(); Robot.PrepareAndDrawShadow(); Weaponchanged = false; } GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2], ScrollValue[3], ScrollValue[4], ScrollValue[5], ScrollValue[6], ScrollValue[7], ScrollValue[8]); #region Mouse Control GL.glTranslatef(-X, -Y, -Z); GL.glRotatef(rotX, 1.0f, 0.0f, 0.0f); GL.glRotatef(rotY, 0.0f, 1.0f, 0.0f); GL.glRotatef(rotZ, 0.0f, 0.0f, 1.0f); #endregion //move camera to initial position - center of cube and above floor GL.glTranslatef(0.0f, 0.0f, -1.0f); GL.glTranslatef(0.0f, 5.0f, 0.0f); GL.glRotatef(-90.0f, 0.0f, 1.0f, 0.0f); //update light position LightPosition[0] = ScrollValue[10]; LightPosition[1] = ScrollValue[11]; LightPosition[2] = ScrollValue[12]; LightPosition[3] = 1.0f; GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glLoadIdentity(); // make it identity matrix MoveRobotByDirection(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw actual cube cube.Scale(xMaxOfCube, yMaxOfCube, zMaxOfCube); cube.Draw(1); GL.glRotatef(180, 0, 1, 0); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); GL.glPushMatrix(); GL.glLoadIdentity(); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //!!!!!!!!!!! draw orginal Robot GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glDisable(GL.GL_CULL_FACE); GL.glEnable(GL.GL_LIGHTING); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(false); GL.glPopMatrix(); GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix RobotPlace[0] = AccumulatedRotationsTraslations[12]; RobotPlaceForward[0] = RobotPlaceBackward[0] = RobotPlaceRight[0] = RobotPlaceLeft[0] = AccumulatedRotationsTraslations[12]; RobotPlace[1] = AccumulatedRotationsTraslations[14]; RobotPlaceForward[1] = RobotPlaceBackward[1] = RobotPlaceRight[1] = RobotPlaceLeft[1] = AccumulatedRotationsTraslations[14]; switch (WhatWillDirection) { case arrow.forward: //Look future to get wallk forward RobotPlaceForward = WillPlace(2.1f, 0, 0); break; case arrow.backward: //Look future to get wallk backward RobotPlaceBackward = WillPlace(-2.1f, 0, 0); break; case arrow.right: //Look future to get wallk right RobotPlaceRight = WillPlace(0, 0, 2.1f); break; case arrow.left: //Look future to get wallk left RobotPlaceLeft = WillPlace(0, 0, -2.1f); break; } if (((RobotPlace[0] < ((car.Drive % 46) - 23) + 7) && (RobotPlace[0] > ((car.Drive % 46) - 23) - 4)) && //in car length RobotPlace[1] > 5 && RobotPlace[1] < 10 && !Robot.IsJumping) //in car width & not jumping { Robot.IsCrashWithCar = true; } //!!!!!!!!!!! GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); GL.glRotatef(-180, 0, 1, 0); #region Reflaction to cube StartReflaction(-1, 1, -1); //Reflaction to cube cube.Scale(xMaxOfCube - 0.002f, yMaxOfCube - 0.002f, zMaxOfCube - 0.002f); cube.Draw(-1); //decrease 0.002 from each dimension of cube to avoid unexpected lines and -1 for mirrow efect GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); #endregion // really draw mirror //( half-transparent ( see its color's alpha byte))) // in order to see reflected objects //GL.glPushMatrix(); //GL.glTranslatef(0, -4, 0); //GL.glDepthMask((byte)GL.GL_FALSE); //GL.glRotatef(90,0,1,0); //DrawMirror(); //GL.glDepthMask((byte)GL.GL_TRUE); //GL.glPopMatrix(); GL.glScalef(-1, 1, 1);//Some rotation for normal Cube direction GL.glRotatef(180, 0, 1, 0); #region Reflaction to Robot GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms); StartReflaction(-1, 1, 1); //Start Reflaction to Robot GL.glLoadIdentity(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation); GL.glLoadMatrixd(AccumulatedRotationsTraslations); GL.glMultMatrixd(CurrentRotationTraslation); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms); GL.glMultMatrixd(AccumulatedRotationsTraslations); //draw reflected Robot GL.glPushMatrix(); RotateRobotByDirection(); GL.glCullFace(GL.GL_BACK); GL.glCullFace(GL.GL_FRONT); GL.glDisable(GL.GL_CULL_FACE); GL.glRotatef(-Robot.WalkAngle, 0, 1, 0); Robot.Draw(false); GL.glPopMatrix(); GL.glDisable(GL.GL_CULL_FACE); GL.glPopMatrix(); //draw all Robot shadows in the mirror!! MakeShadow(ModelVievMatrixBeforeSpecificTransforms, CurrentRotationTraslation); DrawLight(); //draw reflected light GL.glDisable(GL.GL_STENCIL_TEST); #endregion GL.glScalef(1, 1, -1); //Some rotation for normal Cube direction GL.glRotatef(180, 0, 1, 0); DrawLight(); //draw actual light MakeShadow(ModelVievMatrixBeforeSpecificTransforms, CurrentRotationTraslation); //draw all Robot shadows car.Drive += 0.5f; //for animation of car moving //draw car reflection StartReflaction(-1, 1, 1); car.Draw(false); //draw car reflection shadow on floor StartReflaction(-1, 1, 1); GL.glDisable(GL.GL_LIGHTING); GL.glPushMatrix(); MakeShadowMatrix(floorCoordForShadow); GL.glMultMatrixf(cubeXform); car.Draw(true); GL.glPopMatrix(); //draw car reflection shadow on back wall StartReflaction(-1, 1, 1); GL.glDisable(GL.GL_LIGHTING); GL.glPushMatrix(); MakeShadowMatrix(backWallCoordForShadow); GL.glMultMatrixf(cubeXform); car.Draw(true); GL.glPopMatrix(); //draw car reflection shadow on front wall StartReflaction(-1, 1, 1); GL.glDisable(GL.GL_LIGHTING); GL.glPushMatrix(); MakeShadowMatrix(frontWallCoordForShadow); GL.glMultMatrixf(cubeXform); car.Draw(true); GL.glPopMatrix(); GL.glDisable(GL.GL_STENCIL_TEST); //draw the Frame of mirror mirror.DrawFrame(); //draw mirror again to cover car from being shown on the other side of mirror GL.glPushMatrix(); GL.glTranslatef(0, -4, 0); GL.glRotatef(90, 0, 1, 0); mirror.Draw(); GL.glPopMatrix(); //draw car car.Draw(false); //draw shadow car on floor GL.glPushMatrix(); MakeShadowMatrix(floorCoordForShadow); GL.glMultMatrixf(cubeXform); car.Draw(true); GL.glPopMatrix(); //draw shadow car on back wall GL.glPushMatrix(); MakeShadowMatrix(backWallCoordForShadow); GL.glMultMatrixf(cubeXform); car.Draw(true); GL.glPopMatrix(); //draw shadow car on front wall GL.glPushMatrix(); MakeShadowMatrix(frontWallCoordForShadow); GL.glMultMatrixf(cubeXform); car.Draw(true); GL.glPopMatrix(); GL.glFlush(); WGL.wglSwapBuffers(m_uint_DC); }
void DrawFigures() { GL.glPushMatrix(); DrawLights(); switch (display_mod) { case 1: DrawMirrors(); DrawObjects(false); GL.glPopMatrix(); break; case 2: DrawWalls(); DrawObjects(false); GL.glPopMatrix(); //SHADING begin //we'll define cubeXform matrix in MakeShadowMatrix Sub // Disable lighting, we'll just draw the shadow //else instead of shadow we'll see stange projection of the same objects GL.glDisable(GL.GL_LIGHTING); /* * // back shadow * //!!!!!!!!!!!!! * GL.glPushMatrix(); * backMirrorSurface.doRotations(); * //!!!!!!!!!!!! * MakeShadowMatrix(backMirrorSurface.getSurf()); * GL.glMultMatrixf(cubeXform); * DrawObjects(true); * //!!!!!!!!!!!!! * GL.glPopMatrix(); * //!!!!!!!!!!!!! */ // left shadow //!!!!!!!!!!!!! GL.glPushMatrix(); leftMirrorSurface.doRotations(); //!!!!!!!!!!!! MakeShadowMatrix(leftMirrorSurface.getSurf()); GL.glMultMatrixf(shadowCubeXform); DrawObjects(true); //!!!!!!!!!!!!! GL.glPopMatrix(); //!!!!!!!!!!!!! // right shadow //!!!!!!!!!!!!! GL.glPushMatrix(); //!!!!!!!!!!!! rightMirrorSurface.doRotations(); MakeShadowMatrix(rightMirrorSurface.getSurf()); GL.glMultMatrixf(shadowCubeXform); DrawObjects(true); //!!!!!!!!!!!!! GL.glPopMatrix(); //!!!!!!!!!!!!! break; case 3: DrawRoom(); GL.glEnable(GL.GL_LIGHTING); GL.glTranslatef(0.0f, 0.0f, -7.4f); DrawObjects(false); GL.glTranslatef(0.0f, 0.0f, +7.4f); GL.glPopMatrix(); GL.glDisable(GL.GL_LIGHTING); break; } }
void DrawFigures() { //!!!!!!!!!!!!! GL.glPushMatrix(); //!!!!!!!!!!!!! GL.glEnable(GL.GL_TEXTURE_2D); //plane grids if (!rotate) { GL.glPushMatrix(); drawground(); GL.glDisable(GL.GL_TEXTURE_2D); GL.glDisable(GL.GL_LIGHTING); GL.glEnable(GL.GL_COLOR); GL.glTranslatef(pos[0], pos[1], 10); GL.glColor3f(1, 1, 0); GLU.gluSphere(obj, 1, 16, 16); GL.glTranslatef(-pos[0], -pos[1], -10); GL.glEnd(); GL.glEnable(GL.GL_TEXTURE_2D); GL.glPopMatrix(); } else { GL.glPushMatrix(); angleG -= 0.2f; GL.glRotatef(angleG, 0, 0, 0.1f); drawground(); GL.glDisable(GL.GL_TEXTURE_2D); GL.glDisable(GL.GL_LIGHTING); GL.glEnable(GL.GL_COLOR); GL.glTranslatef(pos[0], pos[1], 10); GL.glColor3f(1, 1, 0); GL.glRotatef(angleG, 0, 2, 0); GLU.gluSphere(obj, 1, 16, 16); GL.glTranslatef(-pos[0], -pos[1], -10); GL.glEnd(); GL.glEnable(GL.GL_TEXTURE_2D); GL.glPopMatrix(); } DrawObjects(false, 1); //end of regular showFfron //!!!!!!!!!!!!! GL.glPopMatrix(); //!!!!!!!!!!!!! //SHADING begin //we'll define cubeXform matrix in MakeShadowMatrix Sub // Disable lighting, we'll just draw the shadow //else instead of shadow we'll see stange projection of the same objects GL.glDisable(GL.GL_LIGHTING); // floor shadow //!!!!!!!!!!!!! GL.glPushMatrix(); //!!!!!!!!!!!! MakeShadowMatrix(ground); GL.glMultMatrixf(cubeXform); DrawObjects(true, 1); //!!!!!!!!!!!!! GL.glPopMatrix(); }
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); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }