void RunSolarPanels() { float distance = float.MaxValue; var target = Planetarium.fetch.Sun; var tgtScaled = target.scaledBody.transform; var pos = ScaledSpace.LocalToScaledSpace(vessel.transform.position); var tgt = ScaledSpace.LocalToScaledSpace(target.transform.position); Ray ray = new Ray(pos, (tgt - pos).normalized); RaycastHit hit; if (!Physics.Raycast(ray, out hit, distance, planetLayerMask) || hit.transform == tgtScaled) { PushEC(solarEC * TimeWarp.fixedDeltaTime); } }
/// <summary> /// Determines whether the specified position is occluded by a celestial body. /// Borrowed from Sarbian /// </summary> /// <param name="worldPosition">The world position.</param> /// <param name="byBody">The by body.</param> /// <returns></returns> public static Boolean IsOccluded(Vector3d worldPosition, CelestialBody byBody) { Vector3d camPos = ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.Camera.transform.position); Vector3d vc = (byBody.position - camPos) / (byBody.Radius - 100); Vector3d vt = (worldPosition - camPos) / (byBody.Radius - 100); Double vtVc = Vector3d.Dot(vt, vc); // In front of the horizon plane if (vtVc < vc.sqrMagnitude - 1) { return(false); } return(vtVc * vtVc / vt.sqrMagnitude > vc.sqrMagnitude - 1); }
/// <summary> /// Determines whether the specified position is occluded by a celestial body. /// Borrowed from Sarbian /// </summary> /// <param name="worldPosition">The world position.</param> /// <param name="byBody">The by body.</param> /// <returns></returns> public static bool IsOccluded(Vector3d worldPosition, CelestialBody byBody) { Vector3d camPos = ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.Camera.transform.position); Vector3d VC = (byBody.position - camPos) / (byBody.Radius - 100); Vector3d VT = (worldPosition - camPos) / (byBody.Radius - 100); double VT_VC = Vector3d.Dot(VT, VC); // In front of the horizon plane if (VT_VC < VC.sqrMagnitude - 1) { return(false); } return(VT_VC * VT_VC / VT.sqrMagnitude > VC.sqrMagnitude - 1); }
public void onDraw() { if (siteLocations.Count < 1 || lsTexture == null || !showSites || !iconDisplayDistance()) { return; } CelestialBody Kerbin = KSCBody; bool isActiveSite = false; foreach (KeyValuePair <string, LaunchSite> kvp in siteLocations) { Camera camera = PlanetariumCamera.Camera; Vector3d point = Kerbin.GetWorldSurfacePosition(kvp.Value.geographicLocation.x, kvp.Value.geographicLocation.y, 0); if (!IsOccluded(point, Kerbin)) { isActiveSite = kvp.Value.name.Equals(activeSite); point = ScaledSpace.LocalToScaledSpace(point); point = camera.WorldToScreenPoint(point); Rect iconBound = new Rect((float)point.x, (float)(Screen.height - point.y), 28f, 28f); if (isActiveSite) { Graphics.DrawTexture(iconBound, lsActiveTexture); } else { Graphics.DrawTexture(iconBound, lsTexture); } if (iconBound.Contains(Event.current.mousePosition)) { GUI.Label(new Rect((float)(point.x) + 28f, (float)(Screen.height - point.y) + 5f, 50, 20), kvp.Value.displayName, siteText); if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { if (isActiveSite) { ScreenMessages.PostScreenMessage("Cannot set launch site to active site.", 2.5f, ScreenMessageStyle.LOWER_CENTER); } else { setSite(kvp.Value); } } } } } }
public static Coordinates GetMouseCoordinates(CelestialBody body) { Ray mouseRay = PlanetariumCamera.Camera.ScreenPointToRay(Input.mousePosition); mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin); Vector3d relOrigin = mouseRay.origin - body.position; Vector3d relSurfacePosition; double curRadius = body.pqsController.radiusMax; double lastRadius = 0; double error = 0; int loops = 0; float st = Time.time; while (loops < 50) { if (PQS.LineSphereIntersection(relOrigin, mouseRay.direction, curRadius, out relSurfacePosition)) { Vector3d surfacePoint = body.position + relSurfacePosition; double alt = body.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(body.GetLongitude(surfacePoint), Vector3d.down) * QuaternionD.AngleAxis(body.GetLatitude(surfacePoint), Vector3d.forward) * Vector3d.right); error = Math.Abs(curRadius - alt); if (error < (body.pqsController.radiusMax - body.pqsController.radiusMin) / 100) { return(new Coordinates(body.GetLatitude(surfacePoint), MuUtils.ClampDegrees180(body.GetLongitude(surfacePoint)))); } else { lastRadius = curRadius; curRadius = alt; loops++; } } else { if (loops == 0) { break; } else { // Went too low, needs to try higher curRadius = (lastRadius * 9 + curRadius) / 10; loops++; } } } return(null); }
public static void DrawWaypoint(CelestialBody targetBody, double latitude, double longitude, double altitude, string id, int seed, float alpha = -1.0f) { // Translate to scaled space Vector3d localSpacePoint = targetBody.GetWorldSurfacePosition(latitude, longitude, altitude); Vector3d scaledSpacePoint = ScaledSpace.LocalToScaledSpace(localSpacePoint); // Don't draw if it's behind the camera if (Vector3d.Dot(PlanetariumCamera.Camera.transform.forward, scaledSpacePoint.normalized) < 0.0) { return; } // Translate to screen position Vector3 screenPos = PlanetariumCamera.Camera.WorldToScreenPoint(new Vector3((float)scaledSpacePoint.x, (float)scaledSpacePoint.y, (float)scaledSpacePoint.z)); // Draw the marker at half-resolution (30 x 45) - that seems to match the one in the map view Rect markerRect = new Rect(screenPos.x - 15f, (float)Screen.height - screenPos.y - 45.0f, 30f, 45f); // Half-res for the icon too (16 x 16) Rect iconRect = new Rect(screenPos.x - 8f, (float)Screen.height - screenPos.y - 39.0f, 16f, 16f); if (alpha < 0.0f) { Vector3 cameraPos = ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.Camera.transform.position); bool occluded = WaypointData.IsOccluded(targetBody, cameraPos, localSpacePoint, altitude); float desiredAlpha = occluded ? 0.3f : 1.0f * Config.opacity; if (lastAlpha < 0.0f) { lastAlpha = desiredAlpha; } else if (lastAlpha < desiredAlpha) { lastAlpha = Mathf.Clamp(lastAlpha + Time.deltaTime * 4f, lastAlpha, desiredAlpha); } else { lastAlpha = Mathf.Clamp(lastAlpha - Time.deltaTime * 4f, desiredAlpha, lastAlpha); } alpha = lastAlpha; } // Draw the marker Graphics.DrawTexture(markerRect, GameDatabase.Instance.GetTexture("Squad/Contracts/Icons/marker", false), new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, new Color(0.5f, 0.5f, 0.5f, 0.5f * (alpha - 0.3f) / 0.7f)); // Draw the icon Graphics.DrawTexture(iconRect, ContractDefs.sprites[id].texture, new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, SystemUtilities.RandomColor(seed, alpha)); }
private static Double Flux(ModularFlightIntegrator fi, KopernicusStar star) { // Nullchecks try { if (fi == null) { return 0; } if (fi.Vessel == null || fi.Vessel.state == Vessel.State.DEAD || fi.CurrentMainBody == null) { return 0; } if (star == null) { return 0; } // Get sunVector Boolean directSunlight = false; Vector3 integratorPosition = fi.transform.position; Vector3d scaledSpace = ScaledSpace.LocalToScaledSpace(integratorPosition); Vector3 position = star.sun.scaledBody.transform.position; Double scale = Math.Max((position - scaledSpace).magnitude, 1); Vector3 sunVector = (position - scaledSpace) / scale; Ray ray = new Ray(ScaledSpace.LocalToScaledSpace(integratorPosition), sunVector); // Get Solar Flux Double realDistanceToSun = 0; if (!Physics.Raycast(ray, out RaycastHit raycastHit, Single.MaxValue, ModularFlightIntegrator.SunLayerMask)) { directSunlight = true; realDistanceToSun = scale * ScaledSpace.ScaleFactor - star.sun.Radius; } else if (raycastHit.transform.GetComponent<ScaledMovement>().celestialBody == star.sun) { realDistanceToSun = ScaledSpace.ScaleFactor * raycastHit.distance; directSunlight = true; } if (directSunlight) { return PhysicsGlobals.SolarLuminosity / (12.5663706143592 * realDistanceToSun * realDistanceToSun); } return 0; }
//If dashed = false, draws 0-1-2-3-4-5... //If dashed = true, draws 0-1 2-3 4-5... public static void DrawPath( CelestialBody mainBody, List <Vector3d> points, Color c, bool map, bool dashed = false ) { try { GL.PushMatrix(); material?.SetPass(0); GL.LoadPixelMatrix(); GL.Begin(GL.LINES); GL.Color(c); Vector3d camPos = map ? ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.Camera.transform.position) : (Vector3d)FlightCamera.fetch.mainCamera.transform.position; int step = (dashed ? 2 : 1); for (int i = 0; i < points.Count - 1; i += step) { if (!IsOccluded( points[i], mainBody, camPos ) && !IsOccluded( points[i + 1], mainBody, camPos )) { GLPixelLine( points[i], points[i + 1], map ); } } GL.End(); GL.PopMatrix(); } catch { } }
public void OnRender() { bool map = MapView.MapIsEnabled; Color color = Color.Color; Vector3d up = GeoCoordinates.SurfaceNormal; double height = GeoCoordinates.Body.Radius + Math.Max(GeoCoordinates.TerrainHeight, 0); Vector3d position = GeoCoordinates.Body.Position + (FlightGlobals.ActiveVessel?.CoMD ?? Vector3d.zero); Vector3d center = position + height * up; Vector3d camPos = map ? ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.Camera.transform.position) : (Vector3d)FlightCamera.fetch.mainCamera.transform.position; if (GLUtils.IsOccluded(center, position, GeoCoordinates.Body.Radius, camPos)) { return; } Vector3d north = Vector3d.Exclude(up, GeoCoordinates.Body.Up).normalized; double radius = map ? GeoCoordinates.Body.Radius / 50 : 5; if (!map) { Vector3 centerPoint = FlightCamera.fetch.mainCamera.WorldToViewportPoint(center); if (centerPoint.z < 0) { return; } } GLUtils.GLTriangle( center, center + radius * (QuaternionD.AngleAxis(Rotation - 10, up) * north), center + radius * (QuaternionD.AngleAxis(Rotation + 10, up) * north), color, GLUtils.Colored, map); GLUtils.GLTriangle( center, center + radius * (QuaternionD.AngleAxis(Rotation + 110, up) * north), center + radius * (QuaternionD.AngleAxis(Rotation + 130, up) * north), color, GLUtils.Colored, map); GLUtils.GLTriangle( center, center + radius * (QuaternionD.AngleAxis(Rotation - 110, up) * north), center + radius * (QuaternionD.AngleAxis(Rotation - 130, up) * north), color, GLUtils.Colored, map); }
private void OnGUI() { if (myNode != null && textWhere != null) { var screenWhere = PlanetariumCamera.Camera.WorldToScreenPoint( ScaledSpace.LocalToScaledSpace(textWhere)); if (screenWhere.z > 0 && screenWhere.x >= 0 && screenWhere.x <= Screen.width && screenWhere.y >= 0 && screenWhere.y <= Screen.height) { // In front of camera, so draw var camDist = cameraDist(textWhere); if (0 < camDist && camDist < ringScale) { var offset = 0.6f * ringScale / camDist + 10; labelStyle.normal.textColor = myNode.color; if (GUI.Button( new Rect(screenWhere.x - 50, Screen.height - screenWhere.y + offset, 100, 30), myNode.GetCaption(vessel), labelStyle )) { EditMe?.Invoke(myNode); } } } else { Vector2 edgePos = (screenWhere.z < 0 ? -1f : 1f) * screenRadius * ( new Vector2(screenWhere.x - Screen.width / 2, Screen.height / 2 - screenWhere.y).normalized ); GUI.Label( new Rect( Mathf.Clamp(Screen.width / 2 + edgePos.x, 50, Screen.width - 100), Mathf.Clamp(Screen.height / 2 + edgePos.y, 50, Screen.height - 50), 100, 30 ), myNode.GetCaption(vessel), labelStyle ); } } }
private void DrawArc(LineRenderer line, Vector3d vectStart, Double Angle, Double StartLength, Double EndLength) { Double ArcRadius = Math.Min(StartLength, EndLength) * 0.9; for (int i = 0; i < ArcPoints; i++) { Vector3d vectArc = Quaternion.AngleAxis(-(Single)Angle / (ArcPoints - 1) * i, bodyOrigin.orbit.GetOrbitNormal().xzy) * vectStart; vectArc = vectArc.normalized * ArcRadius; vectArc = bodyOrigin.referenceBody.transform.position + vectArc; line.SetPosition(i, ScaledSpace.LocalToScaledSpace(vectArc)); } //line.SetWidth((float)10 / 1000 * cam.Distance, (float)10 / 1000 * cam.Distance); line.startWidth = 10f / 1000f * cam.Distance; line.endWidth = 10f / 1000f * cam.Distance; line.enabled = true; }
public static void GLDrawBounds(Bounds b, Transform T, Color col, MaterialWrapper mat = null) { //edges[0] = new Vector3(min.x, min.y, min.z); //left-bottom-back //edges[1] = new Vector3(min.x, min.y, max.z); //left-bottom-front //edges[2] = new Vector3(min.x, max.y, min.z); //left-top-back //edges[3] = new Vector3(min.x, max.y, max.z); //left-top-front //edges[4] = new Vector3(max.x, min.y, min.z); //right-bottom-back //edges[5] = new Vector3(max.x, min.y, max.z); //right-bottom-front //edges[6] = new Vector3(max.x, max.y, min.z); //right-top-back //edges[7] = new Vector3(max.x, max.y, max.z); //right-top-front var c = Utils.BoundCorners(b); for (int i = 0; i < 8; i++) { if (T != null) { c[i] = T.TransformDirection(c[i]) + T.position; } if (MapView.MapIsEnabled) { c[i] = ScaledSpace.LocalToScaledSpace(c[i]); } } float far; var camera = GLBeginWorld(out far, mat); GL.Begin(GL.LINES); GL.Color(col); gl_line(c[0], c[1]); gl_line(c[1], c[5]); gl_line(c[5], c[4]); gl_line(c[4], c[0]); gl_line(c[2], c[3]); gl_line(c[3], c[7]); gl_line(c[7], c[6]); gl_line(c[6], c[2]); gl_line(c[2], c[0]); gl_line(c[3], c[1]); gl_line(c[7], c[5]); gl_line(c[6], c[4]); GL.End(); GL.PopMatrix(); camera.farClipPlane = far; }
public static DisposablePlanetarium NewPlanetarium(IntPtr plugin, XYZ sun_world_position) { UnityEngine.Camera camera = PlanetariumCamera.Camera; UnityEngine.Vector3 opengl_camera_x_in_world = camera.cameraToWorldMatrix.MultiplyVector( new UnityEngine.Vector3(1, 0, 0)); UnityEngine.Vector3 opengl_camera_y_in_world = camera.cameraToWorldMatrix.MultiplyVector( new UnityEngine.Vector3(0, 1, 0)); UnityEngine.Vector3 opengl_camera_z_in_world = camera.cameraToWorldMatrix.MultiplyVector( new UnityEngine.Vector3(0, 0, 1)); UnityEngine.Vector3 camera_position_in_world = ScaledSpace.ScaledToLocalSpace(camera.transform.position); // For explanations regarding the OpenGL projection matrix, see // http://www.songho.ca/opengl/gl_projectionmatrix.html. The on-centre // projection matrix has the form: // n / w 0 0 0 // 0 n / h 0 0 // 0 0 (n + f) / (n - f) 2 f n / (n - f) // 0 0 -1 0 // where n and f are the near- and far-clipping distances, and w and h // are the half-width and half-height of the screen seen in the focal plane. // n is also the focal distance, but we prefer to make that distance 1 metre // to avoid having to rescale the result. The only actual effect of n is // the clipping distance, and in space, no one can hear you clip. double m00 = camera.projectionMatrix[0, 0]; double m11 = camera.projectionMatrix[1, 1]; double field_of_view = Math.Atan2(Math.Sqrt(m00 * m00 + m11 * m11), m00 * m11); return(plugin.PlanetariumCreate( sun_world_position, (XYZ)(Vector3d)opengl_camera_x_in_world, (XYZ)(Vector3d)opengl_camera_y_in_world, (XYZ)(Vector3d)opengl_camera_z_in_world, (XYZ)(Vector3d)camera_position_in_world, focal: 1, field_of_view, ScaledSpace.InverseScaleFactor, scaled_space_origin: (XYZ)ScaledSpace.ScaledToLocalSpace( Vector3d.zero))); }
public static Coordinates GetMouseCoordinates(CelestialBody body) { Ray mouseRay = PlanetariumCamera.Camera.ScreenPointToRay(Input.mousePosition); mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin); Vector3d relOrigin = mouseRay.origin - body.position; Vector3d relSurfacePosition; if (PQS.LineSphereIntersection(relOrigin, mouseRay.direction, body.Radius, out relSurfacePosition)) { Vector3d surfacePoint = body.position + relSurfacePosition; return(new Coordinates(body.GetLatitude(surfacePoint), MuUtils.ClampDegrees180(body.GetLongitude(surfacePoint)))); } else { return(null); } }
public static void Draw(Action line_vertices) { try { UnityEngine.GL.PushMatrix(); line_material.SetPass(0); UnityEngine.GL.LoadPixelMatrix(); UnityEngine.GL.Begin(UnityEngine.GL.LINES); Vector3d camera = ScaledSpace.ScaledToLocalSpace( PlanetariumCamera.Camera.transform.position); line_vertices(); UnityEngine.GL.End(); UnityEngine.GL.PopMatrix(); } catch (Exception e) { Log.Fatal("Exception while drawing lines: " + e.ToString()); } }
void OnPreRender() { if (NearCamera == null) { return; } if (NearCamera.transform == null) { return; } if (transform == null) { return; } transform.position = ScaledSpace.LocalToScaledSpace(NearCamera.transform.localPosition); transform.rotation = NearCamera.transform.rotation; }
void DrawIcon(Vector3d position, Texture2D icon) { GUIStyle styleWarpToButton = new GUIStyle(); styleWarpToButton.fixedWidth = 32; styleWarpToButton.fixedHeight = 32; styleWarpToButton.normal.background = icon; Vector3d screenPosNode = PlanetariumCamera.Camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(position)); if (screenPosNode.z < 0) { return; } Rect rectNodeButton = new Rect((Int32)screenPosNode.x - 16, (Int32)(Screen.height - screenPosNode.y) - 16, 32, 32); GUI.Button(rectNodeButton, "", styleWarpToButton); }
public static void GLLine(Vector3 ori, Vector3 end, Color c, MaterialWrapper mat = null) { float far; var camera = GLBeginWorld(out far, mat); if (MapView.MapIsEnabled) { ori = ScaledSpace.LocalToScaledSpace(ori); end = ScaledSpace.LocalToScaledSpace(end); } GL.Begin(GL.LINES); GL.Color(c); GL.Vertex(ori); GL.Vertex(end); GL.End(); GL.PopMatrix(); camera.farClipPlane = far; }
/// <summary> /// Small method to handle flux /// </summary> public static void Flux(ModularFlightIntegrator fi, KopernicusStar star) { // Nullchecks if (fi.Vessel == null || fi.Vessel.state == Vessel.State.DEAD || fi.CurrentMainBody == null) { return; } // Get sunVector RaycastHit raycastHit; Vector3d scaledSpace = ScaledSpace.LocalToScaledSpace(fi.IntegratorTransform.position); double scale = Math.Max((star.sun.scaledBody.transform.position - scaledSpace).magnitude, 1); Vector3 sunVector = (star.sun.scaledBody.transform.position - scaledSpace) / scale; Ray ray = new Ray(ScaledSpace.LocalToScaledSpace(fi.IntegratorTransform.position), sunVector); // Get Body flux Vector3d scaleFactor = ((Vector3d)star.sun.scaledBody.transform.position - fi.CurrentMainBody.scaledBody.transform.position) * (double)ScaledSpace.ScaleFactor; fi.bodySunFlux = star.sunFlare == fi.CurrentMainBody ? 0 : PhysicsGlobals.SolarLuminosity / Math.PI * 4 * scaleFactor.sqrMagnitude; // Get Solar Flux double realDistanceToSun = 0; bool localDirectSunLight = false; if (!Physics.Raycast(ray, out raycastHit, Single.MaxValue, ModularFI.ModularFlightIntegrator.SunLayerMask)) { localDirectSunLight = true; realDistanceToSun = scale * ScaledSpace.ScaleFactor - star.sun.Radius; } else if (raycastHit.transform.GetComponent <ScaledMovement>().celestialBody == star.sun) { realDistanceToSun = ScaledSpace.ScaleFactor * raycastHit.distance; localDirectSunLight = true; } if (localDirectSunLight) { fi.solarFlux = PhysicsGlobals.SolarLuminosity / (12.5663706143592 * realDistanceToSun * realDistanceToSun); if (!fi.Vessel.directSunlight) { fi.Vessel.directSunlight = true; } } }
private void OnGUI() { if (myNode != null && textWhere != null) { var camDist = cameraDist(textWhere); if (0 < camDist && camDist < ringScale) { var screenWhere = PlanetariumCamera.Camera.WorldToScreenPoint( ScaledSpace.LocalToScaledSpace(textWhere)) + (0.6f * ringScale / camDist + 10) * Vector3.down; if (screenWhere.z > 0 && viewport.Contains(screenWhere)) { // In front of camera, so draw button labelStyle.normal.textColor = myNode.color; if (GUI.Button( new Rect( screenWhere.x - halfTextWidth, Screen.height - screenWhere.y, textWidth, 30), myNode.GetCaption(vessel), labelStyle )) { EditMe?.Invoke(myNode); } } else { // Off edge of screen or behind camera, draw marker at edge of screen labelStyle.normal.textColor = new Color( myNode.color.r, myNode.color.g, myNode.color.b, 0.6f); var edgePos = edgePosition((screenWhere.z < 0 ? -1f : 1f) * ((Vector2)screenWhere - screenCenterOffset)); GUI.Label( new Rect(edgePos.x - halfTextWidth, edgePos.y, textWidth, 30), myNode.GetCaption(vessel), labelStyle ); } } } }
void Update() { StarComponent selectedStar = null; // If forceUpdate is enabled, update the active star if (forcedUpdate && Sun.Instance) { stars.First(s => s.IsActiveStar()).SetAsActive(forcedUpdate); // reset forced Update forcedUpdate = false; } // If we are in the tracking station, space center or game, if (HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.SPACECENTER) { // Get the current position of the active vessel if (PlanetariumCamera.fetch.enabled == true) { Vector3 position = ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.fetch.GetCameraTransform().position); selectedStar = stars.OrderBy(star => FlightGlobals.getAltitudeAtPos(position, star.celestialBody)).First(); } else if (FlightGlobals.ActiveVessel != null) { Vector3 position = FlightGlobals.ActiveVessel.GetTransform().position; selectedStar = stars.OrderBy(star => FlightGlobals.getAltitudeAtPos(position, star.celestialBody)).First(); } else if (SpaceCenter.Instance != null && SpaceCenter.Instance.SpaceCenterTransform != null) { Vector3 position = SpaceCenter.Instance.SpaceCenterTransform.position; selectedStar = stars.OrderBy(star => FlightGlobals.getAltitudeAtPos(position, star.celestialBody)).First(); } // If the star has been changed, update everything if (selectedStar != null && !selectedStar.IsActiveStar()) { selectedStar.SetAsActive(); } else if (selectedStar == null && !HomeStar().IsActiveStar()) { HomeStar().SetAsActive(); } } }
private static void MakeRibbonEdge(Vector3d prevPos, Vector3d edgeCenter, float width, Vector3[] vertices, int startIndex) { // Code taken from RemoteTech mod Camera camera = PlanetariumCamera.Camera; Vector3 start = camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(prevPos)); Vector3 end = camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(edgeCenter)); Vector3 segment = new Vector3(end.y - start.y, start.x - end.x, 0).normalized *(width * 0.5f); if (!MapView.Draw3DLines) { float dist = Screen.height / 2f + 0.01f; start.z = start.z >= 0.15f ? dist : -dist; end.z = end.z >= 0.15f ? dist : -dist; } Vector3 p0 = (end + segment); Vector3 p1 = (end - segment); if (MapView.Draw3DLines) { p0 = camera.ScreenToWorldPoint(p0); p1 = camera.ScreenToWorldPoint(p1); } vertices[startIndex + 0] = p0; vertices[startIndex + 1] = p1; // in 2D mode, if one point is in front of the screen and the other is behind, we don't draw the segment // (to achieve this, we draw degenerated triangles, i.e. triangles that have two identical verticies which // make them "flat") if (!MapView.Draw3DLines && (start.z > 0) != (end.z > 0)) { vertices[startIndex + 0] = vertices[startIndex + 1]; if (startIndex >= 2) { vertices[startIndex - 2] = vertices[startIndex - 1]; } } }
public static void DrawGroundMarker(CelestialBody body, double latitude, double longitude, Color c, bool map, double rotation = 0, double radius = 0) { Vector3d up = body.GetSurfaceNVector(latitude, longitude); var height = body.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(longitude, Vector3d.down) * QuaternionD.AngleAxis(latitude, Vector3d.forward) * Vector3d.right); if (height < body.Radius) { height = body.Radius; } Vector3d center = body.position + height * up; Vector3d camPos = map ? ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.Camera.transform.position) : (Vector3d)FlightCamera.fetch.mainCamera.transform.position; if (IsOccluded(center, body, camPos)) { return; } Vector3d north = Vector3d.Exclude(up, body.transform.up).normalized; if (radius <= 0) { radius = map ? body.Radius / 15 : 5; } if (!map) { Vector3 centerPoint = FlightCamera.fetch.mainCamera.WorldToViewportPoint(center); if (centerPoint.z < 0) { return; } } GLTriangle(center, center + radius * (QuaternionD.AngleAxis(rotation - 10, up) * north), center + radius * (QuaternionD.AngleAxis(rotation + 10, up) * north), c, map); GLTriangle(center, center + radius * (QuaternionD.AngleAxis(rotation + 110, up) * north), center + radius * (QuaternionD.AngleAxis(rotation + 130, up) * north), c, map); GLTriangle(center, center + radius * (QuaternionD.AngleAxis(rotation - 110, up) * north), center + radius * (QuaternionD.AngleAxis(rotation - 130, up) * north), c, map); }
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(); }
public static void GLPixelLine(Vector3d worldPosition1, Vector3d worldPosition2, bool map) { Vector3 screenPoint1, screenPoint2; if (map) { screenPoint1 = PlanetariumCamera.Camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(worldPosition1)); screenPoint2 = PlanetariumCamera.Camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(worldPosition2)); } else { screenPoint1 = FlightCamera.fetch.mainCamera.WorldToScreenPoint(worldPosition1); screenPoint2 = FlightCamera.fetch.mainCamera.WorldToScreenPoint(worldPosition2); } if (screenPoint1.z > 0 && screenPoint2.z > 0) { GL.Vertex3(screenPoint1.x, screenPoint1.y, 0); GL.Vertex3(screenPoint2.x, screenPoint2.y, 0); } }