Esempio n. 1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            int startTime = Environment.TickCount & Int32.MaxValue;

            base.OnRenderFrame(e);

            GL.LightModel(LightModelParameter.LightModelAmbient, globLight);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);

            camera.SetView();

            SkyBoxSphere.Render(camera);

            ReferencePlane.setDimensions(50, 50);
            ReferencePlane.render();

            map.Render();

            //shadowTest();

            int totalTime = (Environment.TickCount & Int32.MaxValue) - startTime;

            int fps = 0;

            if (totalTime > 0)
            {
                fps = 1000 / totalTime;
            }

            Title = this.baseTitle + " FPS: " + fps;

            if (useFonts)
            {
                QFont.Begin();

                GL.PushMatrix();
                GL.Translate(0.0, 0.0, 0.0);
                font.Print(Title, QFontAlignment.Left);
                GL.PopMatrix();

                if (cameraHelp)
                {
                    GL.PushMatrix();
                    GL.Translate(config.ScreenWidth * 0.75, 0.0, 0.0);
                    monoFont.Print(cameraHelpText, QFontAlignment.Left);
                    GL.PopMatrix();
                }

                if (gameStats)
                {
                    GL.PushMatrix();
                    GL.Translate(0.0, config.ScreenHeight * 0.10f, 0.0);
                    gameStatsText = String.Format(gameStatsFormat,
                                                  map.GetRobots().Count, activeRobot.GetALife());
                    monoFont.Print(gameStatsText, QFontAlignment.Left);
                    GL.PopMatrix();
                }

                if (gameOver)
                {
                    GL.PushMatrix();
                    GL.Translate(config.ScreenWidth * 0.50, 0.0, 0.0);
                    monoFont.Print(gameOverText, QFontAlignment.Centre);
                    GL.PopMatrix();
                }

                QFont.End();
                GL.Disable(EnableCap.Texture2D);
            }

            GL.Flush();

            SwapBuffers();
        }
Esempio n. 2
0
        public void OnKeyDown(object sender, KeyboardKeyEventArgs args)
        {
            switch (args.Key)
            {
            case Key.H:
                cameraHelp = (cameraHelp) ? false : true;
                break;

            case Key.Tab:

                if (camera == globalCamera)
                {
                    camera = robotCamera;
                    robotCamera.Attach(someRobot);
                }
                else if (camera == robotCamera)
                {
                    camera = lightCamera1;
                }
                else if (camera == lightCamera1)
                {
                    camera = lightCamera2;
                }
                else if (camera == lightCamera2)
                {
                    camera = lightCamera3;
                }
                else if (camera == lightCamera3)
                {
                    camera = lightCamera4;
                }
                else if (camera == lightCamera4)
                {
                    camera = rmcUnitCamera;
                }
                else if (camera == rmcUnitCamera)
                {
                    camera = globalCamera;
                }
                break;

            case Key.F:
                if (Keyboard[Key.ControlLeft])
                {
                    /* toggle fullscreen */

                    if (this.WindowState == WindowState.Fullscreen)
                    {
                        this.WindowState = WindowState.Normal;
                    }
                    else
                    {
                        this.WindowState = WindowState.Fullscreen;
                    }
                }
                else
                {
                    /* toggle light */
                    camera.PerformActions(Camera.Action.TOGGLE_LIGHT);
                }
                break;

            case Key.Number5:
                if (ambientLights)
                {
                    ambientLights = false;
                    setGlobalAmbientLight(0.0f, 0.0f, 0.0f, 1.0f);
                }
                else
                {
                    ambientLights = true;
                    setGlobalAmbientLight(0.2f, 0.2f, 0.2f, 1.0f);
                }
                break;

            case Key.Number6:
                if (bottomLeftCornerLight)
                {
                    bottomLeftCornerLight = true;
                    GL.Disable(EnableCap.Light0);
                }
                else
                {
                    bottomLeftCornerLight = true;
                    GL.Enable(EnableCap.Light0);
                }
                break;

            case Key.Number7:
                if (bottomRightCornerLight)
                {
                    bottomRightCornerLight = true;
                    GL.Disable(EnableCap.Light1);
                }
                else
                {
                    bottomRightCornerLight = true;
                    GL.Enable(EnableCap.Light1);
                }
                break;

            case Key.Number8:
                if (topRightCornerLight)
                {
                    topRightCornerLight = true;
                    GL.Disable(EnableCap.Light2);
                }
                else
                {
                    topRightCornerLight = true;
                    GL.Enable(EnableCap.Light2);
                }
                break;

            case Key.Number9:
                if (topLeftCornerLight)
                {
                    topLeftCornerLight = true;
                    GL.Disable(EnableCap.Light3);
                }
                else
                {
                    topLeftCornerLight = true;
                    GL.Enable(EnableCap.Light3);
                }
                break;

            case Key.Number0:
                if (allPostLights)
                {
                    allPostLights = false;
                    GL.Disable(EnableCap.Light3);
                    GL.Disable(EnableCap.Light2);
                    GL.Disable(EnableCap.Light1);
                    GL.Disable(EnableCap.Light0);
                }
                else
                {
                    allPostLights = true;
                    GL.Enable(EnableCap.Light3);
                    GL.Enable(EnableCap.Light2);
                    GL.Enable(EnableCap.Light1);
                    GL.Enable(EnableCap.Light0);
                }
                break;

            case Key.J:
                camera.PerformActions(Camera.Action.TILT_LEFT | Camera.Action.ACTIVE);
                break;

            case Key.L:
                camera.PerformActions(Camera.Action.TILT_RIGHT | Camera.Action.ACTIVE);
                break;

            case Key.I:
                camera.PerformActions(Camera.Action.TILT_UP | Camera.Action.ACTIVE);
                break;

            case Key.K:
                camera.PerformActions(Camera.Action.TILT_DOWN | Camera.Action.ACTIVE);
                break;

            case Key.B:
                SkyBoxSphere.ChangeEnvironment();
                break;

            case Key.Minus:
                if (fovyscale > 2)
                {
                    fovyscale--;                             // Zoom out.

                    Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / fovyscale, Width / (float)Height, 1.0f, /*64.0f*/ 120.0f);
                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadMatrix(ref projection);
                }
                break;

            case Key.Plus:
                if (fovyscale < 10)
                {
                    fovyscale++;                             // Zoom in.

                    Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / fovyscale, Width / (float)Height, 1.0f, /*64.0f*/ 120.0f);
                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadMatrix(ref projection);
                }
                break;
            }
        }