public virtual void SetPosition(Vector2f newPosition) { if (!newPosition.Equals(this._position)) { this.Position(newPosition); } }
private List <Vector2f> Astar(Field2D field_0, bool flag_1) { for (; pathes.Count > 0;) { AStarFinder.ScoredPath spath_2 = (AStarFinder.ScoredPath)CollectionUtils.RemoveAt(pathes, 0); Vector2f current = spath_2.path[spath_2.path.Count - 1]; if (current.Equals(goal)) { return(spath_2.path); } List <Vector2f> list = field_0.Neighbors(current, flag_1); int size = list.Count; for (int i = 0; i < size; i++) { Vector2f next = list[i]; if (CollectionUtils.Contains(next, visitedCache)) { continue; } CollectionUtils.Add(visitedCache, next); if (!field_0.IsHit(next) && !flying) { continue; } List <Vector2f> path_3 = new List <Vector2f>(spath_2.path); CollectionUtils.Add(path_3, next); float score = spath_2.score + findHeuristic .GetScore(goal.x, goal.y, next.x, next.y); Insert(score, path_3); } } return(null); }
/// <summary> /// Получение единичного вектора из текущего вектора /// </summary> public static Vector2f GetUnitVector(this Vector2f vector) { if (vector.Equals(new Vector2f())) { return(vector); } return(vector / vector.GetLength()); }
/// <summary> /// Получение единичного вектора по 2 точкам /// </summary> /// <param name="start"> точка начала </param> /// <param name="end"> точка конца </param> /// <returns>единичный вектор</returns> public static Vector2f GetUnitVectorTo(this Vector2f start, Vector2f end) { if (start.Equals(end)) { return(new Vector2f(0, 0)); } var vector = end - start; return(vector / vector.GetLength()); }
/// <summary> /// Получение единичного вектора и расстояния между точками /// </summary> /// <param name="start"> точка начала </param> /// <param name="end"> точка конца </param> /// <returns>единичный вектор, расстояние между точками</returns> public static (Vector2f, float) GetUnitVectorAndRange(this Vector2f start, Vector2f end) { if (start.Equals(end)) { return(new Vector2f(0, 0), 0); } var vector = end - start; var range = vector.GetLength(); return(vector / range, range); }
public static Vector2f GetUnitVectorToTarget(this Vector2f start, Vector2f end) { if (start.Equals(end)) { return(new Vector2f(0, 0)); } var vector = end - start; var lenght = GetLenght(vector); return(vector / lenght); }
/// <summary> /// Converts the arc in a list of vertexes. /// </summary> /// <param name="precision">Number of vertexes generated.</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <returns>A list vertexes that represents the arc expresed in object coordinate system.</returns> public List <Vector2f> PoligonalVertexes(int precision, double weldThreshold) { if (precision < 2) { throw new ArgumentOutOfRangeException("The arc precision must be greater or equal to two"); } List <Vector2f> ocsVertexes = new List <Vector2f>(); double start = (double)(this.startAngle * MathHelper.DegToRad); double end = (double)(this.endAngle * MathHelper.DegToRad); if (2 * this.radius >= weldThreshold) { double angulo = (end - start) / precision; Vector2f prevPoint; Vector2f firstPoint; double sine = (double)(this.radius * Math.Sin(start)); double cosine = (double)(this.radius * Math.Cos(start)); firstPoint = new Vector2f(cosine + this.center.X, sine + this.center.Y); ocsVertexes.Add(firstPoint); prevPoint = firstPoint; for (int i = 1; i <= precision; i++) { sine = (double)(this.radius * Math.Sin(start + angulo * i)); cosine = (double)(this.radius * Math.Cos(start + angulo * i)); Vector2f point = new Vector2f(cosine + this.center.X, sine + this.center.Y); if (!point.Equals(prevPoint, weldThreshold) && !point.Equals(firstPoint, weldThreshold)) { ocsVertexes.Add(point); prevPoint = point; } } } return(ocsVertexes); }
public dynamic GetTarget() { if (Target != null) { return(Target.Position); } else if (!Waypoint.Equals(new Vector2f(-1, -1))) { return(Waypoint); } return(null); }
/// <summary> /// Converts the circle in a list of vertexes. /// </summary> /// <param name="precision">Number of vertexes generated.</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <returns>A list vertexes that represents the circle expresed in object coordinate system.</returns> public List <Vector2f> PoligonalVertexes(int precision, float weldThreshold) { if (precision < 3) { throw new ArgumentOutOfRangeException("precision", precision, "The circle precision must be greater or equal to three"); } List <Vector2f> ocsVertexes = new List <Vector2f>(); if (2 * this.radius >= weldThreshold) { float angulo = (float)(MathHelper.TwoPI / precision); Vector2f prevPoint; Vector2f firstPoint; float sine = (float)(this.radius * Math.Sin(MathHelper.HalfPI * 0.5)); float cosine = (float)(this.radius * Math.Cos(MathHelper.HalfPI * 0.5)); firstPoint = new Vector2f(cosine + this.center.X, sine + this.center.Y); ocsVertexes.Add(firstPoint); prevPoint = firstPoint; for (int i = 1; i < precision; i++) { sine = (float)(this.radius * Math.Sin(MathHelper.HalfPI + angulo * i)); cosine = (float)(this.radius * Math.Cos(MathHelper.HalfPI + angulo * i)); Vector2f point = new Vector2f(cosine + this.center.X, sine + this.center.Y); if (!point.Equals(prevPoint, weldThreshold) && !point.Equals(firstPoint, weldThreshold)) { ocsVertexes.Add(point); prevPoint = point; } } } return(ocsVertexes); }
private List <Vector2f> Calc(Field2D field_0, Vector2f start, Vector2f goal_1, bool flag_2) { if (start.Equals(goal_1)) { List <Vector2f> v = new List <Vector2f>(); CollectionUtils.Add(v, start); return(v); } this.goal = goal_1; if (visitedCache == null) { visitedCache = new HashedSet(); } else { CollectionUtils.Clear(visitedCache); } if (pathes == null) { pathes = new List <ScoredPath>(); } else { CollectionUtils.Clear(pathes); } CollectionUtils.Add(visitedCache, start); if (path == null) { path = new List <Vector2f>(); } else { CollectionUtils.Clear(path); } CollectionUtils.Add(path, start); if (spath == null) { spath = new AStarFinder.ScoredPath(0, path); } else { spath.score = 0; spath.path = path; } CollectionUtils.Add(pathes, spath); return(Astar(field_0, flag_2)); }
private List <Vector2f> Calc(Field2D field, Vector2f start, Vector2f goal, bool flag) { if (start.Equals(goal)) { List <Vector2f> v = new List <Vector2f>(); v.Add(start); return(v); } this.goal = goal; if (visitedCache == null) { visitedCache = new HashedSet(); } else { visitedCache.Clear(); } if (pathes == null) { pathes = new List <ScoredPath>(); } else { pathes.Clear(); } visitedCache.Add(start); if (path == null) { path = new List <Vector2f>(); } else { path.Clear(); } path.Add(start); if (spath == null) { spath = new ScoredPath(0, path); } else { spath.score = 0; spath.path = path; } pathes.Add(spath); return(Astar(field, flag)); }
/// <summary> /// Converts the arc in a list of vertexes. /// </summary> /// <param name="precision">Number of vertexes generated.</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <returns>A list vertexes that represents the arc expresed in object coordinate system.</returns> public List<Vector2f> PoligonalVertexes(int precision, float weldThreshold) { if (precision < 2) throw new ArgumentOutOfRangeException("precision", precision, "The arc precision must be greater or equal to two"); List<Vector2f> ocsVertexes = new List<Vector2f>(); float start = (float)(this.startAngle * MathHelper.DegToRad); float end = (float)(this.endAngle * MathHelper.DegToRad); if (2*this.radius >= weldThreshold) { float angulo = (end - start)/precision; Vector2f prevPoint; Vector2f firstPoint; float sine = (float) (this.radius*Math.Sin(start)); float cosine = (float) (this.radius*Math.Cos(start)); firstPoint = new Vector2f(cosine + this.center.X, sine + this.center.Y); ocsVertexes.Add(firstPoint); prevPoint = firstPoint; for (int i = 1; i <= precision; i++) { sine = (float) (this.radius*Math.Sin(start + angulo*i)); cosine = (float) (this.radius*Math.Cos(start + angulo*i)); Vector2f point = new Vector2f(cosine + this.center.X, sine + this.center.Y); if (!point.Equals(prevPoint, weldThreshold) && !point.Equals(firstPoint, weldThreshold)) { ocsVertexes.Add(point); prevPoint = point; } } } return ocsVertexes; }
/// <summary> /// Obtains a list of vertexes that represent the polyline approximating the curve segments as necessary. /// </summary> /// <param name="bulgePrecision">Curve segments precision (a value of zero means that no approximation will be made).</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <param name="bulgeThreshold">Minimun distance from which approximate curved segments of the polyline.</param> /// <returns>The return vertexes are expresed in object coordinate system.</returns> public List<Vector2f> PoligonalVertexes(int bulgePrecision, float weldThreshold, float bulgeThreshold) { List<Vector2f> ocsVertexes = new List<Vector2f>(); int index = 0; foreach (PolylineVertex vertex in this.Vertexes) { float bulge = vertex.Bulge; Vector2f p1; Vector2f p2; if (index == this.Vertexes.Count - 1) { p1 = new Vector2f(vertex.Location.X, vertex.Location.Y); p2 = new Vector2f(this.vertexes[0].Location.X, this.vertexes[0].Location.Y); } else { p1 = new Vector2f(vertex.Location.X, vertex.Location.Y); p2 = new Vector2f(this.vertexes[index + 1].Location.X, this.vertexes[index + 1].Location.Y); } if (!p1.Equals(p2, weldThreshold)) { if (bulge == 0 || bulgePrecision == 0) { ocsVertexes.Add(p1); } else { float c = Vector2f.Distance(p1, p2); if (c >= bulgeThreshold) { float s = (c/2)*Math.Abs(bulge); float r = ((c/2)*(c/2) + s*s)/(2*s); float theta = (float) (4*Math.Atan(Math.Abs(bulge))); float gamma = (float) ((Math.PI - theta)/2); float phi; if (bulge > 0) { phi = Vector2f.AngleBetween(Vector2f.UnitX, p2 - p1) + gamma; } else { phi = Vector2f.AngleBetween(Vector2f.UnitX, p2 - p1) - gamma; } Vector2f center = new Vector2f((float) (p1.X + r*Math.Cos(phi)), (float) (p1.Y + r*Math.Sin(phi))); Vector2f a1 = p1 - center; float angle = 4*((float) (Math.Atan(bulge)))/(bulgePrecision + 1); ocsVertexes.Add(p1); for (int i = 1; i <= bulgePrecision; i++) { Vector2f curvePoint = new Vector2f(); Vector2f prevCurvePoint = new Vector2f(this.vertexes[this.vertexes.Count - 1].Location.X, this.vertexes[this.vertexes.Count - 1].Location.Y); curvePoint.X = center.X + (float) (Math.Cos(i*angle)*a1.X - Math.Sin(i*angle)*a1.Y); curvePoint.Y = center.Y + (float) (Math.Sin(i*angle)*a1.X + Math.Cos(i*angle)*a1.Y); if (!curvePoint.Equals(prevCurvePoint, weldThreshold) && !curvePoint.Equals(p2, weldThreshold)) { ocsVertexes.Add(curvePoint); } } } else { ocsVertexes.Add(p1); } } } index++; } return ocsVertexes; }
/// <summary> /// Converts the circle in a list of vertexes. /// </summary> /// <param name="precision">Number of vertexes generated.</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <returns>A list vertexes that represents the circle expresed in object coordinate system.</returns> public List<Vector2f> PoligonalVertexes(int precision, float weldThreshold) { if (precision < 3) throw new ArgumentOutOfRangeException("precision", precision, "The circle precision must be greater or equal to three"); List<Vector2f> ocsVertexes = new List<Vector2f>(); if (2*this.radius >= weldThreshold) { float angulo = (float) (MathHelper.TwoPI/precision); Vector2f prevPoint; Vector2f firstPoint; float sine = (float) (this.radius*Math.Sin(MathHelper.HalfPI*0.5)); float cosine = (float) (this.radius*Math.Cos(MathHelper.HalfPI*0.5)); firstPoint = new Vector2f(cosine + this.center.X, sine + this.center.Y); ocsVertexes.Add(firstPoint); prevPoint = firstPoint; for (int i = 1; i < precision; i++) { sine = (float) (this.radius*Math.Sin(MathHelper.HalfPI + angulo*i)); cosine = (float) (this.radius*Math.Cos(MathHelper.HalfPI + angulo*i)); Vector2f point = new Vector2f(cosine + this.center.X, sine + this.center.Y); if (!point.Equals(prevPoint, weldThreshold) && !point.Equals(firstPoint, weldThreshold)) { ocsVertexes.Add(point); prevPoint = point; } } } return ocsVertexes; }
public void drawConnectedPlayer() { onGround = false; ohmDecay--; if (ohmDecay > 0) { Render.drawString(Game.font, overheadMessage, new Vector2f(position.X, position.Y - 30), Color.Black, .4f, true); //Main.spriteBatch.DrawString(Main.font1, overheadMessage, new Vector2f(position.X + Main.playerSprite.Width / 2 - (Main.font1.MeasureString(overheadMessage).X / 2), position.Y - 20), Color.White); } Vector2f indexPlayerPos = position; if (username.Equals("")) { Render.drawString(Game.font, (Math.Abs((UID)) + "").Substring(0, 4), position - new Vector2f(0, 15), Color.Black, .4f, true); } else { Render.drawString(Game.font, username, position - new Vector2f(0, 15), Color.Black, .4f, true); } if (Keyboard.IsKeyPressed(Keyboard.Key.O)) { Render.drawString(Game.font, position.ToString(), position - new Vector2f(0, 25), Color.Black, .4f, true); } if (!(oldPosition.Equals(position))) { animType = "move"; } else { animType = "idle"; } if (oldPosition.Y > position.Y) { facingY = 1; sprite = Game.tempIdleN; } else if (oldPosition.Y < position.Y) { facingY = -1; sprite = Game.tempIdleS; } else if (oldPosition.X > position.X) { facingX = 1; sprite = Game.tempIdleEW; } else if (oldPosition.X < position.X) { facingX = -1; sprite = Game.tempIdleEW; } if (alive) { } else { } oldPosition = position; }
/// <summary> /// Obtains a list of vertexes that represent the polyline approximating the curve segments as necessary. /// </summary> /// <param name="bulgePrecision">Curve segments precision (a value of zero means that no approximation will be made).</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <param name="bulgeThreshold">Minimun distance from which approximate curved segments of the polyline.</param> /// <returns>The return vertexes are expresed in object coordinate system.</returns> public List <Vector2f> PoligonalVertexes(int bulgePrecision, double weldThreshold, double bulgeThreshold) { List <Vector2f> ocsVertexes = new List <Vector2f>(); int index = 0; foreach (LightWeightPolylineVertex vertex in this.Vertexes) { double bulge = vertex.Bulge; Vector2f p1; Vector2f p2; if (index == this.Vertexes.Count - 1) { p1 = new Vector2f(vertex.Location.X, vertex.Location.Y); p2 = new Vector2f(this.vertexes[0].Location.X, this.vertexes[0].Location.Y); } else { p1 = new Vector2f(vertex.Location.X, vertex.Location.Y); p2 = new Vector2f(this.vertexes[index + 1].Location.X, this.vertexes[index + 1].Location.Y); } if (!p1.Equals(p2, weldThreshold)) { if (bulge == 0 || bulgePrecision == 0) { ocsVertexes.Add(p1); } else { double c = Vector2f.Distance(p1, p2); if (c >= bulgeThreshold) { double s = (c / 2) * Math.Abs(bulge); double r = ((c / 2) * (c / 2) + s * s) / (2 * s); double theta = (double)(4 * Math.Atan(Math.Abs(bulge))); double gamma = (double)((Math.PI - theta) / 2); double phi; if (bulge > 0) { phi = Vector2f.AngleBetween(Vector2f.UnitX, p2 - p1) + gamma; } else { phi = Vector2f.AngleBetween(Vector2f.UnitX, p2 - p1) - gamma; } Vector2f center = new Vector2f((double)(p1.X + r * Math.Cos(phi)), (double)(p1.Y + r * Math.Sin(phi))); Vector2f a1 = p1 - center; double angle = 4 * ((double)(Math.Atan(bulge))) / (bulgePrecision + 1); ocsVertexes.Add(p1); for (int i = 1; i <= bulgePrecision; i++) { Vector2f curvePoint = new Vector2f(); Vector2f prevCurvePoint = new Vector2f(this.vertexes[this.vertexes.Count - 1].Location.X, this.vertexes[this.vertexes.Count - 1].Location.Y); curvePoint.X = center.X + (double)(Math.Cos(i * angle) * a1.X - Math.Sin(i * angle) * a1.Y); curvePoint.Y = center.Y + (double)(Math.Sin(i * angle) * a1.X + Math.Cos(i * angle) * a1.Y); if (!curvePoint.Equals(prevCurvePoint, weldThreshold) && !curvePoint.Equals(p2, weldThreshold)) { ocsVertexes.Add(curvePoint); } } } else { ocsVertexes.Add(p1); } } } index++; } return(ocsVertexes); }