private static Double3 GenerateOffsets(ulong seed) { Random.InitState(Convert.ToInt32(seed)); Double3 offsets = new Double3 { x = Random.value, y = Random.value, z = Random.value }; return(offsets); }
private static PointMapping GetMapping(Double3 point, IList <Double3> lowResPoints, IList <Double3> lowResNormals, IList <Triangle> lowResTriangles, Sphere[] spheres) { //Find the closest triangle in the low resoltuion mesh int l = spheres.Length; int indexOfClosest = -1; double closestDist = double.MaxValue * 1e-8; Triangle tri; Double3 a, b, c; double uBest = 1.0 / 3.0, vBest = 1.0 / 3.0; for (int i = 0; i < l; ++i) { Sphere s = spheres[i]; double d2 = (point - spheres[i].Center).LengthSquared; double sum = closestDist + s.Radius; if (sum * sum > d2) //The solution can only improve if this condition is met { tri = lowResTriangles[i]; a = lowResPoints[tri.A]; b = lowResPoints[tri.B]; c = lowResPoints[tri.C]; double u, v, w; d2 = DistancePointTriangleSquared(a, b, c, point, out u, out v, out w); if (d2 < closestDist * closestDist) { closestDist = Math.Sqrt(d2); indexOfClosest = i; uBest = u; vBest = v; } } } //Compute barycentricCoordinates tri = lowResTriangles[indexOfClosest]; a = lowResPoints[tri.A]; b = lowResPoints[tri.B]; c = lowResPoints[tri.C]; // Optimization reduces artifacts, unfortunately cannot fully avoid them Double3 uvw = PatternSearch(uBest, vBest, point, lowResPoints[tri.A], lowResPoints[tri.B], lowResPoints[tri.C], lowResNormals[tri.A], lowResNormals[tri.B], lowResNormals[tri.C]); Double3 dir = point - (uvw.X * a + uvw.Y * b + uvw.Z * c); Double3 normal = uvw.X * lowResNormals[tri.A] + uvw.Y * lowResNormals[tri.B] + uvw.Z * lowResNormals[tri.C]; double offset = dir.Length * Math.Sign(Double3.Dot(dir, normal)); Double3 p = uvw.X * a + uvw.Y * b + uvw.Z * c; p = p + offset * normal; return(new PointMapping(tri, uvw, offset)); //uvw are barycentric Coordinates }
/// <summary> /// /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="sl"></param> private void RayboundingNearestPath(Double3 p1, Double3 p2, double offset, ref List <Double2> paths) { List <Double2> listpath = new List <Double2>(); // 对边行为 if ((p1.z == 1 && p2.z == 3) || (p1.z == 3 && p2.z == 1)) { double v1 = p1.x - this.leftBottom.x + p2.x - this.leftBottom.x; double v2 = -p1.x + this.RightBottom.x - p2.x + this.RightBottom.x; if (v1 <= v2) { listpath.Add(new Double2(this.leftBottom.x - offset, p1.y)); listpath.Add(new Double2(this.leftBottom.x - offset, p2.y)); } else { listpath.Add(new Double2(this.RightBottom.x + offset, p1.y)); listpath.Add(new Double2(this.RightBottom.x + offset, p2.y)); } } else if ((p1.z == 2 && p2.z == 4) || (p1.z == 4 && p2.z == 2)) { double v1 = p1.y - this.leftBottom.y + p2.y - this.leftBottom.y; double v2 = -p1.y + this.LeftUp.y - p2.y + this.LeftUp.y; if (v1 <= v2) { listpath.Add(new Double2(p1.x, this.leftBottom.y - offset)); listpath.Add(new Double2(p2.x, this.leftBottom.y - offset)); } else { listpath.Add(new Double2(p1.x, this.LeftUp.y + offset)); listpath.Add(new Double2(p2.x, this.LeftUp.y + offset)); } } else if ((p1.z == 1 && p2.z == 2) || (p1.z == 2 && p2.z == 1)) { listpath.Add(this.RightBottom + new Double2(offset, -offset)); } else if ((p1.z == 2 && p2.z == 3) || (p1.z == 3 && p2.z == 2)) { listpath.Add(this.rightUp + new Double2(offset, offset)); } else if ((p1.z == 3 && p2.z == 4) || (p1.z == 4 && p2.z == 3)) { listpath.Add(this.LeftUp + new Double2(-offset, offset)); } else if ((p1.z == 4 && p2.z == 1) || (p1.z == 1 && p2.z == 4)) { listpath.Add(this.leftBottom + new Double2(-offset, -offset)); } paths = listpath; }
private void StayTouch(int fingerId, int i, ref Double3 summedPositionDelta, ref int dragingFingerCount, ref int horizontalAxis) { global::Touch.TouchState touchState = this.touchesInfo[fingerId].touchState; if (touchState != global::Touch.TouchState.OnEmpty) { if (touchState == global::Touch.TouchState.OnUI) { if (this.touchesInfo[fingerId].touchDownButton == Ref.inputController.leftArrow) { horizontalAxis = -1; } if (this.touchesInfo[fingerId].touchDownButton == Ref.inputController.rightArrow) { horizontalAxis = 1; } if (Ref.controller != null && Ref.controller.throttlePercentUI != null && this.touchesInfo[fingerId].touchDownButton == Ref.controller.throttlePercentUI.transform.parent) { float num = this.touchesInfo[fingerId].lastFingerPosPixels.y - Input.GetTouch(i).position.y; if (num != 0f && Ref.mainVessel != null) { if (Ref.mainVessel.controlAuthority) { Ref.mainVessel.SetThrottle(new Vessel.Throttle(Ref.mainVessel.throttle.throttleOn, Mathf.Clamp01(Ref.mainVessel.throttle.throttleRaw - num / 318f))); if (Ref.inputController.instructionSlideThrottleHolder.activeSelf) { Ref.inputController.instructionSlideThrottleHolder.SetActive(false); Ref.inputController.CheckAllInstructions(); } } else if (Ref.controller.msgUI.color.a < 0.6f) { Ref.controller.ShowMsg("No control"); } } } } } else { if (Ref.currentScene == Ref.SceneType.Build) { Vector2 deltaPixel = this.touchesInfo[fingerId].lastFingerPosPixels - Input.GetTouch(i).position; Vector2 posWorld = Camera.main.ScreenToWorldPoint((Vector3)Input.GetTouch(i).position + Vector3.forward * -Ref.cam.transform.position.z); Ref.inputController.TouchStayEmpty(posWorld, deltaPixel, fingerId); } if (Ref.mapView) { Vector2 v = this.touchesInfo[fingerId].lastFingerPosPixels - Input.GetTouch(i).position; summedPositionDelta += v; dragingFingerCount++; } } }
// Construct a translation matrix public static Mat4D Translation(Double3 delta) { return(new Mat4D(1.0f) { Data = { [3] = delta.X, [7] = delta.Y, [11] = delta.Z } }); }
/// <summary> /// 判断是否在相同的平面 /// </summary> /// <param name="line1"></param> /// <param name="line2"></param> /// <returns></returns> public static bool CheckInSamePlane(Line3D line1, Line3D line2) { if (line1 == null || line2 == null) { return(false); } // 判断是否共面 Double3 diff = line2.StartPoint - line1.StartPoint; Double3 VerticalAxis = Line3D.GetVerticalAxis(line1, line2); return(Double3.Dot(diff, VerticalAxis) == 0 ? true : false); }
public VesselSave(Vessel.State state, string adress, Double3 globalPosition, Double3 globalVelocity, float rotation, float angularVelocity, Vessel.Throttle throttle, Part.Save[] parts, Part.Joint.Save[] joints, List <string> vesselArchivments) { this.globalPosition = globalPosition; this.globalVelocity = globalVelocity; this.rotation = rotation; this.angularVelocity = angularVelocity; this.adress = adress; this.state = state; this.throttle = throttle; this.parts = parts; this.joints = joints; this.vesselArchivments = vesselArchivments; }
/// <summary> /// 判断点是否在直线上 /// </summary> /// <param name="pt"></param> /// <returns></returns> public virtual bool CheckIn(Double3 pt) { Double3 aixsVector = this.AixsVector(pt); if (aixsVector == Double3.zero) { return(true); } else { return(false); } }
/// <summary> /// 判断点是否在直线上 /// </summary> /// <param name="pt"></param> /// <returns></returns> public virtual bool CheckIn(Double3 pt) { Double3 diff = pt - this.Pt; if (Double3.Dot(diff, this.NormalizedNormal) == 0) { return(true); } else { return(false); } }
private static void CalculateClosestApproach(LineRenderer closestApproachLine, Orbit orbit, CelestialBodyData targetPlanet, ref bool drawn) { List <double> list = new List <double>(); if (orbit.periapsis < targetPlanet.orbitData.orbitHeightM && orbit.apoapsis > targetPlanet.orbitData.orbitHeightM) { double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(targetPlanet.orbitData.orbitHeightM, orbit.semiLatusRectum, orbit.eccentricity); list.Add(trueAnomalyAtRadius); list.Add(-trueAnomalyAtRadius); } else { if (!orbit.CanPasSOI(targetPlanet.orbitData.orbitHeightM, targetPlanet.mapData.showClosestApproachDistance)) { return; } if (orbit.apoapsis < targetPlanet.orbitData.orbitHeightM) { list.Add(3.1415927410125732); } else { list.Add(0.0); } } double num = double.PositiveInfinity; Double3 posA = Double3.zero; Double3 posB = Double3.zero; for (int i = 0; i < list.Count; i++) { double nextTrueAnomalyPassageTime = orbit.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]); if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime) { Double3 position = Kepler.GetPosition(Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, list[i]), list[i], orbit.argumentOfPeriapsis); Double3 posOut = targetPlanet.GetPosOut(nextTrueAnomalyPassageTime); double sqrMagnitude2d = (position - posOut).sqrMagnitude2d; if (sqrMagnitude2d <= num) { num = sqrMagnitude2d; posA = position; posB = posOut; } } } if (list.Count > 0) { ClosestApproach.SetLine(closestApproachLine, posA, posB, Ref.map.mapRefs[targetPlanet.parentBody].holder); drawn = true; } }
/// <summary> /// 中间经过的顶点,不包含2端的点。 /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="offset"></param> /// <param name="isPathDir"></param> /// <param name="paths"></param> private void RayboundingNearestPath(Double3 p1, Double3 p2, double offset, bool isPathDir, ref List <Double2> paths) { List <Double2> listpath = new List <Double2>(); // 先计算逆时针距离。 if (p1.z < p2.z) { if (isPathDir == true) { for (int i = (int)p1.z + 1; i <= (int)p2.z; i++) { listpath.Add(GetOutPoint(i, offset)); } } else { for (int i = (int)p1.z; i >= 0; i--) { listpath.Add(GetOutPoint(i, offset)); } // for (int i = this.pointArr.Length - 1; i > (int)p2.z; i--) { listpath.Add(GetOutPoint(i, offset)); } } } else if (p1.z > p2.z) { if (isPathDir == false) { for (int i = (int)p1.z; i >= (int)p2.z + 1; i--) { listpath.Add(GetOutPoint(i, offset)); } } else { for (int i = (int)p1.z + 1; i < this.pointArr.Length; i++) { listpath.Add(GetOutPoint(i, offset)); } for (int i = 0; i <= (int)p2.z; i++) { listpath.Add(GetOutPoint(i, offset)); } } } paths = listpath; }
private void LateUpdate() { if (Input.mouseScrollDelta.y != 0f) { this.ApplyZoom(1f - Input.mouseScrollDelta.y / 10f); } this.horizontalAxis = Input.GetAxisRaw("Horizontal"); Vector2 posWorld = base.PixelPosToWorldPos(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { this.StartTouchEmpty(posWorld, 0); this.oldPos = Input.mousePosition; } if ((Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)) && !this.ClickUI(Input.mousePosition)) { this.EndTouchEmpty(posWorld, 0, true); } if (Input.GetKey("q")) { this.ApplyZoom(1.015f); } if (Input.GetMouseButton(0)) { this.TouchStayEmpty(posWorld, this.oldPos - Input.mousePosition, 0); if (Ref.mapView && !Input.GetMouseButtonDown(0)) { this.ApplyDraging(Double3.ToDouble3(this.oldPos - Input.mousePosition)); } this.oldPos = Input.mousePosition; } float num = (float)((Screen.height <= Screen.width) ? 1334 : 750); if (this.canvasScaler.referenceResolution.x != num) { if (Ref.currentScene == Ref.SceneType.MainMenu) { return; } this.canvasScaler.referenceResolution = new Vector2(num, 1f); if (Ref.currentScene == Ref.SceneType.Game && this.recoverMenuHolder.activeSelf) { Ref.controller.StartRecovery(); } if (Ref.saving != null && Ref.saving.loadingMenuHolder.activeSelf) { Ref.saving.TryStartLoadProcess(); } } }
private void PositionPlanets(Double3 offset) { this.mapRefs[Ref.solarSystemRoot].holder.position = -offset.toVector3; foreach (CelestialBodyData celestialBodyData in Ref.solarSystemRoot.satellites) { this.mapRefs[celestialBodyData].holder.position = (celestialBodyData.GetPosOut(Ref.controller.globalTime) / 10000.0 - offset).toVector3; this.mapRefs[celestialBodyData].orbitLine.transform.localEulerAngles = new Vector3(0f, 0f, (float)(Ref.controller.globalTime * celestialBodyData.orbitData._meanMotion) * 57.29578f); foreach (CelestialBodyData celestialBodyData2 in celestialBodyData.satellites) { this.mapRefs[celestialBodyData2].holder.localPosition = (celestialBodyData2.GetPosOut(Ref.controller.globalTime) / 10000.0).toVector3; this.mapRefs[celestialBodyData2].orbitLine.transform.localEulerAngles = new Vector3(0f, 0f, (float)(Ref.controller.globalTime * celestialBodyData2.orbitData._meanMotion) * 57.29578f); } } }
public List <PathNode> FindPath(Double3 beginPoint, Double3 targetPoint) { Int3 beginBlock = world.GetGound(beginPoint); Int3 targetBlock = world.GetGound(targetPoint); var startNode = new PathNode(beginBlock, 0, beginBlock.Distance(targetBlock), MoveActions.Walk); openList = new List <PathNode> { startNode }; closedList = new List <Int3>(); startNode.GCost = 0; startNode.HCost = CalculateDistanceCost(startNode.Position, targetBlock); while (openList.Count > 0 && Discoverd.Count < maxNodes) { PathNode currentNode = GetLowestFCostNode(openList); if (currentNode.Position == targetBlock) { // Reached final node return(CalculatePath(currentNode)); } openList.Remove(currentNode); closedList.Add(currentNode.Position); foreach (PathNode neighbourNode in GetNeighbourList(currentNode)) { if (closedList.Contains(neighbourNode.Position)) { continue; } int tententiveGCos = currentNode.GCost + CalculateDistanceCost(currentNode.Position, neighbourNode.Position); if (tententiveGCos < neighbourNode.GCost && tententiveGCos < maxEstimatePath) { neighbourNode.cameFromNode = currentNode; neighbourNode.GCost = tententiveGCos; neighbourNode.HCost = CalculateDistanceCost(neighbourNode.Position, targetBlock); neighbourNode.CalculateFCost(); if (!openList.Contains(neighbourNode)) { openList.Add(neighbourNode); } } } } return(null); }
private void SelectionRequested(SelectionFrustum obj) { if (_pos == null) { return; } // The user has interactively edited the constrained sections -> propagate the information to the simulation core List <int> indices = new List <int>(); List <Double3> pos = _pos.GetList(); Double4x4 trafo = _gl.SceneGraph.AbsoluteTransformation; //trafo.Invert(); Double3 center = Double3.Zero; for (int i = 0; i < pos.Count; ++i) { double d; if (obj.IsPointInside(trafo.TransformPoint(pos[i]), out d)) { indices.Add(i); center += pos[i]; } } if (indices.Count > 0) { center /= indices.Count; SceneNode n = new SceneNode(); n.RelativeTranslation = center; CoordinateSystemSceneNode cs = new CoordinateSystemSceneNode(); //cs.RelativeTranslation = center; cs.Call <SceneNode>(m => m.Overlay = true); n.Add(cs); _gl.SceneGraph.Add(n); _sim.AddConstraint(new ConstrainedSection(cs, indices)); _sim.UpdateConstraintConfiguration(); } }
private void SwitchFollowingBody(CelestialBodyData newFollow) { Double3 a = Double3.zero; if (newFollow.parentBody == this.following) { a = -newFollow.GetPosOut(Ref.controller.globalTime); } if (this.following.parentBody == newFollow) { a = this.following.GetPosOut(Ref.controller.globalTime); } this.mapPosition += a / 10000.0; this.following = newFollow; }
public int WritePositions(double[] buffer, double[] undeformedPositions, int indexer) { for (int i = 0; i < _indices.Count; ++i) { int j = 3 * _indices[i]; Double3 p = Transformation.TransformPoint(new Double3(undeformedPositions[j], undeformedPositions[j + 1], undeformedPositions[j + 2])); buffer[indexer++] = p.X; buffer[indexer++] = p.Y; buffer[indexer++] = p.Z; //buffer[indexer++] = undeformedPositions[j]; //buffer[indexer++] = undeformedPositions[j + 1]; //buffer[indexer++] = undeformedPositions[j + 2]; } return(indexer); }
void Update() { time += Time.deltaTime; if (time >= BROADCAST_INTERVAL) { time = 0; var rotation = new Float3(rootTransform.eulerAngles); var bodyRotation = new Float3(bodyTransform.eulerAngles); Double3 uPosition = new Double3(GameMain.mainPlayer.uPosition.x, GameMain.mainPlayer.uPosition.y, GameMain.mainPlayer.uPosition.z); LocalPlayer.SendPacket(new PlayerMovement(LocalPlayer.PlayerId, GameMain.localPlanet?.id ?? -1, rootTransform.position.ToNebula(), uPosition, rotation, bodyRotation)); } }
public static void LoadForLaunch(GameSaving.GameSave loadedData, Double3 launchPadPosition) { for (int i = 0; i < loadedData.vessels.Count; i++) { if (loadedData.vessels[i].adress == Ref.controller.startAdress && Math.Abs(loadedData.vessels[i].globalPosition.x - launchPadPosition.x) < 10.0 && Math.Abs(loadedData.vessels[i].globalPosition.y - launchPadPosition.y) < 40.0) { loadedData.vessels.RemoveAt(i); i--; } else { Vessel.State state = loadedData.vessels[i].state; if (state != Vessel.State.RealTime) { if (state != Vessel.State.OnRails) { if (state == Vessel.State.Stationary) { loadedData.vessels[i].state = Vessel.State.StationaryUnloaded; } } else { loadedData.vessels[i].state = Vessel.State.OnRailsUnloaded; } } else if ((loadedData.vessels[i].globalPosition - launchPadPosition).magnitude2d > 1000.0 || loadedData.vessels[i].adress != Ref.controller.startAdress) { loadedData.vessels[i].state = ((Math.Abs(loadedData.vessels[i].globalVelocity.x) <= 1.0 && Math.Abs(loadedData.vessels[i].globalVelocity.y) <= 1.0) ? Vessel.State.StationaryUnloaded : Vessel.State.OnRailsUnloaded); } } } Ref.planetManager.SwitchLocation(Ref.GetPlanetByName(Ref.controller.startAdress), launchPadPosition, false, true, 0.0); Ref.planetManager.UpdatePositionOffset(new Double3(0.0, 315000.0)); Ref.velocityOffset = Double3.zero; Ref.controller.globalTime = loadedData.globalTime; Ref.controller.timewarpPhase = 0; Ref.timeWarping = false; foreach (GameSaving.VesselSave vesselToLoad in loadedData.vessels) { GameSaving.LoadVessel(vesselToLoad); } Ref.map.following = new OrbitLines.Target(Ref.GetPlanetByName(Ref.controller.startAdress)); Ref.map.UpdateMapPosition(new Double3(0.0, launchPadPosition.y / 10000.0)); Ref.map.UpdateMapZoom(launchPadPosition.y / 10000.0 / 20.0); Ref.planetManager.UpdateAtmosphereFade(); Ref.controller.warpedTimeCounterUI.text = string.Empty; }
private void SwitchFollowingBody(CelestialBodyData newFollow) { Double3 @double = Double3.zero; if (newFollow.parentBody == this.following.targetPlanet) { @double = -newFollow.GetPosOut(Ref.controller.globalTime); } if (this.following.targetPlanet.parentBody == newFollow) { @double = this.following.targetPlanet.GetPosOut(Ref.controller.globalTime); } MonoBehaviour.print(@double); this.mapPosition += @double / 10000.0; this.following = new OrbitLines.Target(newFollow); }
private List <Orbit> GetVesselOrbits(Vessel vessel) { if (vessel == null) { return(new List <Orbit>()); } if (vessel.state == Vessel.State.RealTime) { Double3 velIn = Ref.velocityOffset + vessel.partsManager.rb2d.velocity; if (velIn.sqrMagnitude2d > 4.0) { return(Orbit.CalculateOrbits(vessel.GetGlobalPosition, velIn, Ref.controller.loadedPlanet)); } } return(vessel.orbits); }
private List <Orbit> UpdateRealtimeVesselOrbitLines(Vessel vessel) { if (vessel == null || vessel.partsManager.rb2d == null) { return(new List <Orbit>()); } Double3 velIn = Ref.velocityOffset + vessel.partsManager.rb2d.velocity; if (velIn.sqrMagnitude2d > 2.0) { List <Orbit> list = Orbit.CalculateOrbits(vessel.GetGlobalPosition, velIn, Ref.controller.loadedPlanet); this.UpdateVesselOrbitLines(list, false); return(list); } return(new List <Orbit>()); }
public void UpdatePositionOffset(Double3 newPlanetOffset) { if (newPlanetOffset.x == Ref.positionOffset.x && newPlanetOffset.y == Ref.positionOffset.y) { return; } Ref.positionOffset = newPlanetOffset; Double3 a = new Double3(-450.0, Ref.controller.loadedPlanet.radius + 28.0); this.launchPad.transform.position = (a - Ref.positionOffset).toVector3; base.transform.position = -Ref.positionOffset.toVector3; for (int i = 0; i < this.colliderChuncks.Count; i++) { this.colliderChuncks[i].chunckTransform.position = -Ref.positionOffset.toVector3 - this.colliderChuncks[i].chunckPosOffset; } }
public static float PerlinNoise2D(int x, int y, float width, float height, float scale = 1, ulong?seed = null) { if (seed == null) { seed = GenerateTimeSeed(); } Double3 offset = GenerateOffsets(seed.Value); float perlinX = (float)(x / width * scale + offset.x); float perlinY = (float)(y / height * scale + offset.y); float point = Mathf.PerlinNoise(perlinX, perlinY); return(point); }
public GameSave(string saveName, int mainVesselId, int selectedVesselId, List <GameSaving.VesselSave> vessels, Double3 positionOffset, Double3 velocityOffset, double globalTime, int timeWarpPhase, double startedTimewapTime, float camDistance, bool mapView, Double3 mapPosition, string mapFollowingAdress) { this.saveName = saveName; this.globalTime = globalTime; this.timeWarpPhase = timeWarpPhase; this.startedTimewapTime = startedTimewapTime; this.camDistance = camDistance; this.mapView = mapView; this.mapPosition = mapPosition; this.mapFollowingAdress = mapFollowingAdress; this.mainVesselId = mainVesselId; this.selectedVesselId = selectedVesselId; this.vessels = vessels; this.positionOffset = positionOffset; this.velocityOffset = velocityOffset; }
private static void SetLine(LineRenderer closestApproachLine, Double3 posA, Double3 posB, Transform markerParent) { closestApproachLine.SetPositions(new Vector3[] { (posA / 10000.0).toVector3, (posB / 10000.0).toVector3 }); Double3 @double = (posA - posB) / 10000.0; closestApproachLine.sharedMaterial.mainTextureScale = new Vector2(Mathf.Max(1.6f, (float)(@double.magnitude2d / -(float)Ref.map.mapPosition.z * 80.0) + 0.6f), 1f); if (closestApproachLine.transform.parent != markerParent) { closestApproachLine.transform.parent = markerParent; closestApproachLine.transform.localPosition = Vector3.zero; } }
public static List <Orbit> CalculateOrbits(List <Orbit> orbitsIn) { while (orbitsIn.Count < 3) { Orbit orbit = orbitsIn[orbitsIn.Count - 1]; if (orbit.orbitType == Orbit.Type.Escape) { if (orbitsIn.Count >= 2 && orbitsIn[orbitsIn.Count - 2].orbitType == Orbit.Type.Encounter) { return(orbitsIn); } Double3 position = Kepler.GetPosition(orbit.planet.orbitData.SOI, orbit.endTrueAnomaly, orbit.argumentOfPeriapsis); Double3 velocity = Kepler.GetVelocity(orbit.semiMajorAxis, orbit.planet.orbitData.SOI, orbit.meanMotion, Kepler.GetEccentricAnomalyFromTrueAnomaly(orbit.endTrueAnomaly, orbit.eccentricity), orbit.endTrueAnomaly, orbit.eccentricity, orbit.argumentOfPeriapsis); Double3 posIn = position + orbit.planet.GetPosOut(orbit.orbitEndTime); Double3 velIn = velocity + orbit.planet.GetVelOut(orbit.orbitEndTime); if (double.IsNaN(posIn.x * velIn.y - posIn.y * velIn.x)) { return(orbitsIn); } orbitsIn.Add(new Orbit(posIn, velIn, orbit.orbitEndTime, orbit.nextPlanet, orbit.planet)); } else { if (orbit.orbitType != Orbit.Type.Encounter) { return(orbitsIn); } if (orbitsIn.Count >= 2 && orbitsIn[orbitsIn.Count - 2].planet == orbit.nextPlanet) { return(orbitsIn); } double eccentricAnomalyFromTrueAnomaly = Kepler.GetEccentricAnomalyFromTrueAnomaly(orbit.endTrueAnomaly, orbit.eccentricity); double radius = Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, orbit.endTrueAnomaly); Double3 position2 = Kepler.GetPosition(radius, orbit.endTrueAnomaly, orbit.argumentOfPeriapsis); Double3 velocity2 = Kepler.GetVelocity(orbit.semiMajorAxis, radius, orbit.meanMotion, eccentricAnomalyFromTrueAnomaly, orbit.endTrueAnomaly, orbit.eccentricity, orbit.argumentOfPeriapsis); Double3 posIn2 = position2 - orbit.nextPlanet.GetPosOut(orbit.orbitEndTime); Double3 velIn2 = velocity2 - orbit.nextPlanet.GetVelOut(orbit.orbitEndTime); if (double.IsNaN(posIn2.x * velIn2.y - posIn2.y * velIn2.x)) { return(orbitsIn); } orbitsIn.Add(new Orbit(posIn2, velIn2, orbit.orbitEndTime, orbit.nextPlanet, null)); } } return(orbitsIn); }
public static double GetClosestPointOnLine(Double3 p2, Double3 p3) { double num = p2.x; double num2 = p2.y; double num3 = num * num + num2 * num2; double num4 = (p3.x * num + p3.y * num2) / num3; if (num4 < 0.0) { return(0.0); } if (num4 > 1.0) { return(1.0); } return(num4); }
private void UpdateDynamicVariables(double newTime) { if (this.lastCalculationTime != newTime) { this.lastCalculationTime = newTime; double eccentricAnomaly = Kepler.GetEccentricAnomaly((newTime - this.periapsisPassageTime) * this.meanMotion, this.eccentricity); if (double.IsNaN(eccentricAnomaly)) { return; } this.eccentricAnomnalyOut = eccentricAnomaly; this.trueAnomalyOut = Kepler.GetTrueAnomaly(this.eccentricAnomnalyOut, this.eccentricity); double radius = Kepler.GetRadius(this.semiLatusRectum, this.eccentricity, this.trueAnomalyOut); this.posOut = Kepler.GetPosition(radius, this.trueAnomalyOut, this.argumentOfPeriapsis); this.velOut = Kepler.GetVelocity(this.semiMajorAxis, radius, this.meanMotion, this.eccentricAnomnalyOut, this.trueAnomalyOut, this.eccentricity, this.argumentOfPeriapsis); } }
public Chunck(double from, double size, int LODId, CelestialBodyData planet, CelestialBodyData.TerrainData.DetailLevel[] detailLevels, Transform parent, bool forMap, bool offset) { this.from = from; this.LODId = LODId; this.topSizeHalf = (double)detailLevels[LODId].angularSize / planet.terrainData.unitToAngle * 0.5; float num = (float)from / (float)planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * 360f + detailLevels[LODId].angularSize * 0.5f; this.topPosition = new Double3(Math.Cos((double)(num * 0.0174532924f)), Math.Sin((double)(num * 0.0174532924f))) * (planet.radius + planet.terrainData.maxTerrainHeight); this.chunckTransform = UnityEngine.Object.Instantiate <Transform>(Ref.planetManager.chunckPrefab).transform; this.chunckTransform.parent = parent; this.chunckTransform.localPosition = Vector3.zero; PlanetManager.TerrainPoints terrainPoints = planet.GetTerrainPoints(from, size, detailLevels[LODId].LOD, offset); this.GenerateMesh(this.chunckTransform, terrainPoints, this.GenerateIndices(terrainPoints.points.Length), from, 1f / (float)((double)planet.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * detailLevels[LODId].LOD), 1f / (float)detailLevels[LODId].LOD, "Default", 10, planet, forMap); if (offset) { this.chunckPosOffset = terrainPoints.points[0]; } }
public static Double3 Pow(Double3 v, double p) { return new Double3(System.Math.Pow(v.x, p), System.Math.Pow(v.y, p), System.Math.Pow(v.z, p)); }