Пример #1
0
        public override IHoverData GetHoverData(MapGraphics graphics)
        {
            var radius      = Size / graphics.MapViewScaleValue;
            var cursorPos   = graphics.mapCursorPosition;
            var closestDist = float.PositiveInfinity;

            if (!graphics.IsMouseDown(0))
            {
                hoverData.currentPositionAngle = null;
                foreach (var a in positionAngleProvider())
                {
                    if (graphics.view.mode == MapView.ViewMode.TopDown)
                    {
                        if ((new Vector3((float)a.X, cursorPos.Y, (float)a.Z) - cursorPos).LengthSquared < radius * radius)
                        {
                            hoverData.currentPositionAngle = a;
                            break;
                        }
                    }
                    else if (graphics.view.mode == MapView.ViewMode.Orthogonal)
                    {
                        var projectedPos = Vector3.TransformPosition(a.position, graphics.ViewMatrix);
                        projectedPos.X = (1 + projectedPos.X) * graphics.glControl.Width / 2;
                        projectedPos.Y = (1 - projectedPos.Y) * graphics.glControl.Height / 2;
                        if ((projectedPos.Xy - graphics.mousePosition2D).LengthSquared < (Size * Size))
                        {
                            hoverData.currentPositionAngle = a;
                            break;
                        }
                    }
                    else if (graphics.view.mode == MapView.ViewMode.ThreeDimensional)
                    {
                        var rad     = Size * Get3DIconScale(graphics, (float)a.X, (float)a.Y, (float)a.Z);
                        var lineEnd = graphics.cursorOnMap ? graphics.mapCursorPosition
                            : graphics.view.position + Vector3.Normalize(graphics.mapCursorPosition - graphics.view.position) * 10000;
                        if ((ProjectOnLineSegment(a.position, graphics.view.position, lineEnd) - a.position).Length < rad)
                        {
                            var newDist = (a.position - graphics.view.position).LengthSquared;
                            if (closestDist > newDist)
                            {
                                hoverData.currentPositionAngle = a;
                                closestDist = newDist;
                            }
                        }
                    }
                }
            }
            return(hoverData.currentPositionAngle != null ? hoverData : null);
        }