//------------------ isSecondInFOVOfFirst ------------------------------------- // // returns true if the target position is in the field of view of the entity // positioned at posFirst facing in facingFirst //----------------------------------------------------------------------------- public static bool isSecondInFOVOfFirst(Vector2D posFirst, Vector2D facingFirst, Vector2D posSecond, double fov) { Vector2D toTarget = Vec2DNormalize(posSecond - posFirst); return facingFirst.Dot(toTarget) >= Math.Cos(fov / 2.0); }
private Vector2D PointToLocalSpace(Vector2D point, Vector2D AgentHeading, Vector2D AgentSide, Vector2D AgentPosition) { //make a copy of the point Vector2D TransPoint = new Vector2D(point.X, point.Y); //create a transformation matrix C2DMatrix matTransform = new C2DMatrix(); double Tx = -AgentPosition.Dot(AgentHeading); double Ty = -AgentPosition.Dot(AgentSide); //create the transformation matrix matTransform._11(AgentHeading.X); matTransform._12(AgentSide.X); matTransform._21(AgentHeading.Y); matTransform._22(AgentSide.Y); matTransform._31(Tx); matTransform._32(Ty); //now transform the vertices matTransform.TransformVector2D(TransPoint); return TransPoint; }