public void DrawLine(Vector2 point1, Vector2 point2, Color color, double depth) { Vector2 scale = new Vector2((float)Math.Sqrt((point2 - point1).LengthSquared()), 1); float rotation = (float)Vector2Utils.Vector2Angle(point2 - point1); spriteBatch.Draw(point, point1, null, color, rotation, new Vector2(0), scale, SpriteEffects.None, (float)depth); }
public Boolean IsPointedAt(Vector2 target, float errorDistance) { Vector2 worldPosition = this.WorldPosition(); float angle = Vector2Utils.ShortestAngleDistance(Vector2Utils.Vector2Angle(target - worldPosition), this.WorldDirection()); float distanceToTarget = Vector2.Distance(target, worldPosition); return(Math.Abs(angle) <= Math.PI / 2 && Math.Abs((float)(Math.Sin(angle) * distanceToTarget)) < errorDistance); }
public float GetClosestPointAtAngleInRange(Vector2 target) { PhysicalObject parent = ((PhysicalObject)(this.Parent)); if (parent != null) { float worldDirection = Vector2Utils.Vector2Angle(target - this.WorldPosition()); float targetAngleRelativeToParent = worldDirection - parent.WorldDirection() - this.DirectionRelativeToParent; return(MathUtils.ClosestInRange(Vector2Utils.MinimizeMagnitude(targetAngleRelativeToParent), this.Range, -this.Range)); } else { return(0); } }
public override void Handle(Microsoft.Xna.Framework.GameTime elapsedTime) { base.Handle(elapsedTime); if (Vector2Utils.ShortestAngleDistance(obj.Direction, Vector2Utils.Vector2Angle(followObj.Position - obj.Position)) < (Math.PI / 20)) { if (!fire) { //((NPCShip)obj).FireCoaxialWeapon(); //fire = true; } } // Switch states if we are too close for engagement. if ((followObj.Position - obj.Position).Length() < 500) { // TODO: Dangerous convert...fix this this.Context.AddState(new ClearTargetState((NPCBasicAttackStrategy)this.Context, (NPCShip)this.obj, this.followObj)); this.Context.RemoveState(this); } }