private void UpdateMesh(BidirectionalEdge <ISatellite> edge) { var camera = PlanetariumCamera.Camera; var start = camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(edge.A.Position)); var end = camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(edge.B.Position)); var segment = new Vector3(end.y - start.y, start.x - end.x, 0).normalized *(LineWidth / 2); if (!MapView.Draw3DLines) { //if position is behind camera if (start.z < 0) { start = NetworkLine.FlipDirection(start, end); } else if (end.z < 0) { end = NetworkLine.FlipDirection(end, start); } var dist = Screen.height / 2 + 0.01f; start.z = start.z >= 0.15f ? dist : -dist; end.z = end.z >= 0.15f ? dist : -dist; mPoints2D[0] = (start - segment); mPoints2D[1] = (start + segment); mPoints2D[2] = (end - segment); mPoints2D[3] = (end + segment); } else { mPoints3D[0] = camera.ScreenToWorldPoint(start - segment); mPoints3D[1] = camera.ScreenToWorldPoint(start + segment); mPoints3D[2] = camera.ScreenToWorldPoint(end - segment); mPoints3D[3] = camera.ScreenToWorldPoint(end + segment); } mMeshFilter.mesh.vertices = MapView.Draw3DLines ? mPoints3D : mPoints2D; mMeshFilter.mesh.RecalculateBounds(); mMeshFilter.mesh.MarkDynamic(); }
private void UpdateMesh(Vector3d center, IAntenna dish) { var camera = PlanetariumCamera.Camera; Vector3d antennaPos = ScaledSpace.LocalToScaledSpace(RTCore.Instance.Network[dish.Guid].Position); Vector3d planetPos = ScaledSpace.LocalToScaledSpace(center); CelestialBody refFrame = (MapView.MapCamera.target.vessel != null ? MapView.MapCamera.target.vessel.mainBody : MapView.MapCamera.target.celestialBody); Vector3 up = (refFrame != null ? refFrame.transform.up : Vector3.up); Vector3 space = Vector3.Cross(planetPos - antennaPos, up).normalized *Vector3.Distance(antennaPos, planetPos) * (float)Math.Tan(Math.Acos(dish.CosAngle)); Vector3d end1 = antennaPos + (planetPos + space - antennaPos).normalized * Math.Min(dish.Dish / ScaledSpace.ScaleFactor, Vector3.Distance(antennaPos, planetPos)); Vector3d end2 = antennaPos + (planetPos - space - antennaPos).normalized * Math.Min(dish.Dish / ScaledSpace.ScaleFactor, Vector3.Distance(antennaPos, planetPos)); Vector3 lineStart = camera.WorldToScreenPoint(antennaPos); Vector3 lineEnd1 = camera.WorldToScreenPoint(end1); Vector3 lineEnd2 = camera.WorldToScreenPoint(end2); var segment1 = new Vector3(lineEnd1.y - lineStart.y, lineStart.x - lineEnd1.x, 0).normalized *(LineWidth / 2); var segment2 = new Vector3(lineEnd2.y - lineStart.y, lineStart.x - lineEnd2.x, 0).normalized *(LineWidth / 2); if (!MapView.Draw3DLines) { //if position is behind camera if (lineStart.z < 0) { Vector3 coneCenter = camera.WorldToScreenPoint(planetPos); lineStart = NetworkLine.FlipDirection(lineStart, coneCenter); } else if (lineEnd1.z < 0 || lineEnd2.z < 0) { lineEnd1 = NetworkLine.FlipDirection(lineEnd1, lineStart); lineEnd2 = NetworkLine.FlipDirection(lineEnd2, lineStart); } int dist = Screen.height / 2; lineStart.z = lineStart.z > 0 ? dist : -dist; lineEnd1.z = lineEnd1.z > 0 ? dist : -dist; lineEnd2.z = lineEnd2.z > 0 ? dist : -dist; mPoints2D[0] = (lineStart - segment1); mPoints2D[1] = (lineStart + segment1); mPoints2D[2] = (lineEnd1 - segment1); mPoints2D[3] = (lineEnd1 + segment1); mPoints2D[4] = (lineStart - segment2); mPoints2D[5] = (lineStart + segment2); mPoints2D[6] = (lineEnd2 - segment2); mPoints2D[7] = (lineEnd2 + segment2); } else { mPoints3D[0] = camera.ScreenToWorldPoint(lineStart - segment1); mPoints3D[1] = camera.ScreenToWorldPoint(lineStart + segment1); mPoints3D[2] = camera.ScreenToWorldPoint(lineEnd1 - segment1); mPoints3D[3] = camera.ScreenToWorldPoint(lineEnd1 + segment1); mPoints3D[4] = camera.ScreenToWorldPoint(lineStart - segment2); mPoints3D[5] = camera.ScreenToWorldPoint(lineStart + segment2); mPoints3D[6] = camera.ScreenToWorldPoint(lineEnd2 - segment2); mPoints3D[7] = camera.ScreenToWorldPoint(lineEnd2 + segment2); } mMeshFilter.mesh.vertices = MapView.Draw3DLines ? mPoints3D : mPoints2D; if (!MapView.Draw3DLines) { var bounds = new Bounds(); bounds.center = new Vector3(Screen.width / 2, Screen.height / 2, Screen.height / 2); bounds.extents = new Vector3(Screen.width * 100, Screen.height * 100, 0.1f); mMeshFilter.mesh.bounds = bounds; } else { mMeshFilter.mesh.RecalculateBounds(); } }