/*public Guid? DeviceID { get { return null; } } * public PlayerIndex? XNAPlayerIndex { get { return null; } }*/ // --- Methods // - IR2DInput public void Refresh() // _CalculateVector() { _Keyboard = FRBInput.InputManager.Keyboard; // ** vector Length = √( x2 + y2 ) = √(x*x + y*y) // vector x y from length = //MathFunctions.AngleToVector() //Vector2 facingVector = Vector2.Zero; _Facing.X = 0f; _Facing.Y = 0f; _Length = 0f; if (KeyUp.HasValue && _Keyboard.KeyDown(KeyUp.Value)) { _GotInput = true; _Facing += Input2D_Keyboard_8Way.VECTOR_UP; } if (KeyDown.HasValue && _Keyboard.KeyDown(KeyDown.Value)) { _GotInput = true; _Facing += Input2D_Keyboard_8Way.VECTOR_DOWN; } if (KeyLeft.HasValue && _Keyboard.KeyDown(KeyLeft.Value)) { _GotInput = true; _Facing += Input2D_Keyboard_8Way.VECTOR_LEFT; } if (KeyRight.HasValue && _Keyboard.KeyDown(KeyRight.Value)) { _GotInput = true; _Facing += Input2D_Keyboard_8Way.VECTOR_RIGHT; } if (_GotInput) { // Does resulting vector have lenght ? _Facing.Normalize(); if (Single.IsNaN(_Facing.X) || Single.IsNaN(_Facing.Y) || Single.IsInfinity(_Facing.X) || Single.IsInfinity(_Facing.Y)) { // _Facing is not valid = Character is not really moving => replace it with Zero _Facing.X = 0f; _Facing.Y = 0f; _Length = 0f; _GotInput = false; } else { _Length = _Facing.Length(); } } }
public static void CameraControlFps(Camera camera) { GuiManager.Cursor.StaticPosition = true; Vector3 up = new Vector3(0, 1, 0); camera.Velocity = new Vector3(); Keys forwardKey = Keys.W; Keys backKey = Keys.S; Keys leftKey = Keys.A; Keys rightKey = Keys.D; FlatRedBall.Input.Keyboard keyboard = InputManager.Keyboard; float movementSpeed = 7; if (keyboard.KeyDown(forwardKey)) { camera.Velocity += new Vector3(camera.RotationMatrix.M31, camera.RotationMatrix.M32, camera.RotationMatrix.M33) * movementSpeed; } else if (keyboard.KeyDown(backKey)) { camera.Velocity += new Vector3(camera.RotationMatrix.M31, camera.RotationMatrix.M32, camera.RotationMatrix.M33) * -movementSpeed; } if (keyboard.KeyDown(leftKey)) { camera.Velocity += new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13) * -movementSpeed; } if (keyboard.KeyDown(rightKey)) { camera.Velocity += new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13) * movementSpeed; } #if FRB_XNA // These vaules may be way too fast/slow because I modified it to use pixels rather // than the somewhat arbitrary world coordinates camera.RotationMatrix *= Matrix.CreateFromAxisAngle( camera.RotationMatrix.Right, -.2f * GuiManager.Cursor.ScreenYChange * TimeManager.SecondDifference); camera.RotationMatrix *= Matrix.CreateFromAxisAngle( up, -.2f * GuiManager.Cursor.ScreenXChange * TimeManager.SecondDifference); #elif FRB_MDX camera.RotationMatrix *= Matrix.RotationAxis( new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13), -.2f * GuiManager.Cursor.YVelocity * TimeManager.SecondDifference); camera.RotationMatrix *= Matrix.RotationAxis( up, -.2f * GuiManager.Cursor.XVelocity * TimeManager.SecondDifference); #endif }
/*public Guid? DeviceID { get { return null; } } * public PlayerIndex? XNAPlayerIndex { get { return null; } }*/ // --- Methods // - IR2DInput public void Refresh() // _CalculateVector() { _Keyboard = FRBInput.InputManager.Keyboard; // ** vector Length = √( x2 + y2 ) = √(x*x + y*y) // vector x y from length = //MathFunctions.AngleToVector() //Vector2 facingVector = Vector2.Zero; _Facing.X = 0f; _Facing.Y = 0f; _Length = 0f; if (_Keyboard.KeyDown(Keys.Up) || _Keyboard.KeyDown(Keys.NumPad8)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_UP; } if (_Keyboard.KeyDown(Keys.Down) || _Keyboard.KeyDown(Keys.NumPad2)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_DOWN; } if (_Keyboard.KeyDown(Keys.Left) || _Keyboard.KeyDown(Keys.NumPad4)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_LEFT; } if (_Keyboard.KeyDown(Keys.Right) || _Keyboard.KeyDown(Keys.NumPad6)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_RIGHT; } if (_Keyboard.KeyDown(Keys.NumPad1)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_LEFT_DOWN; } if (_Keyboard.KeyDown(Keys.NumPad3)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_RIGHT_DOWN; } if (_Keyboard.KeyDown(Keys.NumPad9)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_RIGHT_UP; } if (_Keyboard.KeyDown(Keys.NumPad7)) { _GotInput = true; _Facing += Input2DKeyboard8Way.VECTOR_LEFT_UP; } if (_GotInput) { // Does resulting vector have lenght ? _Facing.Normalize(); if (Single.IsNaN(_Facing.X) || Single.IsNaN(_Facing.Y) || Single.IsInfinity(_Facing.X) || Single.IsInfinity(_Facing.Y)) { // No (is not valid) = Character is not really moving => replace it with Zero // keep facing vector as it was //_FacingVectorN = Vector2.Zero; _Facing.X = 0f; _Facing.Y = 0f; _Length = 0f; _GotInput = false; // facingChanged remains false } else { _Length = _Facing.Length(); } } }