public static void GLTriangles(Vector3[] worldVertices, int[] tris, Color c, bool filled = true) { float far; var camera = GLBeginWorld(out far); if (MapView.MapIsEnabled) { for (int i = 0, len = worldVertices.Length; i < len; i++) { worldVertices[i] = ScaledSpace.LocalToScaledSpace(worldVertices[i]); } } GL.Begin(filled? GL.TRIANGLES : GL.LINES); GL.Color(c); for (int i = 0, len = tris.Length / 3; i < len; i++) { int j = i * 3; int k = tris[j + 1], l = tris[j + 2]; j = tris[j]; GL.Vertex(worldVertices[j]); GL.Vertex(worldVertices[k]); GL.Vertex(worldVertices[k]); GL.Vertex(worldVertices[l]); GL.Vertex(worldVertices[l]); GL.Vertex(worldVertices[j]); } GL.End(); GL.PopMatrix(); camera.farClipPlane = far; }
public void Update() { _scaledCamera.transform.position = ScaledSpace.LocalToScaledSpace(_cameraGameObject.transform.position); _scaledCamera.transform.rotation = _cameraGameObject.transform.rotation; _galaxyGameObject.transform.rotation = _cameraGameObject.transform.rotation; }
private void GatherLinkLines(List <CommLink> linkList) { var settings = RACommNetScenario.MapUISettings; foreach (RACommLink link in linkList) { GameObject go; if (!linkRenderers.ContainsKey(link)) { go = new GameObject("LinkLineRenderer"); LineRenderer rend = go.AddComponent <LineRenderer>(); bool dotted = link.FwdAntennaTx.TechLevelInfo.Level < RACommNetScenario.minRelayTL || link.FwdAntennaRx.TechLevelInfo.Level < RACommNetScenario.minRelayTL; InitializeRenderer(rend, dotted); linkRenderers.Add(link, go); } go = linkRenderers[link]; LineRenderer renderer = go.GetComponent <LineRenderer>(); renderer.enabled = true; Vector3d scaledStart = ScaledSpace.LocalToScaledSpace(link.start.precisePosition); Vector3d scaledEnd = ScaledSpace.LocalToScaledSpace(link.end.precisePosition); Camera cam = PlanetariumCamera.Camera; Vector3 camPos = cam.transform.position; float dStart = (float)Vector3d.Distance(camPos, scaledStart); float dEnd = (float)Vector3d.Distance(camPos, scaledEnd); renderer.startWidth = dStart * settings.lineScaleWidth / 1000; renderer.endWidth = dEnd * settings.lineScaleWidth / 1000; Color startColor = (settings.radioPerspective == RadioPerspective.Transmit) ? LinkColor(link.FwdMetric) : LinkColor(link.RevMetric); Color endColor = (settings.radioPerspective == RadioPerspective.Transmit) ? LinkColor(link.RevMetric) : LinkColor(link.FwdMetric); SetColorGradient(renderer, startColor, endColor); renderer.positionCount = 2; renderer.SetPositions(new Vector3[] { scaledStart, scaledEnd }); } }
public void UpdateWaypoint(Waypoint wp) { if (MapView.MapIsEnabled) { foreach (CelestialBody body in FlightGlobals.Bodies) { if (wp.isOnSurface) { if (body.GetName() == wp.celestialName) { if (body.pqsController != null) { Vector3d pqsRadialVector = QuaternionD.AngleAxis(wp.longitude, Vector3d.down) * QuaternionD.AngleAxis(wp.latitude, Vector3d.forward) * Vector3d.right; wp.height = body.pqsController.GetSurfaceHeight(pqsRadialVector) - body.pqsController.radius; if (wp.height < 0) { wp.height = 0; } } Vector3d surfacePos = body.GetWorldSurfacePosition(wp.latitude, wp.longitude, wp.height + wp.altitude); Vector3d scaledPos = ScaledSpace.LocalToScaledSpace(surfacePos); wp.worldPosition = new Vector3((float)scaledPos.x, (float)scaledPos.y, (float)scaledPos.z); wp.isOccluded = IsOccluded(surfacePos, body); } } else { wp.worldPosition = ScaledSpace.LocalToScaledSpace(wp.orbitPosition); } } } }
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) { 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); mPoints3D[0] = camera.ScreenToWorldPoint(mPoints2D[0]); mPoints3D[1] = camera.ScreenToWorldPoint(mPoints2D[1]); mPoints3D[2] = camera.ScreenToWorldPoint(mPoints2D[2]); mPoints3D[3] = camera.ScreenToWorldPoint(mPoints2D[3]); mMeshFilter.mesh.vertices = MapView.Draw3DLines ? mPoints3D : mPoints2D; mMeshFilter.mesh.RecalculateBounds(); mMeshFilter.mesh.MarkDynamic(); }
private void UpdateRing(LineRenderer line, Vector3d center, double radius, Vector3d direction, float camDist, float thickness, Color color) { if (camDist > 0) { line.positionCount = Math.Min(96, Math.Max(16, 12 + 50000 / ((int)camDist + 1))) / 4 * 4; var poses = new Vector3[line.positionCount]; int quadLen = line.positionCount / 4; Vector3d dX = radius * Vector3d.Cross( direction, (direction.x != 0 || direction.z != 0) ? Vector3d.up : Vector3d.forward ).normalized; Vector3d dY = radius * Vector3d.Cross(direction, dX).normalized; for (int i = 0; i < quadLen; ++i) { // Make a circle 4 points at a time to reduce trig calls float theta = 2f * Mathf.PI * i / line.positionCount; float cosTheta = Mathf.Cos(theta); float sinTheta = Mathf.Sin(theta); poses[i] = ScaledSpace.LocalToScaledSpace(center + cosTheta * dX + sinTheta * dY); poses[i + quadLen] = ScaledSpace.LocalToScaledSpace(center - sinTheta * dX + cosTheta * dY); poses[i + 2 * quadLen] = ScaledSpace.LocalToScaledSpace(center - cosTheta * dX - sinTheta * dY); poses[i + 3 * quadLen] = ScaledSpace.LocalToScaledSpace(center + sinTheta * dX - cosTheta * dY); } line.SetPositions(poses); line.startColor = line.endColor = color; line.startWidth = line.endWidth = thickness; line.enabled = true; } else { // Can't see, don't draw old fragments line.enabled = false; } }
// for debug purpose public static void CommitWorldVector(Vector3d start, Vector3d direction, float lengthKm, Color color) { Vector3d end = ScaledSpace.LocalToScaledSpace(start + (direction * (lengthKm * 1000.0))); ScaledSpace.LocalToScaledSpace(ref start); Commit(start, end, color); }
/// <summary> /// Returns the <see cref="Vessel.solarFlux"/> at the given location. /// </summary> public Double CalculateFluxAt(Vessel vessel) { // Get sunVector Boolean directSunlight = false; Vector3 integratorPosition = vessel.transform.position; Vector3d scaledSpace = ScaledSpace.LocalToScaledSpace(integratorPosition); Vector3 position = 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 Thermal Stats if (vessel.mainBody.atmosphere) { if (sun == GetLocalStar(vessel.mainBody)) { FlightIntegrator FI = vessel.GetComponent <FlightIntegrator>(); vessel.mainBody.GetAtmoThermalStats(true, sun, sunVector, Vector3d.Dot(sunVector, vessel.upAxis), vessel.upAxis, vessel.altitude, out FI.atmosphereTemperatureOffset, out FI.bodyEmissiveFlux, out FI.bodyAlbedoFlux); } } // Get Solar Flux Double realDistanceToSun = 0; if (!Physics.Raycast(ray, out RaycastHit raycastHit, Single.MaxValue, ModularFlightIntegrator.SunLayerMask)) { directSunlight = true; realDistanceToSun = scale * ScaledSpace.ScaleFactor - sun.Radius; }
private static Double Flux(ModularFlightIntegrator fi, KopernicusStar star) { // Nullchecks if (fi.Vessel == null || fi.Vessel.state == Vessel.State.DEAD || fi.CurrentMainBody == 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; }
/// <summary> /// Place the 2D label at the correct projected spot on /// the screen from its location in 3D space: /// </summary> private void LabelPlacement() { /* * Vector3 screenPos = GetScreenPosfor( shipCenterCoords + labelLocation); * * // If the projected location is on-screen: * if (screenPos.z >= 0 * && screenPos.x >= 0 && screenPos.x <= Utils.GetCurrentCamera().pixelWidth * && screenPos.y >= 0 && screenPos.y <= Utils.GetCurrentCamera().pixelHeight) * { * label.enabled = true; * // was: labelCanvasObj.transform.position = screenPos; * labelCanvasObj.transform.position = screenPos; * } * else * { * label.enabled = false; * } */ labelTransform.localPosition = labelLocation; labelTransform.localRotation = camRot; Vector3 scaledLabelLocaton = (isOnMap ? (Vector3)ScaledSpace.LocalToScaledSpace(labelTransform.position) : labelTransform.position); float distanceFromCamera = (camPos - scaledLabelLocaton).magnitude; if (isOnMap) { distanceFromCamera *= ScaledSpace.ScaleFactor; } labelTransform.localScale = new Vector3(0.006f, 0.006f, 0.006f) * distanceFromCamera * (float)Width; label.enabled = true; }
private float cameraDist(Vector3d pos) { return((float)Vector3d.Dot( ScaledSpace.LocalToScaledSpace(pos) - PlanetariumCamera.Camera.transform.position, PlanetariumCamera.Camera.transform.forward )); }
/// <summary> /// Draws the orbit. /// </summary> /// <param name="orbit">The orbit.</param> /// <param name="color">The color of the created line.</param> /// <param name="style">The style of the created line.</param> public static void DrawOrbit(Orbit orbit, Color color, Style style = Style.Solid) { // Only render visible stuff if (!orbit.referenceBody.scaledBody.GetComponent <Renderer>().isVisible) { return; } // Clear points Points.Clear(); // Calculations for elliptical orbits if (orbit.eccentricity < 1) { for (Int32 i = 0; i < Math.Floor(360.0 / RESOLUTION); i++) { Points.Add(ScaledSpace.LocalToScaledSpace( orbit.getPositionFromEccAnomaly(i * RESOLUTION * Math.PI / 180))); } Points.Add(Points[0]); // close the loop } // Calculations for hyperbolic orbits else { for (Int32 i = -1000; i <= 1000; i += 5) { Points.Add(ScaledSpace.LocalToScaledSpace( orbit.getPositionFromEccAnomaly(i * RESOLUTION * Math.PI / 180))); } } // Draw the path DrawPath(Points, color, style); }
public static void GLDrawPoint(Vector3 ori, Color c, MaterialWrapper mat = null, float r = 0.1f) { float far; var i = new Vector3(r, 0, 0); var j = new Vector3(0, r, 0); var k = new Vector3(0, 0, r); if (MapView.MapIsEnabled) { i = ScaledSpace.LocalToScaledSpace(i); j = ScaledSpace.LocalToScaledSpace(j); k = ScaledSpace.LocalToScaledSpace(k); ori = ScaledSpace.LocalToScaledSpace(ori); } var camera = GLBeginWorld(out far, mat); GL.Begin(GL.LINES); GL.Color(c); gl_line(ori - i, ori + i); gl_line(ori - j, ori + j); gl_line(ori - k, ori + k); GL.End(); GL.PopMatrix(); camera.farClipPlane = far; }
/// <summary> /// Small method to handle flux /// </summary> public static Double Flux(ModularFlightIntegrator fi, KopernicusStar star) { // Nullchecks if (fi.Vessel == null || fi.Vessel.state == Vessel.State.DEAD || fi.CurrentMainBody == null) { return(0); } // Get sunVector RaycastHit raycastHit; Boolean directSunlight = false; 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 Solar Flux Double realDistanceToSun = 0; if (!Physics.Raycast(ray, out 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); }
public static void GLLines(Vector3[] points, Color c, MaterialWrapper mat = null) { if (points.Length < 2) { return; } float far; var camera = GLBeginWorld(out far, mat); if (MapView.MapIsEnabled) { for (int i = 0, len = points.Length; i < len; i++) { points[i] = ScaledSpace.LocalToScaledSpace(points[i]); } } GL.Begin(GL.LINES); GL.Color(c); for (int i = 0, len = points.Length; i < len - 1; i++) { GL.Vertex(points[i]); GL.Vertex(points[i + 1]); } GL.End(); GL.PopMatrix(); camera.farClipPlane = far; }
public static void GLTriangles(Vector3[] worldVertices, int[] tris, Color c, MaterialWrapper mat = null) { float far; var camera = GLBeginWorld(out far, mat); if (MapView.MapIsEnabled) { for (int i = 0, len = worldVertices.Length; i < len; i++) { worldVertices[i] = ScaledSpace.LocalToScaledSpace(worldVertices[i]); } } GL.Begin(GL.TRIANGLES); GL.Color(c); for (int i = 0, len = tris.Length / 3; i < len; i++) { int j = i * 3; GL.Vertex(worldVertices[tris[j]]); GL.Vertex(worldVertices[tris[j + 1]]); GL.Vertex(worldVertices[tris[j + 2]]); } GL.End(); GL.PopMatrix(); camera.farClipPlane = far; }
//internal Int32 ArrowMult = 1000 private void DrawLineArrow(LineRenderer line1, LineRenderer line2, Vector3d pointStart, Vector3d pointEnd, Vector3d vectPlaneNormal, Double ArrowArmLength) { Vector3d vectArrow = (pointEnd - pointStart).normalized * ArrowArmLength; //400000; Vector3d vectArrow1 = Quaternion.AngleAxis((Single)30, vectPlaneNormal) * vectArrow; Vector3d vectArrow2 = Quaternion.AngleAxis(-(Single)30, vectPlaneNormal) * vectArrow; line1.SetPosition(0, ScaledSpace.LocalToScaledSpace(pointEnd - vectArrow1)); line1.SetPosition(1, ScaledSpace.LocalToScaledSpace(pointEnd)); line2.SetPosition(0, ScaledSpace.LocalToScaledSpace(pointEnd - vectArrow2)); line2.SetPosition(1, ScaledSpace.LocalToScaledSpace(pointEnd)); //line.SetWidth((Single)StartWidth / 1000 * (Single)(cam.transform.position - pointStart).magnitude, (Single)EndWidth / 1000 * (Single)(cam.transform.position - pointEnd).magnitude); //line1.SetWidth((float)10 / 1000 * cam.Distance, (float)10 / 1000 * cam.Distance); line1.startWidth = 10f / 1000f * cam.Distance; line1.endWidth = 10f / 1000f * cam.Distance; //line2.SetWidth((float)10 / 1000 * cam.Distance, (float)10 / 1000 * cam.Distance); line2.startWidth = 10f / 1000f * cam.Distance; line2.endWidth = 10f / 1000f * cam.Distance; //Double distToStart = ScaledSpace.LocalToScaledSpace(pointStart).magnitude; //Double distToEnd = ScaledSpace.LocalToScaledSpace(pointEnd).magnitude; //line.SetWidth((float)StartWidth / 10000f * (Single)distToStart, (float)EndWidth / 10000f * (Single)distToEnd); line1.enabled = true; line2.enabled = true; }
public static bool DrawCBMarker(CelestialBody body, Coordinates pos, Color color, out Vector3d worldPos, Texture2D texture = null, float size = DefaultIconSize) { worldPos = Vector3d.zero; Camera camera; Vector3d point; if (MapView.MapIsEnabled) { //TODO: cache local center coordinates of the marker camera = PlanetariumCamera.Camera; worldPos = body.position + (pos.Alt + body.Radius) * body.GetSurfaceNVector(pos.Lat, pos.Lon); point = ScaledSpace.LocalToScaledSpace(worldPos); if (IsOccluded(worldPos, body)) { return(false); } } else { camera = FlightCamera.fetch.mainCamera; worldPos = body.GetWorldSurfacePosition(pos.Lat, pos.Lon, pos.Alt); point = worldPos; if (camera.transform.InverseTransformPoint(worldPos).z <= 0) { return(false); } } return(color.a > 0 && DrawMarker(camera.WorldToScreenPoint(point), color, texture, size)); }
private void UpdateLineCache() { int oldLength = mLines.Count; int newLength = mEdges.Count; for (int i = newLength; i < oldLength; i++) { VectorLine line = mLines[i]; Vector.DestroyLine(ref line); } if (newLength < oldLength) { mLines.RemoveRange(newLength, oldLength - newLength); } HashSet <TypedEdge <ISatellite> > .Enumerator it = mEdges.GetEnumerator(); for (int i = 0; i < newLength; i++) { it.MoveNext(); var newPoints = new Vector3[] { ScaledSpace.LocalToScaledSpace(it.Current.A.Position), ScaledSpace.LocalToScaledSpace(it.Current.B.Position) }; AssignVectorLine(i, newPoints, it.Current); Vector.Active(mLines[i], CheckVisibility(it.Current)); } }
public void UpdatePoints(Vector3d a, Vector3d b, Color clr) { var cam = PlanetariumCamera.Camera; a = cam.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(a)); b = cam.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(b)); if (a.z <= 0.0 || b.z <= 0.0) { a = b; //< hack away } if (!MapView.Draw3DLines) { a.z = b.z = 0.0f; } else { a = cam.ScreenToWorldPoint(a); b = cam.ScreenToWorldPoint(b); } float width = MapView.Draw3DLines ? MapView.MapCamera.Distance * 0.01f : 3.6f; lr.SetWidth(width, width); lr.SetPosition(0, a); lr.SetPosition(1, b); lr.SetColors(clr, clr); }
private void GatherLinkLines(List <CommLink> linkList) { foreach (RACommLink link in linkList) { GameObject go; if (!linkRenderers.ContainsKey(link)) { go = new GameObject("LinkLineRenderer"); LineRenderer rend = go.AddComponent <LineRenderer>(); InitializeRenderer(rend); linkRenderers.Add(link, go); } go = linkRenderers[link]; LineRenderer renderer = go.GetComponent <LineRenderer>(); renderer.enabled = true; Vector3 scaledStart = ScaledSpace.LocalToScaledSpace(link.start.position); Vector3 scaledEnd = ScaledSpace.LocalToScaledSpace(link.end.position); Camera cam = PlanetariumCamera.Camera; Vector3 camPos = cam.transform.position; float dStart = Vector3.Distance(camPos, scaledStart); float dEnd = Vector3.Distance(camPos, scaledEnd); renderer.startWidth = dStart * lineScaleWidth / 1000; renderer.endWidth = dEnd * lineScaleWidth / 1000; Color startColor = (linkEndPerspective == RadioPerspective.Transmit) ? LinkColor(link.FwdMetric) : LinkColor(link.RevMetric); Color endColor = (linkEndPerspective == RadioPerspective.Transmit) ? LinkColor(link.RevMetric) : LinkColor(link.FwdMetric); SetColorGradient(renderer, startColor, endColor); renderer.positionCount = 2; renderer.SetPositions(new Vector3[] { scaledStart, scaledEnd }); } }
/// <summary> /// Starts up fi instance /// </summary> protected override void Awake() { if (Stars == null) { Stars = new List <KopernicusStar>(); } if (SolarFlux == null) { SolarFlux = new Dictionary <String, Double>(); } Stars.Add(this); DontDestroyOnLoad(this); light = gameObject.GetComponent <Light>(); // Gah typeof(Sun).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Last(f => f.FieldType == typeof(Light)).SetValue(this, light); // sun flare Camera.onPreCull += cam => { Vector3d scaledSpace = target.transform.position - ScaledSpace.LocalToScaledSpace(sun.position); sunDirection = scaledSpace.normalized; sunRotation = sunDirection; sunRotation.x = Math.Round(sunRotation.x, sunRotationPrecision); sunRotation.y = Math.Round(sunRotation.y, sunRotationPrecision); sunRotation.z = Math.Round(sunRotation.z, sunRotationPrecision); if (sunRotation != Vector3d.zero) { transform.forward = sunRotation; } }; }
// return the surface radiation for the body specified (used by body info panel) public static double ComputeSurface(CelestialBody b, double gamma_transparency) { // store stuff Space gsm; Vector3 p; float D; // transform to local space once Vector3d position = ScaledSpace.LocalToScaledSpace(b.position); // accumulate radiation double radiation = 0.0; CelestialBody body = b; while (body != null) { RadiationBody rb = Info(body); RadiationModel mf = rb.model; if (mf.Has_field()) { // generate radii-normalized GSM space gsm = Gsm_space(rb, true); // move the poing in GSM space p = gsm.Transform_in(position); // accumulate radiation and determine pause/belt flags if (mf.has_inner) { D = mf.Inner_func(p); radiation += Lib.Clamp(D / -0.0666f, 0.0f, 1.0f) * rb.radiation_inner; } if (mf.has_outer) { D = mf.Outer_func(p); radiation += Lib.Clamp(D / -0.0333f, 0.0f, 1.0f) * rb.radiation_outer; } if (mf.has_pause) { gsm = Gsm_space(rb, false); p = gsm.Transform_in(position); D = mf.Pause_func(p); radiation += Lib.Clamp(D / -0.1332f, 0.0f, 1.0f) * rb.radiation_pause; } } // avoid loops in the chain body = (body.referenceBody != null && body.referenceBody.referenceBody == body) ? null : body.referenceBody; } // add extern radiation radiation += PreferencesStorm.Instance.ExternRadiation; // clamp radiation to positive range // note: we avoid radiation going to zero by using a small positive value radiation = Math.Max(radiation, Nominal); // return radiation, scaled by gamma transparency if inside atmosphere return(radiation * gamma_transparency); }
private void LocalToScaledSpace(List <Vector3d> local, List <Vector3> scaled) { scaled.Clear(); foreach (var x in local) { scaled.Add(ScaledSpace.LocalToScaledSpace(x)); } }
// public void OnPreRender() public void updateProperties() { sunViewPortPos = Core.Instance.scaledSpaceCamera.WorldToViewportPoint (ScaledSpace.LocalToScaledSpace(source.transform.position)); float dist = (float)(Core.Instance.scaledSpaceCamera.transform.position - ScaledSpace.LocalToScaledSpace(source.transform.position)) .magnitude; sunGlareScale = dist / 2266660f; //if dist > 1.25*sunglareFadeDistance -->1 //if dist < 0.25*sunglareFadeDistance -->0 //else values smoothstepped in between sunGlareFade = Mathf.SmoothStep(0, 1, (dist / sunGlareFadeDistance) - 0.25f); //if dist < 0.5 * ghostFadeDistance -->1 //if dist > 1.5 * ghostFadeDistance -->0 //else values smoothstepped in between ghostFade = Mathf.SmoothStep(0, 1, (dist - 0.5f * ghostFadeDistance) / (ghostFadeDistance)); ghostFade = 1 - ghostFade; hitStatus = false; if (!MapView.MapIsEnabled && !(HighLogic.LoadedScene == GameScenes.TRACKSTATION)) //if (!MapView.MapIsEnabled) { hitStatus = Physics.Raycast(Core.Instance.farCamera.transform.position, (source.transform.position - Core.Instance.farCamera.transform.position).normalized, out hit, Mathf.Infinity, (int)((1 << 15) + (1 << 0))); if (!hitStatus) { hitStatus = Physics.Raycast(Core.Instance.scaledSpaceCamera.transform.position, (ScaledSpace.LocalToScaledSpace(source.transform.position) - Core.Instance.scaledSpaceCamera.transform.position) .normalized, out hit, Mathf.Infinity, (int)((1 << 10))); } } else { hitStatus = Physics.Raycast(Core.Instance.scaledSpaceCamera.transform.position, (ScaledSpace.LocalToScaledSpace(source.transform.position) - Core.Instance.transform.position).normalized, out hit, Mathf.Infinity, (int)((1 << 10))); } if (hitStatus) { //if sun visible, draw sunflare if (hit.transform.gameObject.name == sourceName) { hitStatus = false; } } eclipse = hitStatus; sunglareMaterial.SetVector("sunViewPortPos", sunViewPortPos); sunglareMaterial.SetFloat("aspectRatio", Core.Instance.scaledSpaceCamera.aspect); sunglareMaterial.SetFloat("sunGlareScale", sunGlareScale); sunglareMaterial.SetFloat("sunGlareFade", sunGlareFade); sunglareMaterial.SetFloat("ghostFade", ghostFade); }
private void initMeshFromImpact(Vector3 bodyPosition, Mesh mesh, Vector3 impactPosition, Color color) { var vertices = new Vector3[8]; var uvs = new Vector2[8]; var triangles = new int[12]; Vector3 camPos = ScaledSpace.ScaledToLocalSpace(PlanetariumCamera.Camera.transform.position) - bodyPosition; Vector3 crossV1 = Vector3.Cross(impactPosition, Vector3.right).normalized; Vector3 crossV2 = Vector3.Cross(impactPosition, crossV1).normalized; float crossThickness = Mathf.Min(lineWidth * 0.001f * Vector3.Distance(camPos, impactPosition), 6000.0f); float crossSize = crossThickness * 10.0f; vertices[0] = impactPosition - crossV1 * crossSize + crossV2 * crossThickness; uvs[0] = new Vector2(0.8f, 1); vertices[1] = impactPosition - crossV1 * crossSize - crossV2 * crossThickness; uvs[1] = new Vector2(0.8f, 0); vertices[2] = impactPosition + crossV1 * crossSize + crossV2 * crossThickness; uvs[2] = new Vector2(0.8f, 1); vertices[3] = impactPosition + crossV1 * crossSize - crossV2 * crossThickness; uvs[3] = new Vector2(0.8f, 0); triangles[0] = 0; triangles[1] = 1; triangles[2] = 3; triangles[3] = 0; triangles[4] = 3; triangles[5] = 2; vertices[4] = impactPosition - crossV2 * crossSize - crossV1 * crossThickness; uvs[4] = new Vector2(0.8f, 0); vertices[5] = impactPosition - crossV2 * crossSize + crossV1 * crossThickness; uvs[5] = new Vector2(0.8f, 1); vertices[6] = impactPosition + crossV2 * crossSize - crossV1 * crossThickness; uvs[6] = new Vector2(0.8f, 0); vertices[7] = impactPosition + crossV2 * crossSize + crossV1 * crossThickness; uvs[7] = new Vector2(0.8f, 1); triangles[6] = 4; triangles[7] = 5; triangles[8] = 7; triangles[9] = 4; triangles[10] = 7; triangles[11] = 6; var colors = new Color[vertices.Length]; for (int i = 0; i < colors.Length; ++i) { colors[i] = color; } for (int i = 0; i < vertices.Length; ++i) { // in current implementation, impact positions are displayed only if MapView is in 3D mode (i.e. not zoomed out too far) vertices[i] = MapView.Draw3DLines ? (Vector3)ScaledSpace.LocalToScaledSpace(vertices[i] + bodyPosition) : new Vector3(0, 0, 0); } mesh.Clear(); mesh.vertices = vertices; mesh.uv = uvs; mesh.colors = colors; mesh.triangles = triangles; mesh.RecalculateBounds(); }
public void updatePosition() { if (!orbitValid) { return; } gameObj.transform.localPosition = worldPosition; Vector3 scaled_pos = ScaledSpace.LocalToScaledSpace(worldPosition); //Determine the scale of the line so its thickness is constant from the map camera view float apparent_size = 0.01f; bool pointed = true; switch (info.state) { case State.ACTIVE: apparent_size = 0.015f; pointed = true; break; case State.INACTIVE: apparent_size = 0.01f; pointed = true; break; case State.DEAD: apparent_size = 0.01f; pointed = false; break; } float scale = (float)(apparent_size * Vector3.Distance(MapView.MapCamera.transform.position, scaled_pos)); //Set line vertex positions Vector3 line_half_dir = worldDirection * (scale * ScaledSpace.ScaleFactor); if (pointed) { line.SetWidth(scale, 0); } else { line.SetWidth(scale, scale); line_half_dir *= 0.5f; } line.SetPosition(0, ScaledSpace.LocalToScaledSpace(worldPosition - line_half_dir)); line.SetPosition(1, ScaledSpace.LocalToScaledSpace(worldPosition + line_half_dir)); if (!situationIsGrounded(info.situation)) { orbitRenderer.driver.orbit.UpdateFromUT(adjustedUT); } }
public void UpdatePredictedLine() { for (int i = 0; i < timesPerUpdate; i++) { Iterate(timeStep); } if (predictionLineRenderer == null) { InitializePredictedLine(); } if (MapView.MapIsEnabled) { MapView mapCamera = (MapView)GameObject.FindObjectOfType(typeof(MapView)); try { predictionLineRenderer.SetVertexCount(prevRefPositions.Count); predictionLineRenderer.enabled = true; predictionLineRenderer.useWorldSpace = true; predictionLineRenderer.SetWidth(0.0015f * MapView.MapCamera.Distance, 0.0015f * MapView.MapCamera.Distance); for (int i = 0; i < prevRefPositions.Count; i++) { predictionLineRenderer.SetPosition(i, ScaledSpace.LocalToScaledSpace(prevRefPositions[i] + prevVessel.mainBody.getPositionAtUT(Planetarium.GetUniversalTime()))); } coordXRenderer.enabled = true; coordXRenderer.SetVertexCount(2); coordXRenderer.SetWidth(0.002f * MapView.MapCamera.Distance, 0.002f * MapView.MapCamera.Distance); coordXRenderer.SetPosition(0, ScaledSpace.LocalToScaledSpace(Vector3.zero)); coordXRenderer.SetPosition(1, ScaledSpace.LocalToScaledSpace(new Vector3(1000000.0f, 0.0f, 0.0f))); coordYRenderer.enabled = true; coordYRenderer.SetVertexCount(2); coordYRenderer.SetWidth(0.002f * MapView.MapCamera.Distance, 0.002f * MapView.MapCamera.Distance); coordYRenderer.SetPosition(0, ScaledSpace.LocalToScaledSpace(Vector3.zero)); coordYRenderer.SetPosition(1, ScaledSpace.LocalToScaledSpace(new Vector3(0.0f, 1000000.0f, 0.0f))); coordZRenderer.enabled = true; coordZRenderer.SetVertexCount(2); coordZRenderer.SetWidth(0.002f * MapView.MapCamera.Distance, 0.002f * MapView.MapCamera.Distance); coordZRenderer.SetPosition(0, ScaledSpace.LocalToScaledSpace(Vector3.zero)); coordZRenderer.SetPosition(1, ScaledSpace.LocalToScaledSpace(new Vector3(0.0f, 0.0f, 1000000.0f))); } catch { } } else { predictionLineRenderer.enabled = false; coordXRenderer.enabled = false; coordYRenderer.enabled = false; coordZRenderer.enabled = false; } }
public static void GLVertex(Vector3d worldPosition, bool map) { Vector3 screenPoint = map ? PlanetariumCamera.Camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(worldPosition)) : FlightCamera.fetch.mainCamera.WorldToScreenPoint(worldPosition); GL.Vertex3(screenPoint.x, screenPoint.y, 0); }
void OnPreCull(Camera camera) { Vector3d scaledSpace = target.transform.position - ScaledSpace.LocalToScaledSpace(sun.position); sunDirection = scaledSpace.normalized; if (sunDirection != Vector3d.zero) { transform.forward = sunDirection; } }