// -------------------------------------------------------------------- public void OnFrameTick() { OpenTK.Input.KeyboardState keyboardState = OpenTK.Input.Keyboard.GetState(); bool keySDown = keyboardState.IsKeyDown(OpenTK.Input.Key.S); bool keyADown = keyboardState.IsKeyDown(OpenTK.Input.Key.A); bool keyWDown = keyboardState.IsKeyDown(OpenTK.Input.Key.W); bool keyDDown = keyboardState.IsKeyDown(OpenTK.Input.Key.D); if (keyDDown) { MoveCamera(Vector3.UnitX * DragFactor * 10); } if (keySDown) { MoveCamera(Vector3.UnitZ * DragFactor * 10); } if (keyWDown) { MoveCamera(-Vector3.UnitZ * DragFactor * 10); } if (keyADown) { MoveCamera(-Vector3.UnitX * DragFactor * 10); } if (keyADown || keyDDown || keySDown || keyWDown) { mBoundControl.Refresh(); } }
public void KeyPress(OpenTK.Input.KeyboardState keyState) { if (keyState.IsKeyDown(OpenTK.Input.Key.E)) { this.E = this.E + 5; this.D = this.D - 5; } if (keyState.IsKeyDown(OpenTK.Input.Key.D)) { this.E = this.E - 5; this.D = this.D + 5; } if (keyState.IsKeyDown(OpenTK.Input.Key.C)) { this.C = this.C + 5; this.B = this.B - 5; } if (keyState.IsKeyDown(OpenTK.Input.Key.B)) { this.C = this.C - 5; this.B = this.B + 5; } if (keyState.IsKeyDown(OpenTK.Input.Key.I)) { this.I = this.I + 1; this.O = this.O - 1; } if (keyState.IsKeyDown(OpenTK.Input.Key.O)) { this.I = this.I - 1; this.O = this.O + 1; } }
/// <summary> /// Initializes a new instance of <see cref="KeyboardKeyEventArgs"/> class. /// </summary> /// <param name="keyCode">The <see cref="Keyboard.Key"/> corresponding to the key the user input.</param> public KeyboardKeyEventArgs(Keyboard.Key keyCode) : base() { KeyCode = keyCode; _state = OpenTK.Input.Keyboard.GetState(); _isRepeat = false; }
private void renderControl1_Load(object sender, EventArgs e) { eye = new Vector3(0.0f, 0.0f, 15.0f); target = new Vector3(0.0f, 0.0f, 0.0f); scale = 0.1f; modelviewMatrix = Matrix4.CreateScale(scale) * Matrix4.LookAt(eye, target, Vector3.UnitY); camera = new Camera(); shader = new Shader( File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\\VertexShader.glsl")), File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\\FragmentShader.glsl"))); font = new Cobalt.Font("DejaVu Sans"); string[] args = Environment.GetCommandLineArgs(); if (args.Length > 1) { LoadFile(args[1]); } lastKbd = OpenTK.Input.Keyboard.GetState(); wireframe = false; culling = false; shader.SetUniform("texture", (int)0); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); // "E:\[SSD User Data]\Downloads\disg-BLUS30727\map00107\map00107.obf" // "E:\[SSD User Data]\Downloads\disg-BLUS30727\map30001\map30001.obf" // "E:\[SSD User Data]\Downloads\disg-BLUS30727\BLUS30727\PS3_GAME\USRDIR\Data\MAP (converted)\mp001\map00101.pac" // "E:\[SSD User Data]\Downloads\disg-BLUS30727\BLUS30727\PS3_GAME\USRDIR\Data\MAP (converted)\mp300\map30001.pac" }
public void UpdateState() { this.hasFocus = this.window.Focused; this.charInput = this.charInputBuffer.ToString(); this.charInputBuffer.Clear(); this.keyState = this.keyStateBuffer; }
public static void UpdateFromOpenTK(OpenTK.Input.KeyboardState keyboard) { for (int i = 0; i < (int)OpenTK.Input.Key.LastKey; i++) { var key = (OpenTK.Input.Key)i; _current.SetState(translateOpenTKKey(key), keyboard.IsKeyDown(key) ? KeyState.Down : KeyState.Up); } }
protected override void OnUpdateFrame(OpenTK.FrameEventArgs e) { OpenTK.Input.KeyboardState input = OpenTK.Input.Keyboard.GetState(); if (input.IsKeyDown(OpenTK.Input.Key.Escape)) { Exit(); } base.OnUpdateFrame(e); }
public void UpdateFromMouse() { try { OpenTK.Input.MouseState mouseState = OpenTK.Input.Mouse.GetState(); OpenTK.Input.KeyboardState keyboardState = OpenTK.Input.Keyboard.GetState(); if (OpenTK.Input.Mouse.GetState().RightButton == OpenTK.Input.ButtonState.Pressed) { float xAmount = OpenTK.Input.Mouse.GetState().X - mouseXLast; float yAmount = (OpenTK.Input.Mouse.GetState().Y - mouseYLast); Pan(xAmount, yAmount, true); } if (mouseState.LeftButton == OpenTK.Input.ButtonState.Pressed) { // Dragging left/right rotates around the y-axis. // Dragging up/down rotates around the x-axis. float xAmount = (OpenTK.Input.Mouse.GetState().Y - mouseYLast); float yAmount = OpenTK.Input.Mouse.GetState().X - mouseXLast; Rotate(xAmount * rotateXSpeed, yAmount * rotateYSpeed); } // Holding shift changes zoom speed. float zoomAmount = zoomSpeed * zoomDistanceScale; if (keyboardState.IsKeyDown(OpenTK.Input.Key.ShiftLeft) || OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.ShiftRight)) { zoomAmount *= shiftZoomMultiplier; } // Zooms in or out with arrow keys. if (keyboardState.IsKeyDown(OpenTK.Input.Key.Down)) { Zoom(-zoomAmount, true); } else if (keyboardState.IsKeyDown(OpenTK.Input.Key.Up)) { Zoom(zoomAmount, true); } // Scroll wheel zooms in or out. float scrollZoomAmount = (mouseState.WheelPrecise - mouseSLast) * scrollWheelZoomSpeed; Zoom(scrollZoomAmount * zoomAmount, true); UpdateLastMousePosition(); } catch (Exception) { // RIP OpenTK... } UpdateMatrices(); }
protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); Console.WriteLine("[3] .. OnUpdateFrame"); OpenTK.Input.KeyboardState keyboardState = OpenTK.Input.Keyboard.GetState(); KeyPress(keyboardState); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(-this.D, this.E, this.C, -this.B, -1, 1); }
public void ProcessKeyboardState(OpenTK.Input.KeyboardState keys) { /**/ } public void ProcessMouseMovement(int deltax, int deltay) { /*Pitch += (float)deltax / 100.0f; * if (Pitch > MathHelper.TwoPi) Pitch = 0.0f; * * Roll += (float)deltay / 100.0f; * if (Roll > MathHelper.Pi / 2) Roll = MathHelper.Pi / 2; * if (Roll < -MathHelper.Pi / 2) Roll = -MathHelper.Pi / 2; * * Update();*/ }
protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); OpenTK.Input.KeyboardState keyboard = OpenTK.Input.Keyboard.GetState(); if (keyboard[OpenTK.Input.Key.Escape]) { this.Exit(); } if (keyboard[OpenTK.Input.Key.S]) { takeScreenShot = true; } }
public void KeyPress(OpenTK.Input.KeyboardState keyState) { if (keyState.IsKeyDown(OpenTK.Input.Key.Number1) || keyState.IsKeyDown(OpenTK.Input.Key.Keypad1)) { this.mundo.SelectPoint(0); } if (keyState.IsKeyDown(OpenTK.Input.Key.Number2) || keyState.IsKeyDown(OpenTK.Input.Key.Keypad2)) { this.mundo.SelectPoint(1); } if (keyState.IsKeyDown(OpenTK.Input.Key.Number3) || keyState.IsKeyDown(OpenTK.Input.Key.Keypad3)) { this.mundo.SelectPoint(2); } if (keyState.IsKeyDown(OpenTK.Input.Key.Number4) || keyState.IsKeyDown(OpenTK.Input.Key.Keypad4)) { this.mundo.SelectPoint(3); } if (keyState.IsKeyDown(OpenTK.Input.Key.Plus) || keyState.IsKeyDown(OpenTK.Input.Key.KeypadPlus)) { this.delayedKeyAction(() => this.mundo.IncreaseSplineControlPoint()); } if (keyState.IsKeyDown(OpenTK.Input.Key.Minus) || keyState.IsKeyDown(OpenTK.Input.Key.KeypadMinus)) { this.delayedKeyAction(() => this.mundo.DecreaseSplineControlPoint()); } if (keyState.IsKeyDown(OpenTK.Input.Key.C)) { this.mundo.moveSelectedPoint(Direction.UP); } if (keyState.IsKeyDown(OpenTK.Input.Key.B)) { this.mundo.moveSelectedPoint(Direction.DOWN); } if (keyState.IsKeyDown(OpenTK.Input.Key.E)) { this.mundo.moveSelectedPoint(Direction.LEFT); } if (keyState.IsKeyDown(OpenTK.Input.Key.D)) { this.mundo.moveSelectedPoint(Direction.RIGHT); } if (keyState.IsKeyDown(OpenTK.Input.Key.R)) { this.mundo.reset(); } }
/// <summary>Graphical Event Handling</summary> public override void FrameUpdate(FrameEventArgs e) { // Get states from OpenTK OpenTK.Input.KeyboardState input = OpenTK.Input.Keyboard.GetState(); OpenTK.Input.MouseState mouse = OpenTK.Input.Mouse.GetState(); // Keyboard if (input.IsKeyDown(OpenTK.Input.Key.Escape)) { m_Win.Exit(); } // Mouse if (mouse.X > m_Win.Location.X && mouse.X < (m_Win.Location.X + m_Win.Size.Width) && (mouse.Y > m_Win.Location.Y && mouse.Y < (m_Win.Location.Y + m_Win.Size.Height))) { } }
public PrimitiveType getPrimitive() { OpenTK.Input.KeyboardState keyboardState = OpenTK.Input.Keyboard.GetState(); if (this.listenKeyPress && keyboardState.IsKeyDown(OpenTK.Input.Key.Space)) { this.listenKeyPress = false; this.index++; if (this.index >= this.primitives.Length) { this.index = 0; } Task.Run(async() => { await Task.Delay(200); this.listenKeyPress = true; }); } return(this.primitives[this.index]); }
public override void UpdateFromMouse() { try { OpenTK.Input.MouseState mouseState = OpenTK.Input.Mouse.GetState(); OpenTK.Input.KeyboardState keyboardState = OpenTK.Input.Keyboard.GetState(); if (OpenTK.Input.Mouse.GetState().RightButton == OpenTK.Input.ButtonState.Pressed) { float xAmount = OpenTK.Input.Mouse.GetState().X - mouseXLast; float yAmount = (OpenTK.Input.Mouse.GetState().Y - mouseYLast); Pan(xAmount, yAmount, true); } // Holding shift changes zoom speed. float zoomAmount = zoomSpeed * zoomDistanceScale; if (keyboardState.IsKeyDown(OpenTK.Input.Key.ShiftLeft) || OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.ShiftRight)) { zoomAmount *= shiftZoomMultiplier; } // Zooms in or out with arrow keys. if (keyboardState.IsKeyDown(OpenTK.Input.Key.Down)) { Zoom(-zoomAmount, true); } else if (keyboardState.IsKeyDown(OpenTK.Input.Key.Up)) { Zoom(zoomAmount, true); } // Scroll wheel zooms in or out. float scrollZoomAmount = (mouseState.WheelPrecise - mouseSLast) * scrollWheelZoomSpeed; scale -= scrollZoomAmount * zoomAmount; scale = Math.Max(scale, 0); } catch (Exception) { // RIP OpenTK... } UpdateLastMousePosition(); UpdateMatrices(); }
protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); var state = OpenTK.Input.Keyboard.GetState(); if (state.IsKeyDown(OpenTK.Input.Key.Escape)) { this.Close(); } helicopter.Collision = helicopter.Box.Intersects(blocoC.Box); helicopter.ColideTop = helicopter.Box.IntersectsWithTop(blocoC.Box); camera.Move(); helicopter.HandleInput(); if (oldState.IsKeyDown(OpenTK.Input.Key.B) && state.IsKeyUp(OpenTK.Input.Key.B)) { DrawBoundingBox = !DrawBoundingBox; } //System.Diagnostics.Debug.WriteLine(helicopter.Collision); //if (helicopter.Position.Y < 40) //{ // //if (state.IsKeyDown(OpenTK.Input.Key.Space)) // // helicopter.Position = new OpenTK.Vector3(helicopter.Position.X, helicopter.Position.Y + (0.3f * altitude), helicopter.Position.Z); // //else if(state.IsKeyUp(OpenTK.Input.Key.Space) && helicopter.Position.Y > 0) // // helicopter.Position = new OpenTK.Vector3(helicopter.Position.X, helicopter.Position.Y - (0.1f * altitude), helicopter.Position.Z); //} //(float)CubicEaseInOut(altitude,0,30,30) oldState = state; }
private void renderControl_Load(object sender, EventArgs e) { eye = new Vector3(0.0f, 0.0f, 15.0f); target = new Vector3(0.0f, 0.0f, 0.0f); scale = 1.0f; modelviewMatrix = Matrix4.CreateScale(scale) * Matrix4.LookAt(eye, target, Vector3.UnitY); camera = new Camera(); shader = new Shader( File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\\VertexShader.glsl")), File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\\FragmentShader.glsl"))); font = new Cobalt.Font("DejaVu Sans"); lastKbd = OpenTK.Input.Keyboard.GetState(); wireframe = false; culling = true; lighting = true; takeScreenshot = false; if (shader != null) { shader.SetUniformName(ShaderCommonUniform.ProjectionMatrix, projectionMatrixName); shader.SetUniformName(ShaderCommonUniform.ModelViewMatrix, modelviewMatrixName); shader.SetUniformName(ShaderCommonUniform.MaterialTexture, materialTextureName); shader.SetUniformName(ShaderCommonUniform.MaterialAmbientColor, materialAmbientName); shader.SetUniformName(ShaderCommonUniform.MaterialDiffuseColor, materialDiffuseName); shader.SetUniformName(ShaderCommonUniform.MaterialSpecularColor, materialSpecularName); shader.SetUniform(ShaderCommonUniform.MaterialTexture, (int)0); shader.SetUniform(sunLightColorName, new Vector3(1.0f, 1.0f, 1.0f)); shader.SetUniform(ambientIntensityName, 0.5f); } GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); sunAngle = 45.0f; StartupDebugShortcuts(); }
private void KeyboardUpdate(double timeSinceLastFrame, ref double[] refTranslation, ref double[] refRotation) { OpenTK.Input.KeyboardState keyState = OpenTK.Input.Keyboard.GetState(); /* * By convention, the double arrays are ordered in x,y,z order (x = 0, y = 1, z = 2). * Orientation is right handed, with an inverted Z-axis. * * Translation is converted during calculation to account for facing. */ if (keyState.IsKeyDown(OpenTK.Input.Key.W)) { refTranslation[2] += 500000 * Math.Cos(Facing[1]); } if (keyState.IsKeyDown(OpenTK.Input.Key.S)) { refTranslation[2] += -500000 * Math.Cos(Facing[1]); } if (keyState.IsKeyDown(OpenTK.Input.Key.D)) { refTranslation[0] += 500000 * Math.Cos(Facing[1]); } if (keyState.IsKeyDown(OpenTK.Input.Key.A)) { refTranslation[0] += -500000 * Math.Cos(Facing[1]); } if (keyState.IsKeyDown(OpenTK.Input.Key.Q)) { refTranslation[1] += 500000 * Math.Cos(Facing[2]); } if (keyState.IsKeyDown(OpenTK.Input.Key.E)) { refTranslation[1] += -500000 * Math.Cos(Facing[2]); } if (keyState.IsKeyDown(OpenTK.Input.Key.Keypad7)) { refRotation[2] += 1; } if (keyState.IsKeyDown(OpenTK.Input.Key.Keypad9)) { refRotation[2] += -1; } if (keyState.IsKeyDown(OpenTK.Input.Key.Keypad8)) { refRotation[0] += 1; } if (keyState.IsKeyDown(OpenTK.Input.Key.Keypad5)) { refRotation[0] += -1; } if (keyState.IsKeyDown(OpenTK.Input.Key.Keypad4)) { refRotation[1] += 1; } if (keyState.IsKeyDown(OpenTK.Input.Key.Keypad6)) { refRotation[1] += -1; } if (keyState.IsKeyDown(OpenTK.Input.Key.ShiftLeft) || keyState.IsKeyDown(OpenTK.Input.Key.ShiftRight)) { for (int i = 0; i < refTranslation.Length; i++) { refTranslation[i] *= 10; } } if (keyState.IsKeyDown(OpenTK.Input.Key.ControlLeft)) { for (int i = 0; i < refTranslation.Length; i++) { refTranslation[i] *= 100; } } for (int i = 0; i < 3; i++) { refRotation[i] *= timeSinceLastFrame; refTranslation[i] *= timeSinceLastFrame; Position[i] += refTranslation[i]; } }
public static void CheckEvents() { SakuraGameWindow.ProcessEvents(); bool __isWinFocused = SakuraGameWindow.getFocused(); OpenTK.Input.KeyboardState keyboard = OpenTK.Input.Keyboard.GetState(); GamePadData gamePadData = GamePad.__gamePadData; gamePadData.ButtonsPrev = gamePadData.Buttons; gamePadData.ButtonsDown = 0; gamePadData.Buttons = 0; gamePadData.ButtonsUp = 0; if (__isWinFocused) { if (keyboard.IsKeyDown(OpenTK.Input.Key.Escape)) { System.Environment.Exit(0); } // if (keyboard.IsKeyDown(OpenTK.Input.Key.Left)) { if (!__isKeyLeftDown) { gamePadData.ButtonsDown |= GamePadButtons.Left; } __isKeyLeftDown = true; gamePadData.Buttons |= GamePadButtons.Left; } if (keyboard.IsKeyDown(OpenTK.Input.Key.Right)) { if (!__isKeyRightDown) { gamePadData.ButtonsDown |= GamePadButtons.Right; } __isKeyRightDown = true; gamePadData.Buttons |= GamePadButtons.Right; } if (keyboard.IsKeyDown(OpenTK.Input.Key.Up)) { if (!__isKeyUpDown) { gamePadData.ButtonsDown |= GamePadButtons.Up; } __isKeyUpDown = true; gamePadData.Buttons |= GamePadButtons.Up; } if (keyboard.IsKeyDown(OpenTK.Input.Key.Down)) { if (!__isKeyDownDown) { gamePadData.ButtonsDown |= GamePadButtons.Down; } __isKeyDownDown = true; gamePadData.Buttons |= GamePadButtons.Down; } if (keyboard.IsKeyDown(OpenTK.Input.Key.A)) { if (!__isKeyADown) { gamePadData.ButtonsDown |= GamePadButtons.Square; } __isKeyADown = true; gamePadData.Buttons |= GamePadButtons.Square; } if (keyboard.IsKeyDown(OpenTK.Input.Key.W)) { if (!__isKeyWDown) { gamePadData.ButtonsDown |= GamePadButtons.Triangle; } __isKeyWDown = true; gamePadData.Buttons |= GamePadButtons.Triangle; } if (keyboard.IsKeyDown(OpenTK.Input.Key.D)) { if (!__isKeyDDown) { gamePadData.ButtonsDown |= GamePadButtons.Circle; gamePadData.ButtonsDown |= GamePadButtons.Back; } __isKeyDDown = true; gamePadData.Buttons |= GamePadButtons.Circle; gamePadData.Buttons |= GamePadButtons.Back; } if (keyboard.IsKeyDown(OpenTK.Input.Key.S)) { if (!__isKeySDown) { gamePadData.ButtonsDown |= GamePadButtons.Cross; gamePadData.ButtonsDown |= GamePadButtons.Enter; } __isKeySDown = true; gamePadData.Buttons |= GamePadButtons.Cross; gamePadData.Buttons |= GamePadButtons.Enter; } if (keyboard.IsKeyDown(OpenTK.Input.Key.X)) { if (!__isKeyXDown) { gamePadData.ButtonsDown |= GamePadButtons.Start; } __isKeyXDown = true; gamePadData.Buttons |= GamePadButtons.Start; } if (keyboard.IsKeyDown(OpenTK.Input.Key.Z)) { if (!__isKeyZDown) { gamePadData.ButtonsDown |= GamePadButtons.Select; } __isKeyZDown = true; gamePadData.Buttons |= GamePadButtons.Select; } if (keyboard.IsKeyDown(OpenTK.Input.Key.Q)) { if (!__isKeyQDown) { gamePadData.ButtonsDown |= GamePadButtons.L; } __isKeyQDown = true; gamePadData.Buttons |= GamePadButtons.L; } if (keyboard.IsKeyDown(OpenTK.Input.Key.E)) { if (!__isKeyEDown) { gamePadData.ButtonsDown |= GamePadButtons.R; } __isKeyEDown = true; gamePadData.Buttons |= GamePadButtons.R; } if (keyboard.IsKeyUp(OpenTK.Input.Key.Left)) { if (__isKeyLeftDown) { gamePadData.ButtonsUp |= GamePadButtons.Left; } __isKeyLeftDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.Right)) { if (__isKeyRightDown) { gamePadData.ButtonsUp |= GamePadButtons.Right; } __isKeyRightDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.Up)) { if (__isKeyUpDown) { gamePadData.ButtonsUp |= GamePadButtons.Up; } __isKeyUpDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.Down)) { if (__isKeyDownDown) { gamePadData.ButtonsUp |= GamePadButtons.Down; } __isKeyDownDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.A)) { if (__isKeyADown) { gamePadData.ButtonsUp |= GamePadButtons.Square; } __isKeyADown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.W)) { if (__isKeyWDown) { gamePadData.ButtonsUp |= GamePadButtons.Triangle; } __isKeyWDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.D)) { if (__isKeyDDown) { gamePadData.ButtonsUp |= GamePadButtons.Circle; gamePadData.ButtonsUp |= GamePadButtons.Back; } __isKeyDDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.S)) { if (__isKeySDown) { gamePadData.ButtonsUp |= GamePadButtons.Cross; gamePadData.ButtonsUp |= GamePadButtons.Enter; } __isKeySDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.X)) { if (__isKeyXDown) { gamePadData.ButtonsUp |= GamePadButtons.Start; } __isKeyXDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.Z)) { if (__isKeyZDown) { gamePadData.ButtonsUp |= GamePadButtons.Select; } __isKeyZDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.Q)) { if (__isKeyQDown) { gamePadData.ButtonsUp |= GamePadButtons.L; } __isKeyQDown = false; } if (keyboard.IsKeyUp(OpenTK.Input.Key.E)) { if (__isKeyEDown) { gamePadData.ButtonsUp |= GamePadButtons.R; } __isKeyEDown = false; } } else { __isKeyLeftDown = false; __isKeyRightDown = false; __isKeyUpDown = false; __isKeyDownDown = false; __isKeyADown = false; __isKeyWDown = false; __isKeyDDown = false; __isKeySDown = false; __isKeyXDown = false; __isKeyZDown = false; __isKeyQDown = false; __isKeyEDown = false; } Touch.__data.Clear(); if (__isWinFocused) { //OpenTK.Input.MouseState mouse = OpenTK.Input.Mouse.GetState(); OpenTK.Input.MouseState mouse = OpenTK.Input.Mouse.GetCursorState(); OpenTK.Point pt = SakuraGameWindow.PointToClient(new OpenTK.Point(mouse.X, mouse.Y)); float winW = SakuraGameWindow.getWidth(); float winH = SakuraGameWindow.getHeight(); if (mouse.IsButtonUp(OpenTK.Input.MouseButton.Left)) { if (__isMouseLeftDown == true) { TouchData touchData = new TouchData(); touchData.ID = 0; touchData.Status = TouchStatus.Up; touchData.X = (winW > 0 ? (float)pt.X / winW : 0) - 0.5f; touchData.Y = (winH > 0 ? (float)pt.Y / winH : 0) - 0.5f; Touch.__data.Add(touchData); //Debug.WriteLine("down:" + pt.X + "," + pt.Y); } __isMouseLeftDown = false; } //OpenTK.WindowState wState = MyGameWindow.getWindowState(); //wState != OpenTK.WindowState.Minimized if (mouse.IsButtonDown(OpenTK.Input.MouseButton.Left)) { if (__isMouseLeftDown == false) { TouchData touchData = new TouchData(); touchData.ID = 0; touchData.Status = TouchStatus.Down; touchData.X = (winW > 0 ? (float)pt.X / winW : 0) - 0.5f; touchData.Y = (winH > 0 ? (float)pt.Y / winH : 0) - 0.5f; Touch.__data.Add(touchData); } else { TouchData touchData = new TouchData(); touchData.ID = 0; touchData.Status = TouchStatus.Move; touchData.X = (winW > 0 ? (float)pt.X / winW : 0) - 0.5f; touchData.Y = (winH > 0 ? (float)pt.Y / winH : 0) - 0.5f; Touch.__data.Add(touchData); } __isMouseLeftDown = true; } } else { __isMouseLeftDown = false; } #if false double delta = __timer.Elapsed.TotalMilliseconds; double frame = 1000.0 / 24.0; if (delta < frame) { int free = (int)(frame - delta); Thread.Sleep(free); //Debug.WriteLine("Sleep: " + free); } __timer.Restart(); #endif }
public static void Refresh(int mouseX, int mouseY, bool leftMousePressed, bool middleMousePressed, bool rightMousePressed, OpenTK.Input.KeyboardState keyboard) { _oldMouseX = _mouseX; _oldMouseY = _mouseY; _mouseX = mouseX; _mouseY = mouseY; _relativeMouseX = _mouseX - _oldMouseX; _relativeMouseY = _mouseY - _oldMouseY; _oldLeftMousePressed = _leftMousePressed; _oldMiddleMousePressed = _middleMousePressed; _oldRightMousePressed = _rightMousePressed; _leftMousePressed = leftMousePressed; _middleMousePressed = middleMousePressed; _rightMousePressed = rightMousePressed; _oldKeys = _currentKeys; Keyboard.UpdateFromOpenTK(keyboard); _currentKeys = Keyboard.GetState(); }
protected void KeyPress(OpenTK.Input.KeyboardState keyboardState) { }
public override void Update(TimeSpan delta, OpenTK.Input.KeyboardState keyboardState, OpenTK.Input.KeyboardState previousKeyboardState) { base.Update(delta, keyboardState, previousKeyboardState); }
private void renderControl_Render(object sender, EventArgs e) { this.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} - {1} FPS", Application.ProductName, Core.CurrentFramesPerSecond); RenderControl renderControl = (sender as RenderControl); if (takeScreenshot) { GL.ClearColor(1.0f, 1.0f, 1.0f, 0.0f); } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); // OpenTK GLControl focus checking is GARBAGE, might as well leave the check here off -.- if (renderControl.Focused) { OpenTK.Input.KeyboardState kbdState = OpenTK.Input.Keyboard.GetState(); if (kbdState[OpenTK.Input.Key.Q]) { sunAngle += Core.DeltaTime / 15.0f; } if (kbdState[OpenTK.Input.Key.E]) { sunAngle -= Core.DeltaTime / 15.0f; } lastKbd = kbdState; camera.Update(Core.DeltaTime); } if (wireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } if (culling) { GL.Enable(EnableCap.CullFace); } else { GL.Disable(EnableCap.CullFace); } if (shader != null) { Matrix4 tempMatrix = modelviewMatrix * camera.GetViewMatrix(); shader.SetUniformMatrix(modelviewMatrixName, false, tempMatrix); shader.SetUniform(sunPositionName, new Vector3((float)(Math.Cos(sunAngle * Math.PI / 180.0) * 70.0f), (float)(Math.Sin(sunAngle * Math.PI / 180.0) * 70.0f), 0.0f)); shader.SetUniform(enableLightName, Convert.ToInt32(lighting)); } if (meshes != null) { GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); shader.SetUniform(discardOpaqueName, 0); foreach (Mesh mesh in meshes) { mesh.Render(); } shader.SetUniform(discardOpaqueName, 1); foreach (Mesh mesh in meshes) { mesh.Render(); } } if (!takeScreenshot && font != null) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); StringBuilder builder = new StringBuilder(); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0:0} FPS\n", Core.CurrentFramesPerSecond); if (meshes != null) { builder.AppendLine(); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Camera: WASD & Mouse+Left Button\n"); builder.AppendLine(); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Vsync (F1): {0}\n", renderControl.VSync); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Wireframe (F2): {0}\n", wireframe); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Culling (F3): {0}\n", culling); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Lighting (F4): {0}\n", lighting); builder.AppendLine(); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Rotate Light (Q/E)\n"); } font.DrawString(8.0f, 8.0f, builder.ToString()); } if (takeScreenshot) { renderControl.GrabScreenshot(true).Save(screenshotPath); takeScreenshot = false; GL.ClearColor(renderControl.BackColor); } }
public void tポーリング(bool bWindowがアクティブ中) { for (int i = 0; i < 256; i++) { this.bKeyPushDown[i] = false; this.bKeyPullUp[i] = false; } if (bWindowがアクティブ中) { //this.list入力イベント = new List<STInputEvent>( 32 ); this.list入力イベント.Clear(); // #xxxxx 2012.6.11 yyagi; To optimize, I removed new(); //string d = DateTime.Now.ToString( "yyyy/MM/dd HH:mm:ss.ffff" ); #region [ 入力 ] //----------------------------- OpenTK.Input.KeyboardState currentState = OpenTK.Input.Keyboard.GetState(); if (currentState.IsConnected) { for (int index = 0; index < Enum.GetNames(typeof(OpenTK.Input.Key)).Length; index++) { if (currentState[(OpenTK.Input.Key)index]) { var key = DeviceConstantConverter.TKKtoKey((OpenTK.Input.Key)index); if (SlimDXKey.Unknown == key) { continue; // 未対応キーは無視。 } if (this.bKeyState[(int)key] == false) { if (key != SlimDXKey.Return || (bKeyState[(int)SlimDXKey.LeftAlt] == false && bKeyState[(int)SlimDXKey.RightAlt] == false)) // #23708 2016.3.19 yyagi { var ev = new STInputEvent() { nKey = (int)key, b押された = true, b離された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 nVelocity = CInput管理.n通常音量, }; this.list入力イベント.Add(ev); this.bKeyState[(int)key] = true; this.bKeyPushDown[(int)key] = true; } //if ( (int) key == (int) SlimDXKey.Space ) //{ // Trace.TraceInformation( "FDK(direct): SPACE key registered. " + ct.nシステム時刻 ); //} } } { // #xxxxx: 2017.5.7: from: DIK (SharpDX.DirectInput.Key) を SlimDX.DirectInput.Key に変換。 var key = DeviceConstantConverter.TKKtoKey((OpenTK.Input.Key)index); if (SlimDXKey.Unknown == key) { continue; // 未対応キーは無視。 } if (this.bKeyState[(int)key] == true && !currentState.IsKeyDown((OpenTK.Input.Key)index)) // 前回は押されているのに今回は押されていない → 離された { var ev = new STInputEvent() { nKey = (int)key, b押された = false, b離された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 nVelocity = CInput管理.n通常音量, }; this.list入力イベント.Add(ev); this.bKeyState[(int)key] = false; this.bKeyPullUp[(int)key] = true; } } } } //----------------------------- #endregion } }
public override void Update(TimeSpan delta, OpenTK.Input.KeyboardState keyboardState, OpenTK.Input.KeyboardState previousKeyboardState) { var xSpeed = 700; var ySpeed = 200; var dropSpeed = 150; var leftLimit = 25; var rightLimit = 285; var bottomLimit = 175; // 135 var topLimit = 60; if (this.Y < topLimit) { this.Y = topLimit; } if (leftLimit > this.Left) { this.X = leftLimit; } if (rightLimit < this.Right) { this.X = rightLimit - this.Width; } if (bottomLimit < this.Bottom) { this.Y = bottomLimit - this.Height; } if (retreating) { if (this.Y > 120) // 80 { ApplyImpulse(this.VelY < 0 ? 0 : ((Target.Center.X - this.Center.X) > 0 ? xSpeed : xSpeed * -1), ySpeed * -1); } else { floating = true; retreating = false; stomping = false; angry = false; } } else if (floating) { if (Math.Abs((Target.Center - this.Center).X) < 20) { stomping = true; floating = false; retreating = false; } else { if (this.Y > 70) { ApplyImpulse((Target.Center.X - this.Center.X) > 0 ? xSpeed : xSpeed * -1, ySpeed * -1); } } } else if (stomping) { if (this.Y > 157) // 117 { this.VelY = 0; retreating = true; floating = false; stomping = false; } else { this.VelX = 0; ApplyImpulse(0, dropSpeed); } } if (this.VelY > dropSpeed) { this.VelY = dropSpeed; } foreach (var body in this.CollisionList) { if (body is Killbox) { retreating = true; floating = false; stomping = false; angry = true; } } SetTexture(); base.Update(delta, keyboardState, previousKeyboardState); }
private void window_KeyUp(object sender, TKKeyboardKeyEventArgs e) { this.keyStateBuffer = e.Keyboard; }
// garbage test private Matrix4 GetTransformationMatrix(int baseNodeIdx, int nodeIdx) { Node node = Nodes[nodeIdx]; Vector3[] scales = new Vector3[2]; Vector3[] rotations = new Vector3[2]; Vector3[] translations = new Vector3[2]; for (int i = 0; i < 2; i++) { int transformIdx = (int)((Core.DeltaTime / 16.0f) + i); transformIdx = tmpTransformIdx + i; if (transformIdx >= nodeTransforms[nodeIdx].Length) { transformIdx %= nodeTransforms[nodeIdx].Length; } NodeTransformData nodeTransform = nodeTransforms[nodeIdx][transformIdx]; scales[i] = new Vector3(nodeTransform.ScaleX.Value0x00, nodeTransform.ScaleY.Value0x00, nodeTransform.ScaleZ.Value0x00); rotations[i] = new Vector3(nodeTransform.RotationX.Value0x00, nodeTransform.RotationY.Value0x00, nodeTransform.RotationZ.Value0x00); translations[i] = new Vector3(nodeTransform.TranslationX.Value0x00, nodeTransform.TranslationY.Value0x00, -nodeTransform.TranslationZ.Value0x00) * 10.0f; } // garbage test OpenTK.Input.KeyboardState tmpKbd = OpenTK.Input.Keyboard.GetState(); if (tmpKbd[OpenTK.Input.Key.KeypadPlus]) { blend += 0.000005f; } if (tmpKbd[OpenTK.Input.Key.KeypadMinus]) { blend -= 0.000005f; } if (blend < 0.0f) { blend = 0.0f; } if (blend > 1.0f) { blend = 1.0f; } if (tmpKbd[OpenTK.Input.Key.Keypad7] && !tmpLastKbd[OpenTK.Input.Key.Keypad7]) { tmpTransformIdx--; } if (tmpKbd[OpenTK.Input.Key.Keypad9] && !tmpLastKbd[OpenTK.Input.Key.Keypad9]) { tmpTransformIdx++; } tmpLastKbd = tmpKbd; // garbage test Matrix4 localMatrix = Matrix4.Identity; localMatrix *= Matrix4.CreateScale(Vector3.Lerp(scales[0], scales[1], blend)); localMatrix *= Matrix4.CreateRotationX(Vector3.Lerp(rotations[0], rotations[1], blend).X); localMatrix *= Matrix4.CreateRotationY(Vector3.Lerp(rotations[0], rotations[1], blend).Y); localMatrix *= Matrix4.CreateRotationZ(Vector3.Lerp(rotations[0], rotations[1], blend).Z); localMatrix *= Matrix4.CreateTranslation(Vector3.Lerp(translations[0], translations[1], blend)); if (node.RelatedNodeIndex != -1) { int relativeNodeIdx = baseNodeIdx + node.RelatedNodeIndex; if (relativeNodeIdx != nodeIdx) { localMatrix *= GetTransformationMatrix(baseNodeIdx, relativeNodeIdx); } } return(localMatrix); }
public override bool IsKeyDown(int key) { OpenTK.Input.KeyboardState state = OpenTK.Input.Keyboard.GetState(); return(state.IsKeyDown((OpenTK.Input.Key)key)); }
internal KeyboardKeyEventArgs(Keyboard.Key keyCode, OpenTK.Input.KeyboardState state, bool isRepeat) { KeyCode = keyCode; _state = state; _isRepeat = isRepeat; }
private void renderControl1_Render(object sender, EventArgs e) { this.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} - {1} FPS", Application.ProductName, Core.CurrentFramesPerSecond); RenderControl renderControl = (sender as RenderControl); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); OpenTK.Input.KeyboardState kbdState = OpenTK.Input.Keyboard.GetState(); if (renderControl.Focused) { if (kbdState[OpenTK.Input.Key.Escape] && !lastKbd[OpenTK.Input.Key.Escape]) { Application.Exit(); } if (kbdState[OpenTK.Input.Key.F1] && !lastKbd[OpenTK.Input.Key.F1]) { renderControl.VSync = !renderControl.VSync; } if (kbdState[OpenTK.Input.Key.F2] && !lastKbd[OpenTK.Input.Key.F2]) { wireframe = !wireframe; } if (kbdState[OpenTK.Input.Key.F3] && !lastKbd[OpenTK.Input.Key.F3]) { culling = !culling; } } lastKbd = kbdState; if (renderControl.ClientRectangle.Contains(this.PointToClient(Control.MousePosition))) { camera.Update(Core.DeltaTime); } if (wireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } if (culling) { GL.Enable(EnableCap.CullFace); } else { GL.Disable(EnableCap.CullFace); } if (shader != null) { Matrix4 tempMatrix = modelviewMatrix * camera.GetViewMatrix(); shader.SetUniformMatrix(modelviewMatrixName, false, tempMatrix); } if (obfBinary != null) { GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); if (shader != null) { shader.SetUniform("alpha_reference", 0.5f); } for (int i = 1; i >= 0; i--) { if (shader != null) { shader.SetUniform("alpha_doLessThan", (int)i); } if (tsbRenderAll.Checked) { obfBinary.RenderAssets(shader); } else { var selection = tscmbAssets.ComboBox.SelectedItem; obfBinary.RenderAsset(((KeyValuePair <short, ICollection <short> >)selection).Key, shader); } } } if (font != null) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); StringBuilder builder = new StringBuilder(); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0:0} FPS\n", Core.CurrentFramesPerSecond); builder.AppendLine(); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Vsync (F1): {0}\n", renderControl.VSync); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Wireframe (F2): {0}\n", wireframe); builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Culling (F3): {0}\n", culling); font.DrawString(8.0f, 8.0f, builder.ToString()); } }