public KopernicusOrbitRendererData(CelestialBody body, OrbitRenderer renderer) : base(body) #endif { orbitColor = renderer.orbitColor; nodeColor = renderer.nodeColor; lowerCamVsSmaRatio = renderer.lowerCamVsSmaRatio; upperCamVsSmaRatio = renderer.upperCamVsSmaRatio; }
void UpdateOrbitalPosition() { CurrentPositionAngle += ((20 - OrbitHeight) / 2f) * Time.deltaTime * dir; transform.position = OrbitRenderer.GetPoint(OrbitHeight, CurrentPositionAngle); int mod = dir > 0 ? -1 : 1; transform.up = mod * new Vector3(transform.position.y, -1 * transform.position.x, 0).normalized; //sprite.transform.rotation = (transform.position - GameManager.Instance.Planet.transform.position) }
private void Awake() { _orbitRenderer = GetComponent <OrbitRenderer>(); _lineRenderer = GetComponent <LineRenderer>(); _spaceCameraMovement = _spaceCamera.GetComponent <CameraMovement>(); _spaceCameraRange = _spaceCamera.GetComponent <CameraRange>(); _spaceCameraMovement.Moved.AddListener(new UnityAction(ChangeWidth)); }
public void init(OrbitRenderer orbitRenderer, string name, Color color) { var renderGameObject = new GameObject(name + " Orbit Renderer"); renderGameObject.transform.parent = orbitRenderer.sceneCelestial.transform; renderGameObject.transform.localPosition = Vector3.zero; this.orbitRenderer = orbitRenderer; lineRenderer = renderGameObject.AddComponent <LineRenderer>(); lineRenderer.SetColors(color, color); Shown = false; }
void Start() { GameManager.OnGameOver += onGameOver; path = OrbitRenderer.GetPoints(OrbitHeight, pathPrecision); TaskWeights.Add(ShipTask.Scanning, 0.5f); TaskWeights.Add(ShipTask.Repairs, 0f); TaskWeights.Add(ShipTask.Fighting, 0f); TaskWeights.Add(ShipTask.Resting, 0f); CurrentPositionAngle = OrbitInsertionAngle; OrbitInsertionPoint = OrbitRenderer.GetPoint(OrbitHeight, OrbitInsertionAngle); dir = Random.Range(0f, 1f) < 0.5f ? 1 : -1; //if (dir > 0) gameObject.transform.localScale = new Vector3(1, -1, 1); sprite.color = new Color(sprite.color.r, sprite.color.g, sprite.color.b, 0f); minDelta = Random.Range(0.2f, 0.8f); }
public override void OnInspectorGUI() { GUI.changed = false; OrbitRenderer orbitRenderer = (OrbitRenderer)target; int numPoints = 100; numPoints = EditorGUILayout.IntField(new GUIContent("Number of Points", nTip), (int)orbitRenderer.numPoints); // If there has been a change in the orbit parameters, then need to recalculate the positions and // assign them to the Line Renderer if (GUI.changed) { Undo.RecordObject(orbitRenderer, "OrbitRenderer Change"); orbitRenderer.numPoints = numPoints; EditorUtility.SetDirty(orbitRenderer); } }
// Back out of orbital predictions. private void hideExitOrbit(OrbitRenderer showOrbit) { showOrbit.drawMode = OrbitRenderer.DrawMode.OFF; showOrbit.driver.drawOrbit = false; showOrbit.drawIcons = OrbitRenderer.DrawIcons.NONE; oDirection.enabled = false; foreach (MapObject mobj in MapView.MapCamera.targets) { if (mobj.vessel == null) { continue; } if (mobj.vessel.GetInstanceID() == FlightGlobals.ActiveVessel.GetInstanceID()) { MapView.MapCamera.SetTarget(mobj); } } if (MapView.MapIsEnabled && !wasInMapView) { MapView.ExitMapView(); } }
// Back out of orbital predictions. private void hideExitOrbit(OrbitRenderer showOrbit) { showOrbit.drawMode = OrbitRenderer.DrawMode.OFF; showOrbit.driver.drawOrbit = false; showOrbit.drawIcons = OrbitRenderer.DrawIcons.NONE; oDirection.enabled = false; foreach (MapObject mobj in MapView.MapCamera.targets) { if (mobj.vessel == null) continue; if (mobj.vessel.GetInstanceID() == FlightGlobals.ActiveVessel.GetInstanceID()) { MapView.MapCamera.SetTarget(mobj); } } if (MapView.MapIsEnabled && !wasInMapView) MapView.ExitMapView(); }
/// <summary> /// [HACK] Spawn a new body from the PSystem-Prefab /// </summary> public static void Instantiate(PSystemBody template, string name) { // Fix Templates if (template == null) { ScreenMessages.PostScreenMessage("You need a valid Template!", 3f, ScreenMessageStyle.UPPER_CENTER); return; } // Spawn Message ScreenMessages.PostScreenMessage("Created new Planet " + name + ", based on " + template.name + "!", 5f, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage("This tool is meant to be used by modders, it can break mods!", 5f, ScreenMessageStyle.UPPER_CENTER); // Clone the Template GameObject bodyObject = UnityEngine.Object.Instantiate(template.gameObject); PSystemBody body = bodyObject.GetComponent <PSystemBody>(); // Alter it's name and flight-Number body.name = name; body.celestialBody.bodyName = name; body.celestialBody.transform.name = name; body.celestialBody.bodyTransform.name = name; body.scaledVersion.name = name; if (body.pqsVersion != null) { body.pqsVersion.name = name; body.pqsVersion.gameObject.name = name; body.pqsVersion.transform.name = name; foreach (PQS p in body.pqsVersion.GetComponentsInChildren(typeof(PQS), true)) { p.name = p.name.Replace(template.celestialBody.bodyName, name); } } body.flightGlobalsIndex = PSystemManager.Instance.localBodies.Last().flightGlobalsIndex + 1; // Change it's Orbit body.orbitDriver.orbit = Orbit.CreateRandomOrbitAround(PSystemManager.Instance.localBodies.First(), 4000000000, 60000000000); body.orbitDriver.referenceBody = PSystemManager.Instance.localBodies.First(); body.orbitDriver.orbit.referenceBody = body.orbitDriver.referenceBody; body.orbitRenderer.lowerCamVsSmaRatio = template.orbitRenderer.lowerCamVsSmaRatio; body.orbitRenderer.upperCamVsSmaRatio = template.orbitRenderer.upperCamVsSmaRatio; // Clear it's childs body.children = new List <PSystemBody>(); // Add it to the System-Prefab body.transform.parent = PSystemManager.Instance.systemPrefab.transform; PSystemManager.Instance.systemPrefab.rootBody.children.Add(body); // Hack^6 - Hack the PSystemManager to spawn this thing MethodInfo spawnBody = typeof(PSystemManager).GetMethod("SpawnBody", BindingFlags.NonPublic | BindingFlags.Instance); spawnBody.Invoke(PSystemManager.Instance, new object[] { PSystemManager.Instance.localBodies.First(), body }); CelestialBody cBody = PSystemManager.Instance.localBodies.Last(); // Add the body to FlightGlobals.Bodies FlightGlobals.fetch.bodies.Add(cBody); // Start the CelestialBody typeof(CelestialBody).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(cBody, null); // Start the OrbitDriver if (cBody.orbitDriver != null) { typeof(OrbitDriver).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(cBody.orbitDriver, null); } // Fix and start the OrbitRenderer if (Resources.FindObjectsOfTypeAll <OrbitRenderer>().Count(r => r.name == cBody.name) == 1) { OrbitRenderer renderer = Resources.FindObjectsOfTypeAll <OrbitRenderer>().First(r => r.name == cBody.name); renderer.driver = cBody.orbitDriver; renderer.celestialBody = cBody; typeof(OrbitRenderer).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(renderer, null); } // Force the start of the PQS-Spheres foreach (PQS p in cBody.GetComponentsInChildren <PQS>(true)) { p.ForceStart(); } // Fix the ScaledVersion if (cBody.scaledBody.GetComponents <ScaledSpaceFader>().Length == 1) { cBody.scaledBody.GetComponent <ScaledSpaceFader>().celestialBody = cBody; } if (cBody.scaledBody.GetComponents <AtmosphereFromGround>().Length == 1) { cBody.scaledBody.GetComponent <AtmosphereFromGround>().planet = cBody; } }
public void GenerateShip() { ShipCount++; int type = Random.Range(0, 4); float angle = (float)Random.Range(0, 359); float radius = (float)Random.Range(8, 15); GameObject newShip = Instantiate(ShipPrefab, GameRoot.transform); newShip.name = RandomName(); ShipController newShipController = newShip.GetComponent <ShipController>(); newShipController.OrbitHeight = radius; newShipController.ShipName = newShip.name; newShip.transform.position = OrbitRenderer.GetPoint(radius, angle).normalized * 50f; newShipController.OrbitInsertionAngle = angle; newShipController.ShipType = type; switch (type) { case 0: newShip.GetComponentInChildren <SpriteRenderer>().color = ScienceShipColor; Debug.Log("Ship" + type + " " + newShip.GetComponentInChildren <SpriteRenderer>().color); newShipController.IntelMod = 1.5f; newShipController.FightMod = 0.5f; newShipController.ShipType = type; break; case 1: newShip.GetComponentInChildren <SpriteRenderer>().color = EngineerColor; Debug.Log("Ship" + type + " " + newShip.GetComponentInChildren <SpriteRenderer>().color); newShipController.RepairMod = 1.5f; newShipController.DespairMod = 0.5f; newShipController.ShipType = type; break; case 2: newShip.GetComponentInChildren <SpriteRenderer>().color = MilitaryColor; Debug.Log("Ship" + type + " " + newShip.GetComponentInChildren <SpriteRenderer>().color); newShipController.FightMod = 1.5f; newShipController.DespairMod = 0.5f; newShipController.ShipType = type; break; case 3: newShip.GetComponentInChildren <SpriteRenderer>().color = PassengerColor; Debug.Log("Ship" + type + " " + newShip.GetComponentInChildren <SpriteRenderer>().color); newShipController.FightMod = 0.5f; newShipController.DespairMod = 1.5f; newShipController.ShipType = type; break; } GameObject newOverlay = Instantiate(OverlayPrefab, OverlayParent.transform); newOverlay.GetComponent <ShipUIOverlay>().LinkedShip = newShipController; newOverlay.name = newShipController.ShipName + "_overlay"; newShipController.SetOverlay(newOverlay); newShipController.timerCircle = newOverlay.GetComponent <ShipUIOverlay>().TimerMask.gameObject; }
private void setup() { generator = new System.Random(this.Root.MissionSeed); iconWaypoints = new List <Waypoint>(); for (int cardinals = 0; cardinals < 4; cardinals++) { bool addedWaypoint = false; switch (cardinals) { case 0: if (HighLogic.LoadedSceneIsFlight) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.ASCENDINGNODE; addedWaypoint = true; } break; case 1: if (HighLogic.LoadedSceneIsFlight) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.DESCENDINGNODE; addedWaypoint = true; } break; case 2: iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.APOAPSIS; addedWaypoint = true; break; case 3: iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.PERIAPSIS; addedWaypoint = true; break; } if (addedWaypoint) { iconWaypoints[iconWaypoints.Count - 1].celestialName = targetBody.GetName(); iconWaypoints[iconWaypoints.Count - 1].isOnSurface = false; iconWaypoints[iconWaypoints.Count - 1].isNavigatable = false; iconWaypoints[iconWaypoints.Count - 1].seed = Root.MissionSeed; WaypointManager.AddWaypoint(iconWaypoints[iconWaypoints.Count - 1]); } } for (int x = 0; x < numSpinners; x++) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].celestialName = targetBody.GetName(); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.ORBITAL; iconWaypoints[iconWaypoints.Count - 1].isOnSurface = false; iconWaypoints[iconWaypoints.Count - 1].isNavigatable = false; iconWaypoints[iconWaypoints.Count - 1].seed = Root.MissionSeed; WaypointManager.AddWaypoint(iconWaypoints[iconWaypoints.Count - 1]); } orbitDriver = new OrbitDriver(); orbitDriver.orbit = new Orbit(); orbitDriver.orbit.referenceBody = targetBody; orbitDriver.orbit.semiMajorAxis = sma; orbitDriver.orbit.eccentricity = eccentricity; orbitDriver.orbit.argumentOfPeriapsis = argumentOfPeriapsis; orbitDriver.orbit.inclination = inclination; orbitDriver.orbit.LAN = lan; orbitDriver.orbit.meanAnomalyAtEpoch = meanAnomalyAtEpoch; orbitDriver.orbit.epoch = epoch; orbitDriver.orbit.Init(); //The orbit needs to be post processed in an appropriate scene, or it will be useless. Util.PostProcessOrbit(ref orbitDriver.orbit); orbitDriver.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); orbitRenderer = MapView.MapCamera.gameObject.AddComponent <OrbitRenderer>(); orbitRenderer.driver = orbitDriver; orbitRenderer.drawIcons = OrbitRenderer.DrawIcons.NONE; orbitRenderer.drawNodes = false; orbitRenderer.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); setVisible(true); orbitRenderer.celestialBody = targetBody; beenSetup = true; }
// Use this for initialization void Start() { orbitRenderer = gameObject.AddComponent <OrbitRenderer>(); orbitRenderer.Init(this); orbitRenderer.showOrbit(); }
private void setup() { generator = new System.Random(this.Root.MissionSeed); iconWaypoints = new List<Waypoint>(); for (int cardinals = 0; cardinals < 4; cardinals++) { bool addedWaypoint = false; switch (cardinals) { case 0: if (HighLogic.LoadedSceneIsFlight) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.ASCENDINGNODE; addedWaypoint = true; } break; case 1: if (HighLogic.LoadedSceneIsFlight) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.DESCENDINGNODE; addedWaypoint = true; } break; case 2: iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.APOAPSIS; addedWaypoint = true; break; case 3: iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.PERIAPSIS; addedWaypoint = true; break; } if (addedWaypoint) { iconWaypoints[iconWaypoints.Count - 1].celestialName = targetBody.GetName(); iconWaypoints[iconWaypoints.Count - 1].isOnSurface = false; iconWaypoints[iconWaypoints.Count - 1].isNavigatable = false; iconWaypoints[iconWaypoints.Count - 1].seed = Root.MissionSeed; WaypointManager.AddWaypoint(iconWaypoints[iconWaypoints.Count - 1]); } } for (int x = 0; x < numSpinners; x++) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].celestialName = targetBody.GetName(); iconWaypoints[iconWaypoints.Count - 1].waypointType = WaypointType.ORBITAL; iconWaypoints[iconWaypoints.Count - 1].isOnSurface = false; iconWaypoints[iconWaypoints.Count - 1].isNavigatable = false; iconWaypoints[iconWaypoints.Count - 1].seed = Root.MissionSeed; WaypointManager.AddWaypoint(iconWaypoints[iconWaypoints.Count - 1]); } orbitDriver = new OrbitDriver(); orbitDriver.orbit = new Orbit(); orbitDriver.orbit.referenceBody = targetBody; orbitDriver.orbit.semiMajorAxis = sma; orbitDriver.orbit.eccentricity = eccentricity; orbitDriver.orbit.argumentOfPeriapsis = argumentOfPeriapsis; orbitDriver.orbit.inclination = inclination; orbitDriver.orbit.LAN = lan; orbitDriver.orbit.meanAnomalyAtEpoch = meanAnomalyAtEpoch; orbitDriver.orbit.epoch = epoch; orbitDriver.orbit.Init(); //The orbit needs to be post processed in an appropriate scene, or it will be useless. Util.PostProcessOrbit(ref orbitDriver.orbit); orbitDriver.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); orbitRenderer = MapView.MapCamera.gameObject.AddComponent<OrbitRenderer>(); orbitRenderer.driver = orbitDriver; orbitRenderer.drawIcons = OrbitRenderer.DrawIcons.NONE; orbitRenderer.drawNodes = false; orbitRenderer.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); setVisible(true); orbitRenderer.celestialBody = targetBody; beenSetup = true; }
private void setup() { generator = new System.Random(this.Root.MissionSeed); iconWaypoints = new List <Waypoint>(); for (int x = 0; x < 4; x++) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].celestialName = targetBody.GetName(); iconWaypoints[iconWaypoints.Count - 1].textureName = "orbit"; iconWaypoints[iconWaypoints.Count - 1].isOrbital = true; iconWaypoints[iconWaypoints.Count - 1].seed = Root.MissionSeed; WaypointManager.AddWaypoint(iconWaypoints[iconWaypoints.Count - 1]); } orbitDriver = new OrbitDriver(); //Start with periapsis at a safe distance and a random eccentricity, weighted towards the bottom. //Derive SMA from eccentricity and desired periapsis. orbitDriver.orbit = new Orbit(); switch (this.orbitType) { case OrbitType.POLAR: setRandomOrbit(difficultyFactor, false, true); break; case OrbitType.EQUATORIAL: setRandomOrbit(difficultyFactor, true, false); break; case OrbitType.STATIONARY: setSynchronousOrbit(difficultyFactor, true, 0.0); break; case OrbitType.SYNCHRONOUS: setSynchronousOrbit(difficultyFactor, false, generator.NextDouble() * (difficultyFactor / 2)); break; case OrbitType.MOLNIYA: setMolniyaOrbit(); break; case OrbitType.TUNDRA: setTundraOrbit(); break; default: setRandomOrbit(difficultyFactor, false, false); break; } orbitDriver.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); orbitRenderer = MapView.MapCamera.gameObject.AddComponent <OrbitRenderer>(); orbitRenderer.driver = orbitDriver; orbitRenderer.drawIcons = OrbitRenderer.DrawIcons.NONE; orbitRenderer.drawNodes = false; orbitRenderer.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); setVisible(true); orbitRenderer.celestialBody = targetBody; beenSetup = true; }
// Show exit orbital predictions private void showExitOrbit(Vessel near, Vessel far, string model) { float baseWidth = 20.0f; double baseStart = 10; double baseEnd = 50; // Recenter map, save previous state. wasInMapView = MapView.MapIsEnabled; if (!MapView.MapIsEnabled) { MapView.EnterMapView(); } print("Finding target."); MapObject farTarget = findVesselBody(far); if (farTarget != null) { MapView.MapCamera.SetTarget(farTarget); } Vector3 mapCamPos = ScaledSpace.ScaledToLocalSpace(MapView.MapCamera.transform.position); Vector3 farTarPos = ScaledSpace.ScaledToLocalSpace(farTarget.transform.position); float dirScalar = Vector3.Distance(mapCamPos, farTarPos); print("Initializing, camera distance is " + dirScalar); // Initialize projection stuff. print("Beginning orbital projection."); Vector3d exitTraj = getJumpOffset(near, far, model); oPredictDriver = new OrbitDriver(); oPredictDriver.orbit = new Orbit(); oPredictDriver.orbit.referenceBody = far.mainBody; oPredictDriver.referenceBody = far.mainBody; oPredictDriver.upperCamVsSmaRatio = 999999; // Took forever to figure this out - this sets at what zoom level the orbit appears. Was causing it not to appear at small bodies. oPredictDriver.lowerCamVsSmaRatio = 0.0001f; oPredictDriver.orbit.UpdateFromStateVectors(far.orbit.pos, exitTraj, far.mainBody, Planetarium.GetUniversalTime()); oPredictDriver.orbit.Init(); Vector3d p = oPredictDriver.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime()); Vector3d v = oPredictDriver.orbit.getOrbitalVelocityAtUT(Planetarium.GetUniversalTime()); oPredictDriver.orbit.h = Vector3d.Cross(p, v); oPredict = MapView.MapCamera.gameObject.AddComponent <OrbitRenderer>(); oPredict.upperCamVsSmaRatio = 999999; oPredict.lowerCamVsSmaRatio = 0.0001f; oPredict.celestialBody = far.mainBody; oPredict.driver = oPredictDriver; oPredictDriver.Renderer = oPredict; // Splash some color on it. print("Displaying orbital projection."); oPredict.driver.drawOrbit = true; oPredict.driver.orbitColor = Color.red; oPredict.orbitColor = Color.red; oPredict.drawIcons = OrbitRenderer.DrawIcons.OBJ_PE_AP; oPredict.drawMode = OrbitRenderer.DrawMode.REDRAW_AND_RECALCULATE; // Directional indicator. oDirObj = new GameObject("Indicator"); oDirObj.layer = 10; // Map layer! oDirection = oDirObj.AddComponent <LineRenderer>(); oDirection.useWorldSpace = false; oOrigin = null; foreach (Transform sstr in ScaledSpace.Instance.scaledSpaceTransforms) { if (sstr.name == far.mainBody.name) { oOrigin = sstr; print("Found origin: " + sstr.name); break; } } oDirection.transform.parent = oOrigin; oDirection.transform.position = ScaledSpace.LocalToScaledSpace(far.transform.position); oDirection.material = new Material(Shader.Find("Particles/Additive")); oDirection.SetColors(Color.clear, Color.red); if (dirScalar / 325000 > baseWidth) { baseWidth = dirScalar / 325000f; } oDirection.SetWidth(baseWidth, 0.01f); print("Base Width set to " + baseWidth); oDirection.SetVertexCount(2); if (dirScalar / 650000 > baseStart) { baseStart = dirScalar / 650000; } if (dirScalar / 130000 > baseEnd) { baseEnd = dirScalar / 130000; } print("Base Start set to " + baseStart); print("Base End set to " + baseEnd); oDirection.SetPosition(0, Vector3d.zero + exitTraj.xzy.normalized * baseStart); oDirection.SetPosition(1, exitTraj.xzy.normalized * baseEnd); oDirection.enabled = true; // */ }
// Show exit orbital predictions private void showExitOrbit(Vessel near, Vessel far, string model) { // Recenter map, save previous state. wasInMapView = MapView.MapIsEnabled; if (!MapView.MapIsEnabled) MapView.EnterMapView(); print("Finding target."); MapObject farTarget = findVesselBody(far); if (farTarget != null) MapView.MapCamera.SetTarget(farTarget); // Initialize projection stuff. print("Beginning orbital projection."); Vector3d exitTraj = getJumpOffset(near, far, model); oPredictDriver = new OrbitDriver(); oPredictDriver.orbit = new Orbit(); oPredictDriver.orbit.referenceBody = far.mainBody; oPredictDriver.referenceBody = far.mainBody; oPredictDriver.upperCamVsSmaRatio = 999999; // Took forever to figure this out - this sets at what zoom level the orbit appears. Was causing it not to appear at small bodies. oPredictDriver.lowerCamVsSmaRatio = 0.0001f; oPredictDriver.orbit.UpdateFromStateVectors(far.orbit.pos, exitTraj, far.mainBody, Planetarium.GetUniversalTime()); oPredictDriver.orbit.Init(); Vector3d p = oPredictDriver.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime()); Vector3d v = oPredictDriver.orbit.getOrbitalVelocityAtUT(Planetarium.GetUniversalTime()); oPredictDriver.orbit.h = Vector3d.Cross(p, v); oPredict = MapView.MapCamera.gameObject.AddComponent<OrbitRenderer>(); oPredict.upperCamVsSmaRatio = 999999; oPredict.lowerCamVsSmaRatio = 0.0001f; oPredict.celestialBody = far.mainBody; oPredict.driver = oPredictDriver; oPredictDriver.Renderer = oPredict; // Splash some color on it. print("Displaying orbital projection."); oPredict.driver.drawOrbit = true; oPredict.driver.orbitColor = Color.red; oPredict.orbitColor = Color.red; oPredict.drawIcons = OrbitRenderer.DrawIcons.OBJ_PE_AP; oPredict.drawMode = OrbitRenderer.DrawMode.REDRAW_AND_RECALCULATE; // Directional indicator. oDirObj = new GameObject("Indicator"); oDirObj.layer = 10; // Map layer! oDirection = oDirObj.AddComponent<LineRenderer>(); oDirection.useWorldSpace = false; oOrigin = null; foreach (Transform sstr in ScaledSpace.Instance.scaledSpaceTransforms) { if (sstr.name == far.mainBody.name) { oOrigin = sstr; print("Found origin: " + sstr.name); break; } } oDirection.transform.parent = oOrigin; oDirection.transform.position = ScaledSpace.LocalToScaledSpace(far.transform.position); oDirection.material = new Material(Shader.Find("Particles/Additive")); oDirection.SetColors(Color.clear, Color.red); oDirection.SetWidth(20.0f, 0.01f); oDirection.SetVertexCount(2); oDirection.SetPosition(0, Vector3d.zero + exitTraj.xzy.normalized * 10); oDirection.SetPosition(1, exitTraj.xzy.normalized * 50); oDirection.enabled = true; // */ }
// Show exit orbital predictions private void ShowExitOrbit(Vessel nearObject, Vessel farObject) { // Recenter map, save previous state. wasInMapView = MapView.MapIsEnabled; if (!MapView.MapIsEnabled) { MapView.EnterMapView(); } MapObject mapObject = FindVesselBody(farObject); if ((UnityEngine.Object)mapObject != (UnityEngine.Object)null) { MapView.MapCamera.SetTarget(mapObject); } Vector3 mapCamPos = ScaledSpace.ScaledToLocalSpace(MapView.MapCamera.transform.position); Vector3 farTarPos = ScaledSpace.ScaledToLocalSpace(mapObject.transform.position); float dirScalar = Vector3.Distance(mapCamPos, farTarPos); //log.Debug("Initializing, camera distance is " + dirScalar); if (!IsPatchedConicsAvailable) { HideExitOrbit(); } else { predictionsDrawn = true; Vector3d vel = ESLDBeacon.GetJumpVelOffset(nearObject, farObject); if (predictionGameObject != null) { Destroy(predictionGameObject); } predictionGameObject = new GameObject("OrbitRendererGameObject"); predictionOrbitDriver = predictionGameObject.AddComponent <OrbitDriver>(); predictionOrbitDriver.orbit.referenceBody = farObject.mainBody; predictionOrbitDriver.orbit = new Orbit(); predictionOrbitDriver.referenceBody = farObject.mainBody; predictionOrbitDriver.upperCamVsSmaRatio = 999999f; // Took forever to figure this out - this sets at what zoom level the orbit appears. Was causing it not to appear at small bodies. predictionOrbitDriver.lowerCamVsSmaRatio = 0.0001f; predictionOrbitDriver.orbit.UpdateFromStateVectors(farObject.orbit.pos, vel, farObject.mainBody, Planetarium.GetUniversalTime()); predictionOrbitDriver.orbit.Init(); Vector3d relativePositionAtUT = predictionOrbitDriver.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime()); Vector3d orbitalVelocityAtUT = predictionOrbitDriver.orbit.getOrbitalVelocityAtUT(Planetarium.GetUniversalTime()); predictionOrbitDriver.orbit.h = Vector3d.Cross(relativePositionAtUT, orbitalVelocityAtUT); predictionOrbitDriver.updateMode = OrbitDriver.UpdateMode.TRACK_Phys; predictionOrbitDriver.orbitColor = Color.red; predictionOrbitRenderer = predictionGameObject.AddComponent <OrbitRenderer>(); predictionOrbitRenderer.SetColor(Color.red); predictionOrbitRenderer.vessel = vessel; predictionOrbitDriver.vessel = vessel; predictionOrbitRenderer.upperCamVsSmaRatio = 999999f; predictionOrbitRenderer.lowerCamVsSmaRatio = 0.0001f; predictionOrbitRenderer.celestialBody = farObject.mainBody; predictionOrbitRenderer.driver = predictionOrbitDriver; predictionOrbitDriver.Renderer = predictionOrbitRenderer; if (true) { // This draws the full Patched Conics prediction. predictionPatchedConicSolver = predictionGameObject.AddComponent <PatchedConicSolver>(); predictionPatchedConicRenderer = predictionGameObject.AddComponent <PatchedConicRenderer>(); predictionOrbitRenderer.drawIcons = OrbitRendererBase.DrawIcons.NONE; predictionOrbitRenderer.drawMode = OrbitRendererBase.DrawMode.OFF; } #if false else { // This draws just the first patch, similar to a Level 1 tracking station. predictionOrbitRenderer.driver.drawOrbit = true; predictionOrbitRenderer.drawIcons = OrbitRenderer.DrawIcons.OBJ_PE_AP; predictionOrbitRenderer.drawMode = OrbitRenderer.DrawMode.REDRAW_AND_RECALCULATE; predictionOrbitRenderer.enabled = true; } #endif base.StartCoroutine(NullOrbitDriverVessels()); // Splash some color on it. // Directional indicator. /* * float baseWidth = 20.0f; * double baseStart = 10; * double baseEnd = 50; * oDirObj = new GameObject("Indicator"); * oDirObj.layer = 10; // Map layer! * oDirection = oDirObj.AddComponent<LineRenderer>(); * oDirection.useWorldSpace = false; * oOrigin = null; * foreach (Transform sstr in ScaledSpace.Instance.scaledSpaceTransforms) * { * if (sstr.name == far.mainBody.name) * { * oOrigin = sstr; * log.debug("Found origin: " + sstr.name); * break; * } * } * oDirection.transform.parent = oOrigin; * oDirection.transform.position = ScaledSpace.LocalToScaledSpace(far.transform.position); * oDirection.material = new Material(Shader.Find("Particles/Additive")); * oDirection.SetColors(Color.clear, Color.red); * if (dirScalar / 325000 > baseWidth) baseWidth = dirScalar / 325000f; * oDirection.SetWidth(baseWidth, 0.01f); * log.debug("Base Width set to " + baseWidth); * oDirection.SetVertexCount(2); * if (dirScalar / 650000 > baseStart) baseStart = dirScalar / 650000; * if (dirScalar / 130000 > baseEnd) baseEnd = dirScalar / 130000; * log.debug("Base Start set to " + baseStart); * log.debug("Base End set to " + baseEnd); * oDirection.SetPosition(0, Vector3d.zero + exitTraj.xzy.normalized * baseStart); * oDirection.SetPosition(1, exitTraj.xzy.normalized * baseEnd); * oDirection.enabled = true; */ } }
private void setup() { generator = new System.Random(this.Root.MissionSeed); iconWaypoints = new List<Waypoint>(); for (int x = 0; x < 4; x++) { iconWaypoints.Add(new Waypoint()); iconWaypoints[iconWaypoints.Count - 1].celestialName = targetBody.GetName(); iconWaypoints[iconWaypoints.Count - 1].textureName = "orbit"; iconWaypoints[iconWaypoints.Count - 1].isOrbital = true; iconWaypoints[iconWaypoints.Count - 1].seed = Root.MissionSeed; WaypointManager.AddWaypoint(iconWaypoints[iconWaypoints.Count - 1]); } orbitDriver = new OrbitDriver(); //Start with periapsis at a safe distance and a random eccentricity, weighted towards the bottom. //Derive SMA from eccentricity and desired periapsis. orbitDriver.orbit = new Orbit(); switch (this.orbitType) { case OrbitType.POLAR: setRandomOrbit(difficultyFactor, false, true); break; case OrbitType.EQUATORIAL: setRandomOrbit(difficultyFactor, true, false); break; case OrbitType.STATIONARY: setSynchronousOrbit(difficultyFactor, true, 0.0); break; case OrbitType.SYNCHRONOUS: setSynchronousOrbit(difficultyFactor, false, generator.NextDouble()*(difficultyFactor/2)); break; case OrbitType.MOLNIYA: setMolniyaOrbit(); break; case OrbitType.TUNDRA: setTundraOrbit(); break; default: setRandomOrbit(difficultyFactor, false, false); break; } orbitDriver.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); orbitRenderer = MapView.MapCamera.gameObject.AddComponent<OrbitRenderer>(); orbitRenderer.driver = orbitDriver; orbitRenderer.drawIcons = OrbitRenderer.DrawIcons.NONE; orbitRenderer.drawNodes = false; orbitRenderer.orbitColor = WaypointManager.RandomColor(Root.MissionSeed); setVisible(true); orbitRenderer.celestialBody = targetBody; beenSetup = true; }