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); }
bool OnSelect(WorldCoordinateSelectEvent e, Action <Selection> continuation) { var hits = new List <Selection>(); // TODO: Get rid of the extra allocation and copying _sceneGraph.RayIntersect(e.Origin, e.Direction, hits); foreach (var hit in hits) { continuation(hit); } return(true); // Find floor / ceiling hit (furthest point) // Iterate all tiles on a straight-line path between origin and floor hit // For each tile, yield if filled and if empty iterate contents performing hit checks. /* * float denominator = Vector3.Dot(Normal, e.Direction); * if (Math.Abs(denominator) < 0.00001f) * return; * * float t = Vector3.Dot(-e.Origin, Normal) / denominator; * if (t < 0) * return; * * Vector3 intersectionPoint = e.Origin + t * e.Direction; * int x = (int)(intersectionPoint.X / _renderable.TileSize.X); * int y = (int)(intersectionPoint.Y / _renderable.TileSize.Y); * * int highlightIndex = y * _map.Width + x; * var underlayTile = _map.GetUnderlay(x, y); * var overlayTile = _map.GetOverlay(x, y); * * e.RegisterHit(t, new MapTileHit( * new Vector2(x, y), * intersectionPoint, * _renderable.GetWeakUnderlayReference(x, y), * _renderable.GetWeakOverlayReference(x, y))); * * if (underlayTile != null) e.RegisterHit(t, underlayTile); * if (overlayTile != null) e.RegisterHit(t, overlayTile); * e.RegisterHit(t, this); * * var zone = _map.GetZone(x, y); * if (zone != null) * e.RegisterHit(t, zone); * * var chain = zone?.Chain; * if (chain != null) * { * foreach (var zoneEvent in chain.Events) * e.RegisterHit(t, zoneEvent); * } * * if (_lastHighlightIndex != highlightIndex) * { * HighlightIndexChanged?.Invoke(this, highlightIndex); * _lastHighlightIndex = highlightIndex; * } */ }
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; } } }
bool OnSelect(WorldCoordinateSelectEvent e, Action <Selection> continuation) { float denominator = Vector3.Dot(Normal, e.Direction); if (Math.Abs(denominator) < 0.00001f) { return(false); } float t = Vector3.Dot(-e.Origin, Normal) / denominator; if (t < 0) { return(false); } Vector3 intersectionPoint = e.Origin + t * e.Direction; int x = (int)(intersectionPoint.X / _renderable.TileSize.X); int y = (int)(intersectionPoint.Y / _renderable.TileSize.Y); int highlightIndex = y * _map.Width + x; var underlayTile = _map.GetUnderlay(x, y); var overlayTile = _map.GetOverlay(x, y); continuation(new Selection(e.Origin, e.Direction, t, new MapTileHit( new Vector2(x, y), intersectionPoint, _renderable.GetWeakUnderlayReference(x, y), _renderable.GetWeakOverlayReference(x, y)))); if (underlayTile != null) { continuation(new Selection(e.Origin, e.Direction, t, underlayTile)); } if (overlayTile != null) { continuation(new Selection(e.Origin, e.Direction, t, overlayTile)); } continuation(new Selection(e.Origin, e.Direction, t, this)); var zone = _map.GetZone(x, y); if (zone != null) { continuation(new Selection(e.Origin, e.Direction, t, zone)); } var chain = zone?.Chain; if (chain != null) { foreach (var zoneEvent in chain.Events) { continuation(new Selection(e.Origin, e.Direction, t, zoneEvent)); } } if (_lastHighlightIndex != highlightIndex) { HighlightIndexChanged?.Invoke(this, highlightIndex); _lastHighlightIndex = highlightIndex; } return(true); }
void Select(WorldCoordinateSelectEvent worldCoordinateSelectEvent) { }