public static Vector2 ThumbMovement(Vector2 state) { float xb = state.X; float yb = state.Y; Vector2 direction = new Vector2(xb, yb); float deadZone = 0.3f; if (direction.Length() < deadZone) { direction = Vector2.Zero; } else { direction = direction.GetNormalized() * ((direction.Length() - deadZone) / (1 - deadZone)); } //if (direction.Length() > 0.95f) //{ // float magnitude = 0.95f; // direction.Normalize(); // direction.X = direction.X * magnitude; // direction.Y = direction.Y * magnitude; //} return direction; }
public override void Update() { if (Input.KeyDown(Keys.Space)) { base.AddTask(new Task_ChopTree(Input.MouseWorldTilePos.X, Input.MouseWorldTilePos.Y)); } Velocity = Vector2.Zero; if (CurrentPath != null) { (Vector2 nextPos, int nextIndex) = GetClosestPathPoint(); Vector2 direction = (nextPos - Center); Velocity += direction.GetNormalized() * 5f; if (direction.LengthSquared() <= Tile.SIZE * 0.5f) { for (int i = 0; i < nextIndex + 1; i++) { CurrentPath.RemoveAt(0); } if (CurrentPath.Count == 0) { CurrentPath = null; } } } if (CurrentPath == null) { //PlotPath(TilePosition.X + Rand.Range(-10, 11), TilePosition.Y + Rand.Range(-10, 11)); } }
public void GetNormalizedTest() { Vector2 target = new Vector2(3, 4); float actual = target.GetNormalized().Magnitude; Assert.AreEqual(1, actual); }
/// <summary> /// Finds the angle in radians between the Vector2 and specified other Vector2. /// </summary> /// <param name="compareTo">Other Vector2 to compare to for angle calculation.</param> public float AngleBetween(Vector2 compareTo) { // Normalize both Vector2s Vector2 a = GetNormalized(); Vector2 b = compareTo.GetNormalized(); return((float)Math.Acos(a.DotProduct(b))); }
public void normalized() { var v = new Vector2(3, 4); v = v.GetNormalized(); Assert.Equal(3.0 / 5.0, v.X); Assert.Equal(4.0 / 5.0, v.Y); }
// In case maxLength = 1: "normalize if length is greater than one." public static Vector2 GetClampedTo(this Vector2 v, float maxLength) { Vector2 result = v; if (result.LengthSquared() > maxLength * maxLength) { result = result.GetNormalized() * maxLength; } return(result); }
static public Vector2 BindAround(this Vector2 item, float radius) { float distance; Vector2 direction = item.GetNormalized(out distance); if (distance > radius) { return(direction * radius); } return(item); }
/// <summary> /// Gets the line end point. /// </summary> /// <param name="startPoint">The start point.</param> /// <param name="direction">The direction.</param> /// <param name="length">The length.</param> /// <returns>The end point of a line.</returns> public static Vector2 GetLineEndPoint(this Vector2 startPoint, Vector2 direction, float length) { return(startPoint + direction.GetNormalized() * length); }
static public Vector2 BindMagnitudeBetween(this Vector2 item, float value1, float value2) { float magnitude; return(item.GetNormalized(out magnitude) * magnitude.BindBetween(value1, value2)); }
static public Vector2 BindMagnitudeBelow(this Vector2 item, float upper) { float magnitude; return(item.GetNormalized(out magnitude) * magnitude.BindBelow(upper)); }
static public Vector2 BindMagnitudeAbove(this Vector2 item, float lower) { float magnitude; return(item.GetNormalized(out magnitude) * magnitude.BindAbove(lower)); }
public Ray2(Vector2 o, Vector2 d) { origin = o; direction = d.GetNormalized(); }
static public Plane2 CreateNormalAndPoint(Vector2 normal, Vector2 point) { normal = normal.GetNormalized(); return(CreateNormalAndDistance(normal, normal.GetDot(point))); }
public Plane2(Vector2 n, float d) { normal = n.GetNormalized(); distance = d; }