private void DebugDrawNavMesh() { RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey; AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey); if (navMesh != null) { for (uint navCellIndex = 0; navCellIndex < navMesh.GetNavCellCount(); navCellIndex++) { int connectivityId = navMesh.GetNavCellConnectivityID(navCellIndex); if (connectivityId != AsyncRPGSharedLib.Navigation.NavMesh.EMPTY_NAV_CELL) { for (MathConstants.eDirection direction = MathConstants.eDirection.first; direction < MathConstants.eDirection.count; direction++) { if (!navMesh.NavCellHasNeighbor(navCellIndex, direction)) { Point3d portalLeft, portalRight; Vector3 portalVertexLeft, portalVertexRight; navMesh.ComputePointsOnNavCellSide(navCellIndex, direction, out portalLeft, out portalRight); portalVertexLeft = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalLeft); portalVertexRight = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalRight); Debug.DrawLine( portalVertexLeft, portalVertexRight, Color.yellow, 0.0f, // duration false); // depth test } } } } } }
private void DebugDrawTestVisibility() { int characterID = _gameWorldController.Model.CurrentCharacterID; RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey; CharacterEntity entity = _gameWorldController.Model.GetCharacterEntity(characterID); if (entity != null) { Point3d startWorldPos = entity.Position; Point2d endPixelPos = GetMousePixelPosition(); Point3d endWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(endPixelPos); // Draw the target nav cell AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey); if (navMesh != null) { NavRef startNavRef = navMesh.ComputeNavRefAtPoint(startWorldPos); NavRef endNavRef = navMesh.ComputeNavRefAtPoint(endWorldPos); if (startNavRef.IsValid && endNavRef.IsValid) { bool canSee = navMesh.NavRefCanSeeOtherNavRef(startNavRef, endNavRef); Color debugColor = canSee ? Color.green : Color.red; // Draw a box around the nav cell { Point3d endCenterWorldPos = navMesh.ComputeNavCellCenter((uint)endNavRef.NavCellIndex); Point2d endCenterPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(endCenterWorldPos); float halfWidth = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f; Vector3 boxUL = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x - halfWidth, endCenterPixelPos.y - halfWidth, 0.0f); Vector3 boxUR = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x + halfWidth, endCenterPixelPos.y - halfWidth, 0.0f); Vector3 boxLR = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x + halfWidth, endCenterPixelPos.y + halfWidth, 0.0f); Vector3 boxLL = ClientGameConstants.ConvertPixelPositionToVertexPosition( endCenterPixelPos.x - halfWidth, endCenterPixelPos.y + halfWidth, 0.0f); Debug.DrawLine(boxUL, boxUR, debugColor); Debug.DrawLine(boxUR, boxLR, debugColor); Debug.DrawLine(boxLR, boxLL, debugColor); Debug.DrawLine(boxLL, boxUL, debugColor); } // Update the visibility status label _visibilityStatusLabel.Text = canSee ? "VISIBLE" : "INVISIBLE"; _visibilityStatusLabel.SetLocalPosition(endPixelPos.x, endPixelPos.y); _visibilityStatusLabel.Color = debugColor; _visibilityStatusLabel.Visible = true; // Render the ray-cast line { Vector3 startVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(startWorldPos); Vector3 endVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(endWorldPos); Debug.DrawLine(startVertex, endVertex, debugColor); } } } } }
private void DebugDrawTestPath() { int characterID = _gameWorldController.Model.CurrentCharacterID; RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey; CharacterEntity entity = _gameWorldController.Model.GetCharacterEntity(characterID); if (entity != null) { Point2d mousePixelPos = GetMousePixelPosition(); Point3d mouseWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(mousePixelPos); // Draw the target nav cell string targetLabel = ""; AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey); if (navMesh != null) { NavRef navRef = navMesh.ComputeNavRefAtPoint(mouseWorldPos); if (navRef.IsValid) { Point3d centerWorldPos = navMesh.ComputeNavCellCenter((uint)navRef.NavCellIndex); Point2d centerPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(centerWorldPos); float halfWidth = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f; Vector3 boxUL = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x - halfWidth, centerPixelPos.y - halfWidth, 0.0f); Vector3 boxUR = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x + halfWidth, centerPixelPos.y - halfWidth, 0.0f); Vector3 boxLR = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x + halfWidth, centerPixelPos.y + halfWidth, 0.0f); Vector3 boxLL = ClientGameConstants.ConvertPixelPositionToVertexPosition( centerPixelPos.x - halfWidth, centerPixelPos.y + halfWidth, 0.0f); Debug.DrawLine(boxUL, boxUR, Color.blue); Debug.DrawLine(boxUR, boxLR, Color.blue); Debug.DrawLine(boxLR, boxLL, Color.blue); Debug.DrawLine(boxLL, boxUL, Color.blue); targetLabel = "\nNavCell=" + navRef.NavCellIndex.ToString(); } // Attempt to compute a path from the active player to the mouse _pathComputer.BlockingPathRequest(navMesh, roomKey, entity.Position, mouseWorldPos); // Update the path status label { if (_pathComputer.ResultCode == PathComputer.eResult.success) { _pathStatusLabel.Text = "VALID" + targetLabel; _pathStatusLabel.Color = Color.green; } else { _pathStatusLabel.Text = _pathComputer.ResultCode + targetLabel; _pathStatusLabel.Color = Color.red; } _pathStatusLabel.SetLocalPosition(mousePixelPos.x, mousePixelPos.y); _pathStatusLabel.Visible = true; } // Render the raw path for (int stepIndex = 1; stepIndex < _pathComputer.FinalPath.Count; stepIndex++) { Point3d previousPoint = _pathComputer.FinalPath[stepIndex - 1].StepPoint; Point3d currentPoint = _pathComputer.FinalPath[stepIndex].StepPoint; Vector3 previousPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(previousPoint); Vector3 currentPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentPoint); Debug.DrawLine(previousPixelPoint, currentPixelPoint, Color.green); } } } }