public void UpdatePlayerOriantation(Point MousePos) { Vector2 Newvec = new Vector2(MousePos.X - Playerposition.X, MousePos.Y - Playerposition.Y); float Rangel = (float)Math.Acos((Newvec * DefulltOriantation) / (Newvec.GetMagnitude() * DefulltOriantation.GetMagnitude())); float angle = 180 * Rangel / (float)Math.PI; PlayerOriantation = angle; }
static public void SetPlanarSpriteAsLine(this Transform item, Vector2 point1, Vector2 point2, float total_margin = 0.0f) { Vector2 diff = point2 - point1; item.SetPlanarPosition(point1.GetMidpoint(point2)); item.SetPlanarRotation(diff.GetAngleInDegrees()); item.SetPlanarSpriteWidth((diff.GetMagnitude() - total_margin).BindAbove(0.0f)); }
public void magnitude() { var a = new Vector2(3, 4); Assert.Equal(5, a.GetMagnitude()); a = new Vector2(-3, 4); Assert.Equal(5, a.GetMagnitude()); }
public virtual void Update() { _velocity.X = 1; float _magnitude = _velocity.GetMagnitude(); _velocity *= 5; _magnitude = _velocity.GetMagnitude(); _position.X = Math.Clamp(_position.X, 0, Console.WindowWidth - 1); _position.Y = Math.Clamp(_position.Y, 0, Console.WindowHeight - 1); }
static public Vector2 GetNormalized(this Vector2 item, out float magnitude) { magnitude = item.GetMagnitude(); if (magnitude != 0.0f) { return(item / magnitude); } return(Vector2.zero); }
public override void Update() { int xVelocity = -Convert.ToInt32(Game.GetKeyDown((int)KeyboardKey.KEY_A)) + Convert.ToInt32(Game.GetKeyDown((int)KeyboardKey.KEY_D)); int yVelocity = -Convert.ToInt32(Game.GetKeyDown((int)KeyboardKey.KEY_W)) + Convert.ToInt32(Game.GetKeyDown((int)KeyboardKey.KEY_S)); Velocity = new Vector2(xVelocity, yVelocity); if (Velocity.GetMagnitude() != 0) { Velocity.X /= Velocity.GetMagnitude(); Velocity.Y /= Velocity.GetMagnitude(); } //ConsoleKey keyPressed = Game.GetNextKey(); //switch (keyPressed) //{ // case ConsoleKey.A: // _velocity.X = -1; // break; // case ConsoleKey.D: // _velocity.X = 1; // break; // case ConsoleKey.W: // _velocity.Y = -1; // break; // case ConsoleKey.S: // _velocity.Y = 1; // break; // case ConsoleKey.Spacebar: // Game.SetCurrentScene(1); // break; // default: // _velocity.X = 0; // _velocity.Y = 0; // break; //} base.Update(); }
static public void DrawLine(Vector2 p1, Vector2 p2, float line_thickness = 1.0f) { Vector2 diff = p2 - p1; float angle = diff.GetAngleInDegrees(); float distance = diff.GetMagnitude(); GUIUtility.RotateAroundPivot(angle, p1); GUI.DrawTexture( p1.GetRect().GetEnlarged(0.0f, line_thickness * 0.5f, distance, line_thickness * 0.5f), GetWhitePixelTexture() ); GUIUtility.RotateAroundPivot(-angle, p1); }
static public Vector2 GetNormalized(this Vector2 item) { return(item / item.GetMagnitude()); }