public void Update(double elapsedTime) { // Get controls and apply to player character double _x = _input.Controller.LeftControlStick.X; double _y = _input.Controller.LeftControlStick.Y * -1; Vector controlInput = new Vector(_x, _y, 0); if (Math.Abs(controlInput.Length()) < 0.0001) { // If the input is very small, then the player may not be using // a controller;, they might be using the keyboard. if (_input.Keyboard.IsKeyHeld(Keys.Left)) { controlInput.X = -1; } if (_input.Keyboard.IsKeyHeld(Keys.Right)) { controlInput.X = 1; } if (_input.Keyboard.IsKeyHeld(Keys.Up)) { controlInput.Y = 1; } if (_input.Keyboard.IsKeyHeld(Keys.Down)) { controlInput.Y = -1; } } _playerCharacter.Move(controlInput * elapsedTime); }
public Vector Normalise(Vector v) { double r = v.Length(); if (r != 0.0) // guard against divide by zero { return new Vector(v.X / r, v.Y / r, v.Z / r); // normalise and return } else { return new Vector(0, 0, 0); } }
public Vector Normalize(Vector v) { double r = v.Length(); if (r != 0.0) { return new Vector(X / r, Y / r, Z / r); } else { return new Vector(0, 0, 0); } }
public Vector Normalise(Vector v) { double r = v.Length(); if (r != 0.0) { return new Vector(v.X/r, v.Y/r, v.Z/r); } return new Vector(0, 0, 0); }