void Select(WorldCoordinateSelectEvent e) { var map = Resolve <IMapManager>().Current; float denominator = Vector3.Dot(Normal, e.Direction); if (Math.Abs(denominator) < 0.00001f) { return; } var pixelPosition = Position * new Vector2(map.TileSize.X, map.TileSize.Y); float t = Vector3.Dot(new Vector3(pixelPosition, 0.0f) - e.Origin, Normal) / denominator; if (t < 0) { return; } var intersectionPoint = e.Origin + t * e.Direction; int x = (int)(intersectionPoint.X - pixelPosition.X); int y = (int)(intersectionPoint.Y - pixelPosition.Y); if (x < 0 || x >= _size.X || y < 0 || y >= _size.Y) { return; } e.RegisterHit(t, this); }
public void Select(WorldCoordinateSelectEvent e) { _renderable.HighlightIndex = null; float denominator = Vector3.Dot(Normal, e.Direction); if (Math.Abs(denominator) < 0.00001f) { return; } float t = Vector3.Dot(Position - e.Origin, Normal) / denominator; if (t < 0) { return; } var intersectionPoint = e.Origin + t * e.Direction; int x = (int)((intersectionPoint.X + TileSize.X / 2) / TileSize.X); int y = (int)(intersectionPoint.Y / TileSize.Y); if (x < 0 || x >= _mapData.Width || y < 0 || y >= _mapData.Height) { return; } int index = y * _mapData.Width + x; _renderable.HighlightIndex = index; var underlayId = _mapData.Underlay[index]; var overlayId = _mapData.Overlay[index]; int zoneIndex = _mapData.ZoneLookup[index]; var underlayTile = underlayId != -1 ? _tileData.Tiles[underlayId] : null; var overlayTile = overlayId != -1 ? _tileData.Tiles[overlayId] : null; int?underlayZ = underlayTile?.Layer.ToDrawLayer().ToDebugZCoordinate(y); int?overlayZ = overlayTile?.Layer.ToDrawLayer().ToDebugZCoordinate(y); e.RegisterHit(t, $"Hit Tile ({(intersectionPoint.X + TileSize.X/2) / TileSize.X}, {intersectionPoint.Y / TileSize.Y}) Z: ({underlayZ}, {overlayZ})"); if (underlayId != -1) { e.RegisterHit(t, underlayTile); } if (overlayId != -1) { e.RegisterHit(t, overlayTile); } e.RegisterHit(t, this); if (zoneIndex != -1) { var zone = _mapData.Zones[zoneIndex]; e.RegisterHit(t, zone); HashSet <IEventNode> printedEvents = new HashSet <IEventNode>(); var zoneEvent = zone.Event; while (zoneEvent != null && !printedEvents.Contains(zoneEvent)) { e.RegisterHit(t, zoneEvent); printedEvents.Add(zoneEvent); zoneEvent = zoneEvent.NextEvent; } } }