Example #1
0
        public static void Render(Camera camera)
        {
            GL.PushMatrix();

            float[] camPos = camera.GetPosition();
            GL.Translate(camPos[0] + xOffset, camPos[1] + yOffset, camPos[2] + zOffset);
            currEnv.Render();

            GL.PopMatrix();
        }
Example #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;
            }
        }
Example #3
0
        public void LoadMap(string filename)
        {
            int x = 0;
            int y = 0;
            Light light;

            map = MapFile.Load(resourcePath + "/Maps/" + filename);

            mapWidth = map.GetWidth();
            mapHeight = map.GetHeight();

            activeRobot = map.GetActiveRobot();
            robotCamera.Attach(activeRobot);
            map.AddRobotToRemoteControlUnitList(activeRobot);

            light = new Light(LightName.Light7);
            activeRobot.AddLight(light);

            someRobot = activeRobot;

            LightPost lightpost = new LightPost(4);
            map.SetTile(lightpost, x, y);

            light = new Light(LightName.Light0);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                         2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                         1.0f, 1.0f, 1.0f);

            lightpost.AddLight(light);

            l = light;

            lightCamera1 = new Camera(0.0f, 6.0f, 0.0f,
                         2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                         0.0f, 1.0f, 0.0f);

            lightpost = new LightPost(3);
            map.SetTile(lightpost, x + mapWidth - 1, y);

            light = new Light(LightName.Light1);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                -2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 0.0f, 1.0f);
            lightpost.AddLight(light);

            lightCamera2 = new Camera(mapWidth - 1, 6.0f, 0.0f,
                (mapWidth - 1) - 2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 1.0f, 0.0f);

            lightpost = new LightPost(2);
            map.SetTile(lightpost, x + mapWidth - 1, y + mapHeight -1);

            light = new Light(LightName.Light2);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                -2.0f * (float) Math.Sqrt(2.0f), 0.0f, 2.0f * (float) Math.Sqrt(2.0f),
                1.0f, 1.0f, 1.0f);
            lightpost.AddLight(light);

            lightCamera3 = new Camera(mapWidth, 6.0f, -(mapHeight - 1),
                (mapWidth - 1) - 2.0f * (float) Math.Sqrt(2.0f), 0.0f, -(mapHeight - 1) + 2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 1.0f, 0.0f);

            lightpost = new LightPost(1);
            map.SetTile(lightpost, x, y + (mapHeight - 1));

            light = new Light(LightName.Light3);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                2.0f * (float) Math.Sqrt(2.0f), 0.0f, 2.0f * (float) Math.Sqrt(2.0f),
                1.0f, 1.0f, 1.0f);
            lightpost.AddLight(light);

            lightCamera4 = new Camera(0.0f, 6.0f, -(mapHeight - 1),
                2.0f * (float) Math.Sqrt(2.0f), 0.0f, -(mapHeight - 1) + 2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 1.0f, 0.0f);

            this.Title = this.baseTitle;

            PrintHelp();

            prevMousePosition = this.WindowCenter;
            prevMouseDelta = new Point(0, 0);
            nullDelta = new Point(0, 0);

            globalCamera.SetMap(map);
            robotCamera.SetMap(map);

            camera = globalCamera;

            System.Windows.Forms.Cursor.Hide();

            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.ColorMaterial);
            GL.Enable(EnableCap.Texture2D);

            /* To Avoid Having Z-Fighting for projecting surfaces onto another surface (Shadows) */
            GL.PolygonOffset(-10.0f, -25.0f);
        }