public void updateCamera(OpenTK.Input.KeyboardDevice keyboard, OpenTK.Input.MouseDevice mouse) { const float speed = 1.0f; const float mouseSpeed = 0.5f; camAngle.Y += mouse.XDelta * mouseSpeed; camAngle.X += mouse.YDelta * mouseSpeed; Vector2 RadAng = new Vector2(); RadAng.X = (camAngle.X / 180 * Math.PI); RadAng.Y = (camAngle.Y / 180 * Math.PI); if (keyboard[OpenTK.Input.Key.W]) { camCoord.X -= (float)(Math.Sin(RadAng.Y) * speed); camCoord.Z += (float)(Math.Cos(RadAng.Y) * speed); camCoord.Y += (float)(Math.Sin(RadAng.X) * speed); } if (keyboard[OpenTK.Input.Key.S]) { camCoord.X += (float)(Math.Sin(RadAng.Y) * speed); camCoord.Z -= (float)(Math.Cos(RadAng.Y) * speed); camCoord.Y -= (float)(Math.Sin(RadAng.X) * speed); } if (keyboard[OpenTK.Input.Key.D]) { camCoord.X -= (float)(Math.Cos(RadAng.Y) * speed); camCoord.Z -= (float)(Math.Sin(RadAng.Y) * speed); } if (keyboard[OpenTK.Input.Key.A]) { camCoord.X += (float)(Math.Cos(RadAng.Y) * speed); camCoord.Z += (float)(Math.Sin(RadAng.Y) * speed); } if (camAngle.X > 89) { camAngle.X = 89; } if (camAngle.X < -89) { camAngle.X = -89; } if (camAngle.Y > 360) { camAngle.Y -= 360; } else if (camAngle.Y < 0) { camAngle.Y += 360; } }
public void updatePlayerPos(OpenTK.Input.KeyboardDevice keyboard, double elapsedTime, bool cameraMode) { if (keyboard != null) { getNewDirection(keyboard, elapsedTime, cameraMode); } if (directionChanged) { createNewTrail(); directionChanged = false; } switch (direction) { case PlayerDirection.UP: position.X += speed * elapsedTime; setPosition(position); break; case PlayerDirection.LEFT: position.Z -= speed * elapsedTime; setPosition(position); break; case PlayerDirection.DOWN: position.X -= speed * elapsedTime; setPosition(position); break; case PlayerDirection.RIGHT: position.Z += speed * elapsedTime; setPosition(position); break; } }
internal KeyboardDevice(TkKeyboardDevice keyboardDevice) { this.keyboardDevice = keyboardDevice; }
void Keyboard_KeyUp(OpenTK.Input.KeyboardDevice sender, OpenTK.Input.Key key) { KeyCode code = TransformKey(key); Keyboard.Keys[code] = false; }
void Keyboard_KeyDown(OpenTK.Input.KeyboardDevice sender, OpenTK.Input.Key key) { KeyCode code = TransformKey(key); Keyboard.Keys[code] = true; }
public void getNewDirection(OpenTK.Input.KeyboardDevice keyboard, double elapsedTime, bool cameraMode) { //TODO: O movimento deve ser diferente na camera de cima. Ver definicao do trabalho. inputTimeBuffer += elapsedTime; if (!cameraMode) //3rd person { if (keyboard[OpenTK.Input.Key.Left]) { if (inputTimeBuffer < INPUT_DELAY) { return; } else { inputTimeBuffer = 0; } switch (direction) { case PlayerDirection.UP: setDirection(PlayerDirection.LEFT); break; case PlayerDirection.LEFT: setDirection(PlayerDirection.DOWN); break; case PlayerDirection.DOWN: setDirection(PlayerDirection.RIGHT); break; case PlayerDirection.RIGHT: setDirection(PlayerDirection.UP); break; } } else if (keyboard[OpenTK.Input.Key.Right]) { if (inputTimeBuffer < INPUT_DELAY) { return; } else { inputTimeBuffer = 0; } switch (direction) { case PlayerDirection.UP: setDirection(PlayerDirection.RIGHT); break; case PlayerDirection.LEFT: setDirection(PlayerDirection.UP); break; case PlayerDirection.DOWN: setDirection(PlayerDirection.LEFT); break; case PlayerDirection.RIGHT: setDirection(PlayerDirection.DOWN); break; } } } else //Top View { if (keyboard[OpenTK.Input.Key.Left]) { if (inputTimeBuffer < INPUT_DELAY) { return; } else { inputTimeBuffer = 0; } if (direction != PlayerDirection.RIGHT && direction != PlayerDirection.LEFT) { setDirection(PlayerDirection.LEFT); } } else if (keyboard[OpenTK.Input.Key.Right]) { if (inputTimeBuffer < INPUT_DELAY) { return; } else { inputTimeBuffer = 0; } if (direction != PlayerDirection.RIGHT && direction != PlayerDirection.LEFT) { setDirection(PlayerDirection.RIGHT); } } else if (keyboard[OpenTK.Input.Key.Up]) { if (inputTimeBuffer < INPUT_DELAY) { return; } else { inputTimeBuffer = 0; } if (direction != PlayerDirection.UP && direction != PlayerDirection.DOWN) { setDirection(PlayerDirection.UP); } } else if (keyboard[OpenTK.Input.Key.Down]) { if (inputTimeBuffer < INPUT_DELAY) { return; } else { inputTimeBuffer = 0; } if (direction != PlayerDirection.UP && direction != PlayerDirection.DOWN) { setDirection(PlayerDirection.DOWN); } } } }
public GLKeyboard(OpenTK.Input.KeyboardDevice keydev) { mdev = keydev; mdev.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(mdev_KeyDown); mdev.KeyUp += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(mdev_KeyUp); }