Ejemplo n.º 1
0
        public void Run()
        {
            Glfw.Init();
            try {
                Glfw.OpenWindowHint(OpenWindowHint.NoResize, 1);
                                #if !DEBUG
                GlfwVidMode mode;
                Glfw.GetDesktopMode(out mode);
                Glfw.OpenWindow(mode.Width, mode.Height, 8, 8, 8, 0, 24, 0, WindowMode.FullScreen);
                                #else
                Glfw.OpenWindow(WindowWidth, WindowHeight, 8, 8, 8, 0, 24, 0, WindowMode.Window);
                                #endif
                Glfw.SetWindowPos(100, 100);
                Glfw.SetWindowTitle("Caribbean Stick - The Dark Project");
                Glfw.SwapInterval(false);
                GL.Enable(EnableCap.TextureRectangle);
                GL.GenTextures(1, out oglTexture);
                GL.BindTexture(TextureTarget.TextureRectangle, oglTexture);
                GL.TexParameter(TextureTarget.TextureRectangle, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                // TODO: non-constant size???
                                #if !DEBUG
                GL.Viewport(mode.Width / 2 - WindowWidth / 2, mode.Height / 2 - WindowHeight / 2, WindowWidth, WindowHeight);
                                #else
                GL.Viewport(0, 0, WindowWidth, WindowHeight);
                                #endif
                GL.MatrixMode(MatrixMode.Projection);
                GL.Ortho(0.0, WindowWidth, WindowHeight, 0.0, 0.0, 1.0);
                GL.MatrixMode(MatrixMode.Modelview);

                CurrentGameState = new MenuState(this);

                float prevTime = (float)Glfw.GetTime();

                Glfw.PollEvents();
                while (Glfw.GetWindowParam(WindowParam.Opened) == 1)
                {
                    CurrentKS         = KeyboardState.GetState();
                    MouseClickCurrent = Glfw.GetMouseButton(MouseButton.LeftButton);
                    if (PreviousKS == null)
                    {
                        PreviousKS = CurrentKS;
                    }

//					if (CurrentKS[Key.Escape]) {
//						Glfw.CloseWindow();
//					}

                    float time  = (float)Glfw.GetTime();
                    float delta = time - prevTime;

                    CurrentGameState.Update(delta);
                    CurrentGameState.Draw();
                    DrawOGL();

                    prevTime = time;

                    PreviousKS         = CurrentKS;
                    MouseClickPrevious = MouseClickCurrent;

                    Glfw.SwapBuffers();
                    Glfw.PollEvents();
                }
            } finally {
                CurrentGameState.Dispose();
                Glfw.Terminate();
            }
        }
Ejemplo n.º 2
0
 internal static void SaveOldKeyboardInput()
 {
     oldKeyboardState = KeyboardState.GetState();
 }
Ejemplo n.º 3
0
        static void OnUpdateFrame()
        {
            // Проверяем нажатия клавиш каждый кадр, а не по прерыванию!
            KeybrdState = KeyboardState.GetState(Window);

            float camMoveSens = 5.0f * FPS.Period;
            float camRotateSens = 200.0f * FPS.Period;
            float MoveX = 0.0f, MoveY = 0.0f, MoveZ = 0.0f,
                  RotateX = 0.0f, RotateY = 0.0f;

            if (KeybrdState[Key.W])
            {
                MoveY += camMoveSens;
            }
            if (KeybrdState[Key.A])
            {
                MoveX -= camMoveSens;
            }
            if (KeybrdState[Key.S])
            {
                MoveY -= camMoveSens;
            }
            if (KeybrdState[Key.D])
            {
                MoveX += camMoveSens;
            }
            if (KeybrdState[Key.E])
            {
                MoveZ += camMoveSens;
            }
            if (KeybrdState[Key.Q])
            {
                MoveZ -= camMoveSens;
            }

            if (MoveX != 0 || MoveY != 0 || MoveZ != 0)
            {
                MainCamera.Move(MoveX, MoveY, MoveZ);
            }

            if (KeybrdState[Key.Left])
            {
                RotateX += camRotateSens;
            }
            if (KeybrdState[Key.Right])
            {
                RotateX -= camRotateSens;
            }
            if (KeybrdState[Key.Up])
            {
                RotateY += camRotateSens;
            }
            if (KeybrdState[Key.Down])
            {
                RotateY -= camRotateSens;
            }

            if (RotateX != 0 || RotateY != 0)
            {
                MainCamera.AddRotation(RotateX, RotateY);
            }

            SkyBox.Position = MainCamera.Position;
        }
Ejemplo n.º 4
0
 internal static void UpdateKeyboardInput()
 {
     keyboardState = KeyboardState.GetState();
 }