diff --git a/Changelog.txt b/Changelog.txt index dff3dff..49104ce 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,10 @@ +**v0.7.8** + +- Updated to KSP 1.3.0 and Kopernicus 1.3.0-1 +- Improved PQSCityGroups feature +- Improved debugging tools + + **v0.7.7** - Added the parameter groundTiling diff --git a/GameData/Sigma/Dimensions/Configs/Sigma-Dimensions.version b/GameData/Sigma/Dimensions/Configs/Sigma-Dimensions.version index ead8407..e4827a3 100644 --- a/GameData/Sigma/Dimensions/Configs/Sigma-Dimensions.version +++ b/GameData/Sigma/Dimensions/Configs/Sigma-Dimensions.version @@ -13,13 +13,13 @@ { "MAJOR": 0, "MINOR": 7, - "PATCH": 7, + "PATCH": 8, "BUILD": 0 }, "KSP_VERSION": { "MAJOR": 1, - "MINOR": 2, - "PATCH": 2 + "MINOR": 3, + "PATCH": 0 } } diff --git a/GameData/Sigma/Dimensions/Plugins/SigmaDimensions.dll b/GameData/Sigma/Dimensions/Plugins/SigmaDimensions.dll index 5ffcf70..aa846a3 100644 Binary files a/GameData/Sigma/Dimensions/Plugins/SigmaDimensions.dll and b/GameData/Sigma/Dimensions/Plugins/SigmaDimensions.dll differ diff --git a/README.md b/README.md index c76402e..1b2cc41 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **The Universal Rescale Mod for KSP** -KSP Forum Thread: http://forum.kerbalspaceprogram.com/index.php?/topic/126548-0 +KSP Forum Thread: http://forum.kerbalspaceprogram.com/index.php?/topic/126548-0/ Download Latest Release: https://github.com/Sigma88/Sigma-Dimensions/releases/latest diff --git a/[Source]/Distribution/SigmaDimensions.dll b/[Source]/Distribution/SigmaDimensions.dll index 5ffcf70..aa846a3 100644 Binary files a/[Source]/Distribution/SigmaDimensions.dll and b/[Source]/Distribution/SigmaDimensions.dll differ diff --git a/[Source]/SigmaDimensions/PQSCityGroupsLoader.cs b/[Source]/SigmaDimensions/PQSCityGroupsLoader.cs index d559ad0..a480cb2 100644 --- a/[Source]/SigmaDimensions/PQSCityGroupsLoader.cs +++ b/[Source]/SigmaDimensions/PQSCityGroupsLoader.cs @@ -10,15 +10,15 @@ namespace SigmaDimensionsPlugin public class PQSCityGroups : MonoBehaviour { Dictionary GroupsList = new Dictionary(); - public static List ExternalGroups = new List(); + public static Dictionary>> ExternalGroups = new Dictionary>>(); + public static List debug = new List(); void Start() { foreach (ConfigNode GroupsLoader in GameDatabase.Instance.GetConfigNodes("PQSCity_Groups")) { - AddGroups(GroupsLoader.GetNodes("Group")); + AddGroups(GroupsLoader.GetNodes("GROUP")); } - AddGroups(ExternalGroups.ToArray()); SaveGroups(); } @@ -38,61 +38,240 @@ void AddGroups(ConfigNode[] Groups) void SaveGroups() { + // LOAD SD GROUPS foreach (ConfigNode Group in GroupsList.Values) { + Debug.debug = false; + if (Group.HasValue("debug")) + { + NumericParser log = new NumericParser(); + log.SetFromString(Group.GetValue("debug")); + if (log.value) + Debug.debug = true; + } + string name = Group.GetValue("name"); - CelestialBody body = FlightGlobals.Bodies.First(b => b.transform.name == Group.GetValue("body")); + CelestialBody body = FlightGlobals.Bodies.First(b => b.name == Group.GetValue("body")); if (string.IsNullOrEmpty(name) || body == null) continue; + Debug.Log(">>> Sigma Dimensions Log: PQSCityGroupsLoader <<<"); + Debug.Log("> Planet: " + body.name + (body.name != body.transform.name ? (", (A.K.A.: " + body.transform.name + ")") : "")); + Debug.Log(" > Group: " + name); - Vector3Parser center = new Vector3Parser(); - if (Group.HasValue("CentralPQSCity")) - { - center = body.GetComponentsInChildren(true).FirstOrDefault(p => p.name == Group.GetValue("CentralPQSCity")).repositionRadial; - } - else if (Group.HasValue("CentralPQSCity2")) + + // FIND GROUP CENTER + Vector3Parser center = null; + + if (Group.HasNode("CENTER")) { - center = (Vector3)body.GetComponentsInChildren(true).First(p => p.name == Group.GetValue("CentralPQSCity2")).PlanetRelativePosition; + ConfigNode C = Group.GetNode("CENTER"); + + if (C.HasValue("CentralPQSCity")) + { + if (body == FlightGlobals.GetHomeBody() && C.GetValue("CentralPQSCity") == "KSC") + center = new Vector3(157000, -1000, -570000); + } + + if (center == null) + center = GetCenter(C, body); } - else if (Group.HasValue("CentralPosition")) + + if (!body.Has("PQSCityGroups")) + body.Set("PQSCityGroups", new Dictionary()); + Dictionary PQSList = body.Get>("PQSCityGroups"); + + if (Group.HasNode("MODS")) { - center.SetFromString(Group.GetValue("CentralPosition")); + ConfigNode M = Group.GetNode("MODS"); + + if (center == null) + center = GetCenter(M, body); } - else if (Group.HasValue("CentralLAT") && Group.HasValue("CentralLON")) + + foreach (string planet in ExternalGroups.Keys) { - EnumParser LAT = new EnumParser(); - EnumParser LON = new EnumParser(); - LAT.SetFromString(Group.GetValue("CentralLAT")); - LON.SetFromString(Group.GetValue("CentralLON")); - center = Utility.LLAtoECEF(LAT, LON, 1, 1); + UnityEngine.Debug.Log("SigmaLog: EXTERNAL PLANET - " + planet); + foreach (string group in ExternalGroups[planet].Keys) + { + UnityEngine.Debug.Log("SigmaLog: EXTERNAL GROUP - " + group); + UnityEngine.Debug.Log("SigmaLog: EXTERNAL MODS COUNT - " + ExternalGroups[planet][group].Count); + } } - else if (Group.HasValue("PQSCity")) + if (center == null && ExternalGroups.ContainsKey(body.name) && ExternalGroups[body.name].ContainsKey(name)) + center = GetPosition(ExternalGroups[body.name][name][0]); + if (center == null) continue; + if (Debug.debug && !debug.Contains(center)) debug.Add(center); + Debug.Log(" > Center position = " + center.value + ", (LAT: " + new SigmaDimensions.LatLon(center).lat + ", LON: " + new SigmaDimensions.LatLon(center).lon + ")"); + + + // ADD PQS MODS TO THE GROUP + if (Group.HasNode("MODS")) { - center = body.GetComponentsInChildren(true).FirstOrDefault(p => p.name == Group.GetValue("PQSCity")).repositionRadial; + ConfigNode M = Group.GetNode("MODS"); + + foreach (string city in M.GetValues("PQSCity")) + { + PQSCity mod = body.GetComponentsInChildren(true).FirstOrDefault(m => m.name == city); + + if (mod != null) + { + if (PQSList.ContainsKey(mod)) continue; + + PQSList.Add(mod, center); + Debug.Log(" > PQSCity: " + mod.name); + } + } + foreach (string city2 in M.GetValues("PQSCity2")) + { + PQSCity2 mod = body.GetComponentsInChildren(true).FirstOrDefault(m => m.name == city2); + + if (mod != null) + { + if (PQSList.ContainsKey(mod)) continue; + + PQSList.Add(mod, center); + Debug.Log(" > PQSCity2: " + mod.name); + } + } } - else if (Group.HasValue("PQSCity2")) + + + // ADD EXTERNAL MODS TO THIS GROUP + if (ExternalGroups.ContainsKey(body.name) && ExternalGroups[body.name].ContainsKey(name)) { - center = (Vector3)body.GetComponentsInChildren(true).First(p => p.name == Group.GetValue("CentralPQSCity2")).PlanetRelativePosition; + foreach (object mod in ExternalGroups[body.name][name]) + { + if (PQSList.ContainsKey(mod)) continue; + + PQSList.Add(mod, center); + Debug.Log(" > external: " + mod); + } } - else continue; - if (!body.Has("PQSCityGroups")) - body.Set("PQSCityGroups", new Dictionary()); - Dictionary PQSList = body.Get>("PQSCityGroups"); - foreach (string city in Group.GetValues("PQSCity")) + // REMOVE KSC FROM THE LIST + + PQSCity ksc = FlightGlobals.GetHomeBody().GetComponentsInChildren(true).FirstOrDefault(m => m.name == "KSC"); + if (PQSList.ContainsKey(ksc)) + PQSList.Remove(ksc); + + + body.Set("PQSCityGroups", PQSList); + + + // ADD THIS GROUP TO THE MOVE LIST + if (Group.HasNode("MOVE")) { - PQSCity mod = body.GetComponentsInChildren(true).First(m => m.name == city); - if (mod != null && !PQSList.ContainsKey(mod)) - PQSList.Add(mod, center); + ConfigNode C2 = Group.GetNode("MOVE"); + Vector3? newCenter = GetCenter(C2, body); + + if (newCenter == null) continue; + Debug.Log("Move Group to position = " + newCenter.Value + ", (LAT: " + new SigmaDimensions.LatLon(newCenter.Value).lat + ", LON: " + new SigmaDimensions.LatLon(newCenter.Value).lon + ")"); + + + var info = new KeyValuePair[]>((Vector3)newCenter, new[] { 0, 0, new NumericParser() }); + + if (C2.HasValue("Rotate")) + info.Value[0].SetFromString(C2.GetValue("Rotate")); Debug.Log("Rotate group = " + info.Value[0].value); + if (C2.HasValue("fixAltitude")) + info.Value[1].SetFromString(C2.GetValue("fixAltitude")); Debug.Log("Fix group altitude = " + info.Value[1].value); + if (C2.HasValue("originalAltitude")) + info.Value[2].SetFromString(C2.GetValue("originalAltitude")); + else + info.Value[2].SetFromString("-Infinity"); Debug.Log("Original group altitude = " + (info.Value[2].value == double.NegativeInfinity ? "[Not Specified]" : info.Value[2].value.ToString())); + + + if (!body.Has("PQSCityGroupsMove")) + body.Set("PQSCityGroupsMove", new Dictionary[]>>()); + var MoveList = body.Get[]>>>("PQSCityGroupsMove"); + + if (!MoveList.ContainsKey(center.value)) + MoveList.Add(center.value, info); + + body.Set("PQSCityGroupsMove", MoveList); } - foreach (string city2 in Group.GetValues("PQSCity2")) + } + + + // LOAD REMAINING EXTERNAL GROUPS + foreach (string planet in ExternalGroups.Keys) + { + foreach (string group in ExternalGroups[planet].Keys) { - PQSCity2 mod = body.GetComponentsInChildren(true).First(m => m.name == city2); - if (mod != null && !PQSList.ContainsKey(mod)) - PQSList.Add(mod, center); + CelestialBody body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == planet); + if (body == null || ExternalGroups[planet][group].Count == 0) continue; + + // Since these groups are new they don't have a center + // Define the center as the position of the first mod in the array + Vector3? center = null; + center = GetPosition(ExternalGroups[planet][group][0]); + if (center == null) continue; + + if (!body.Has("PQSCityGroups")) + body.Set("PQSCityGroups", new Dictionary()); + Dictionary PQSList = body.Get>("PQSCityGroups"); + + foreach (object mod in ExternalGroups[planet][group]) + { + if (!PQSList.ContainsKey(mod)) + PQSList.Add(mod, (Vector3)center); + } + + + // REMOVE KSC FROM THE LIST + + PQSCity ksc = FlightGlobals.GetHomeBody().GetComponentsInChildren(true).FirstOrDefault(m => m.name == "KSC"); + if (PQSList.ContainsKey(ksc)) + PQSList.Remove(ksc); + + + body.Set("PQSCityGroups", PQSList); } - body.Set("PQSCityGroups", PQSList); } } + + Vector3? GetCenter(ConfigNode node, CelestialBody body) + { + if (node.HasValue("CentralPQSCity")) + { + return body.GetComponentsInChildren(true).FirstOrDefault(p => p.name == node.GetValue("CentralPQSCity")).repositionRadial; + } + else if (node.HasValue("CentralPQSCity2")) + { + return body.GetComponentsInChildren(true).First(p => p.name == node.GetValue("CentralPQSCity2")).PlanetRelativePosition; + } + else if (node.HasValue("CentralPosition")) + { + Vector3Parser v = new Vector3Parser(); + v.SetFromString(node.GetValue("CentralPosition")); + return v; + } + else if (node.HasValue("CentralLAT") && node.HasValue("CentralLON")) + { + NumericParser LAT = new NumericParser(); + NumericParser LON = new NumericParser(); + LAT.SetFromString(node.GetValue("CentralLAT")); + LON.SetFromString(node.GetValue("CentralLON")); + return Utility.LLAtoECEF(LAT, LON, 1, 1); + } + else if (node.HasValue("PQSCity")) + { + return body.GetComponentsInChildren(true).FirstOrDefault(p => p.name == node.GetValue("PQSCity")).repositionRadial; + } + else if (node.HasValue("PQSCity2")) + { + return body.GetComponentsInChildren(true).First(p => p.name == node.GetValue("PQSCity2")).PlanetRelativePosition; + } + else return null; + } + + Vector3? GetPosition(object mod) + { + string type = mod.GetType().ToString(); + if (type == "PQSCity") + return ((PQSCity)mod).repositionRadial; + else if (type == "PQSCity2") + return ((PQSCity2)mod).PlanetRelativePosition; + else return null; + } } } diff --git a/[Source]/SigmaDimensions/SigmaDimensions.cs b/[Source]/SigmaDimensions/SigmaDimensions.cs index e53d640..e280696 100644 --- a/[Source]/SigmaDimensions/SigmaDimensions.cs +++ b/[Source]/SigmaDimensions/SigmaDimensions.cs @@ -17,9 +17,15 @@ public class SigmaDimensions : MonoBehaviour void Start() { + Debug.debug = false; // Reset Debug + Debug.debug = (PQSCityGroups.debug.Count > 0); Debug.Log(">>> Sigma Dimensions Log: PQSCityGroups <<<"); + foreach (CelestialBody cb in FlightGlobals.Bodies) { - body = cb; + body = cb; // DON'T CHANGE THIS (body is public and required by other methods) + Debug.debug = (body.Has("PQSCityGroups")); + Debug.Log("> Planet: " + body.name); + resize = body.Has("resize") ? body.Get("resize") : 1; landscape = body.Has("landscape") ? body.Get("landscape") : 1; resizeBuildings = body.Has("resizeBuildings") ? body.Get("resizeBuildings") : 1; @@ -38,212 +44,242 @@ void Start() void CityFixer(PQSCity pqs) { - // Resize the Building + Debug.debug = false; + // Resize the Building pqs.transform.localScale *= (float)resizeBuildings; // Fix PQSCity Groups - if (body.Has("PQSCityGroups")) { Dictionary PQSList = body.Get>("PQSCityGroups"); if (PQSList.ContainsKey(pqs)) { - GroupFixer(pqs, PQSList[pqs].normalized); + Debug.debug = PQSCityGroups.debug.Contains(PQSList[pqs]); + Debug.Log(" > PQSCity: " + pqs.name); + GroupFixer(pqs, PQSList[pqs]); } } // Fix Altitude - double groundLevel = body.pqsController.GetSurfaceHeight(pqs.repositionRadial) - body.Radius; + Debug.Log(" > Ground Level at Mod = " + groundLevel); if (!pqs.repositionToSphere && !pqs.repositionToSphereSurface) { // Offset = Distance from the center of the planet + Debug.Log(" > Original Absolute Offset = " + pqs.repositionRadiusOffset); double fromRadius = pqs.repositionRadiusOffset - (body.Radius / resize); double builtInOffset = fromRadius - groundLevel / (resize * landscape); pqs.repositionRadiusOffset = body.Radius + groundLevel + builtInOffset * resizeBuildings; + Debug.Log(" > Fixed Absolute Offset = " + pqs.repositionRadiusOffset); } else if (pqs.repositionToSphere && !pqs.repositionToSphereSurface) { // Offset = Distance from the radius of the planet + Debug.Log(" > Original Altitude = " + pqs.repositionRadiusOffset); double builtInOffset = pqs.repositionRadiusOffset - groundLevel / (resize * landscape); - pqs.repositionRadiusOffset = groundLevel + builtInOffset * resizeBuildings; + Debug.Log(" > Fixed Altitude = " + pqs.repositionRadiusOffset); } else if (pqs.repositionToSphereSurface && pqs.repositionToSphereSurfaceAddHeight) { // Offset = Distance from the surface of the planet + Debug.Log(" > Original Offset = " + pqs.repositionRadiusOffset); pqs.repositionRadiusOffset *= resizeBuildings; + Debug.Log(" > Fixed Offset = " + pqs.repositionRadiusOffset); } } void City2Fixer(PQSCity2 pqs) { - // Resize the Building + // Resize the Building pqs.transform.localScale *= (float)resizeBuildings; // Fix PQSCity Groups - if (body.Has("PQSCityGroups")) { Dictionary PQSList = body.Get>("PQSCityGroups"); if (PQSList.ContainsKey(pqs)) { - GroupFixer(pqs, PQSList[pqs].normalized); + Debug.debug = PQSCityGroups.debug.Contains(PQSList[pqs]); + Debug.Log(" > PQSCity2: " + pqs.name); + GroupFixer(pqs, PQSList[pqs]); } } // Fix Altitude - if (!pqs.snapToSurface) { // Offset = Distance from the radius of the planet double groundLevel = body.pqsController.GetSurfaceHeight(pqs.PlanetRelativePosition) - body.Radius; + Debug.Log(" > Ground Level at Mod = " + groundLevel); if (body.ocean && groundLevel < 0) - { groundLevel = 0; - } double builtInOffset = pqs.alt - groundLevel / (resize * landscape); pqs.alt = groundLevel + builtInOffset * resizeBuildings; + + Debug.Log(" > PQSCity2 Alt = " + pqs.alt); } else { // Offset = Distance from the surface of the planet + pqs.snapHeightOffset *= resizeBuildings; + Debug.Log(" > PQSCity2 Offset = " + pqs.snapHeightOffset); } } - void GroupFixer(PQSCity pqs, Vector3 REFvector) + void GroupFixer(object mod, Vector3 REFvector) { - if (body == FlightGlobals.GetHomeBody()) - LinkToKSC(pqs); + // Moves the group + Vector3 PQSposition = ((Vector3)GetPosition(mod)); + Debug.Log(" > Group center position = " + REFvector + ", (LAT: " + new LatLon(REFvector).lat + ", LON: " + new LatLon(REFvector).lon + ")"); + Debug.Log(" > Mod original position = " + PQSposition + ", (LAT: " + new LatLon(PQSposition).lat + ", LON: " + new LatLon(PQSposition).lon + ")"); + + if (body == FlightGlobals.GetHomeBody() && REFvector == new Vector3(157000, -1000, -570000)) + { + PQSCity KSC = body.GetComponentsInChildren().First(m => m.name == "KSC"); + MoveGroup(mod, KSC.repositionRadial, KSC.reorientFinalAngle - (-15), 0, 64.7846885412); + REFvector = KSC.repositionRadial; // Change the REFvector the the new position for Lerping + } + else if (body.Has("PQSCityGroupsMove")) + { + var MovesInfo = body.Get[]>>>("PQSCityGroupsMove"); + + if (MovesInfo.ContainsKey(REFvector)) + { + var info = MovesInfo[REFvector]; + MoveGroup(mod, info.Key, (float)info.Value[0], info.Value[1], info.Value[2]); + REFvector = info.Key; // Change the REFvector the the new position for Lerping + } + } + + // Update PQSposition + PQSposition = ((Vector3)GetPosition(mod)); - Vector3 PQSvector = pqs.repositionRadial.normalized; - Vector3 NEWvector = Vector3.LerpUnclamped(REFvector, PQSvector, (float)(resizeBuildings / resize)); - pqs.repositionRadial = NEWvector; + // Spread or Shrinks the group to account for Resize + Vector3 NEWvector = Vector3.LerpUnclamped(REFvector.normalized, PQSposition.normalized, (float)(resizeBuildings / resize)); + SetPosition(mod, NEWvector); + Debug.Log(" > Mod lerped position = " + (Vector3)GetPosition(mod) + ", (LAT: " + new LatLon((Vector3)GetPosition(mod)).lat + ", LON: " + new LatLon((Vector3)GetPosition(mod)).lon + ")"); } - void GroupFixer(PQSCity2 pqs, Vector3 REFvector) + void MoveGroup(object mod, Vector3 moveTo, float angle = 0, double fixAltitude = 0, double originalAltitude = double.NegativeInfinity) { - if (body == FlightGlobals.GetHomeBody()) - LinkToKSC(pqs); - - Vector3 PQSvector = pqs.PlanetRelativePosition.normalized; - Vector3 NEWvector = Vector3.LerpUnclamped(REFvector, PQSvector, (float)(resizeBuildings / resize)); - LatLon NEWlatlon = new LatLon(NEWvector); - pqs.lat = NEWlatlon.lat; - pqs.lon = NEWlatlon.lon; + LatLon target = new LatLon(moveTo.normalized); + + // Fix Rotation + Rotate(mod, angle); + + // ORIGINAL VECTORS (Center, North, East) + LatLon origin = new LatLon(body.Get>("PQSCityGroups")[mod].normalized); + Vector3 north = Vector3.ProjectOnPlane(Vector3.up, origin.vector); + Vector3 east = QuaternionD.AngleAxis(90, origin.vector) * north; + + // PQS Vectors (PQS, North, East) + Vector3 oldPQS = Vector3.ProjectOnPlane(((Vector3)GetPosition(mod)).normalized, origin.vector); + Vector3 pqsNorth = Vector3.Project(oldPQS, north); + Vector3 pqsEast = Vector3.Project(oldPQS, east); + + // Distance from center (Northward, Eastward) + float northward = pqsNorth.magnitude * (1 - (Vector3.Angle(north.normalized, pqsNorth.normalized) / 90)); + float eastward = pqsEast.magnitude * (1 - (Vector3.Angle(east.normalized, pqsEast.normalized) / 90)); + + // New Position Vectors (North, East) + Vector3 newNorth = Vector3.ProjectOnPlane(Vector3.up, target.vector).normalized; + Vector3 newEast = (QuaternionD.AngleAxis(90, target.vector) * newNorth); + + // Account for PQSCity rotation: + // PQSCity rotate when their Longitude changes + angle -= (float)(origin.lon - target.lon); + QuaternionD rotation = QuaternionD.AngleAxis(angle, target.vector); + + // Calculate final position by adding the north and east distances to the target position + // then rotate the new vector by as many degrees as it is necessary to account for the PQS model rotation + SetPosition(mod, rotation * (target.vector + newNorth * northward + newEast * eastward)); + Debug.Log(" > Group final position = " + target.vector + ", (LAT: " + target.lat + ", LON: " + target.lon + ")"); + Debug.Log(" > Mod final position = " + (Vector3)GetPosition(mod) + ", (LAT: " + new LatLon((Vector3)GetPosition(mod)).lat + ", LON: " + new LatLon((Vector3)GetPosition(mod)).lon + ")"); + + // Fix Altitude + if (originalAltitude == double.NegativeInfinity) + originalAltitude = (body.pqsController.GetSurfaceHeight(origin.vector) - body.Radius) / (resize * landscape); + Debug.Log(" > Mod original altitude = " + originalAltitude); + + FixAltitude(mod, (body.pqsController.GetSurfaceHeight(target.vector) - body.Radius) / (resize * landscape) - originalAltitude, fixAltitude); } - void LinkToKSC(PQSCity pqs) + Vector3? GetPosition(object mod) { - PQSCity KSC = body.GetComponentsInChildren().First(m => m.name == "KSC"); - LatLon movedKSC = new LatLon(KSC.repositionRadial.normalized); - Vector3 reference = body.Get>("PQSCityGroups")[pqs].normalized; + string type = mod.GetType().ToString(); + if (type == "PQSCity") + return ((PQSCity)mod).repositionRadial; + else if (type == "PQSCity2") + return ((PQSCity2)mod).PlanetRelativePosition; + return null; + } - if (reference == movedKSC.vector) + void SetPosition(object mod, Vector3 position) + { + string type = mod.GetType().ToString(); + if (type == "PQSCity") + ((PQSCity)mod).repositionRadial = position; + else if (type == "PQSCity2") { - // Fix Rotation - float angle = KSC.reorientFinalAngle - (-15); - pqs.reorientFinalAngle += angle; - - // Stock Vectors (KSC, North, East) - LatLon stockKSC = new LatLon(new Vector3(157000, -1000, -570000).normalized); - Vector3 north = Vector3.ProjectOnPlane(Vector3.up, stockKSC.vector); - Vector3 east = QuaternionD.AngleAxis(90, stockKSC.vector) * north; - - // PQS Vectors (PQS, North, East) - Vector3 oldPQS = Vector3.ProjectOnPlane(pqs.repositionRadial.normalized, stockKSC.vector); - Vector3 pqsNorth = Vector3.Project(oldPQS, north); - Vector3 pqsEast = Vector3.Project(oldPQS, east); - - // Distance from KSC (Northward, Eastward) - float northward = pqsNorth.magnitude * (1 - (Vector3.Angle(north.normalized, pqsNorth.normalized) / 90)); - float eastward = pqsEast.magnitude * (1 - (Vector3.Angle(east.normalized, pqsEast.normalized) / 90)); - - // New KSC Vectors (North, East) - Vector3 newNorth = Vector3.ProjectOnPlane(Vector3.up, movedKSC.vector).normalized; - Vector3 newEast = (QuaternionD.AngleAxis(90, movedKSC.vector) * newNorth); - - // Account for PQSCity rotation: - // PQSCity rotate when their Longitude changes - angle -= (float)(stockKSC.lon - movedKSC.lon); - QuaternionD rotation = QuaternionD.AngleAxis(angle, movedKSC.vector); - - // Calculate final position by adding the north and east distances to the movedKSC position - // then rotate the new vector by as many degrees as it is necessary to account for the PQS model rotation - pqs.repositionRadial = rotation * (movedKSC.vector + newNorth * northward + newEast * eastward); - - // Fix Altitude - if (!pqs.repositionToSphereSurface) - { - pqs.repositionRadiusOffset += (body.pqsController.GetSurfaceHeight(movedKSC.vector) - body.Radius) / (resize * landscape) - 64.7846885412; - } + LatLon LLA = new LatLon(position); + ((PQSCity2)mod).lat = LLA.lat; + ((PQSCity2)mod).lon = LLA.lon; } } - void LinkToKSC(PQSCity2 pqs) + void FixAltitude(object mod, double terrainShift, double fixAltitude) { - PQSCity KSC = body.GetComponentsInChildren().First(m => m.name == "KSC"); - LatLon movedKSC = new LatLon(KSC.repositionRadial.normalized); - Vector3 reference = body.Get>("PQSCityGroups")[pqs].normalized; + string type = mod.GetType().ToString(); + if (type == "PQSCity") + { + PQSCity pqs = (PQSCity)mod; + if (!pqs.repositionToSphereSurface || !pqs.repositionToSphereSurfaceAddHeight) + pqs.repositionRadiusOffset += terrainShift; - if (reference == movedKSC.vector) + pqs.repositionRadiusOffset += fixAltitude; + Debug.Log(" > Fixed repositionRadiusOffset = " + pqs.repositionRadiusOffset); + } + else if (type == "PQSCity2") { - // Fix Rotation - float angle = KSC.reorientFinalAngle - (-15); - pqs.rotation += angle; - - // Stock Vectors (KSC, North, East) - LatLon stockKSC = new LatLon(new Vector3(157000, -1000, -570000).normalized); - Vector3 north = Vector3.ProjectOnPlane(Vector3.up, stockKSC.vector); - Vector3 east = QuaternionD.AngleAxis(90, stockKSC.vector) * north; - - // PQS Vectors (PQS, North, East) - Vector3 oldPQS = Vector3.ProjectOnPlane(pqs.PlanetRelativePosition.normalized, stockKSC.vector); - Vector3 pqsNorth = Vector3.Project(oldPQS, north); - Vector3 pqsEast = Vector3.Project(oldPQS, east); - - // Distance from KSC (Northward, Eastward) - float northward = pqsNorth.magnitude * (1 - (Vector3.Angle(north.normalized, pqsNorth.normalized) / 90)); - float eastward = pqsEast.magnitude * (1 - (Vector3.Angle(east.normalized, pqsEast.normalized) / 90)); - - // New KSC Vectors (North, East) - Vector3 newNorth = Vector3.ProjectOnPlane(Vector3.up, movedKSC.vector).normalized; - Vector3 newEast = (QuaternionD.AngleAxis(90, movedKSC.vector) * newNorth); - - // Account for PQSCity rotation: - // PQSCity rotate when their Longitude changes - angle -= (float)(stockKSC.lon - movedKSC.lon); - QuaternionD rotation = QuaternionD.AngleAxis(angle, movedKSC.vector); - - // Calculate final position by adding the north and east distances to the movedKSC position - // then rotate the new vector by as many degrees as it is necessary to account for the PQS model rotation - LatLon newPQS = new LatLon(rotation * (movedKSC.vector + newNorth * northward + newEast * eastward)); - pqs.lat = newPQS.lat; - pqs.lon = newPQS.lon; - - // Fix Altitude - if (!pqs.snapToSurface) + PQSCity2 pqs = (PQSCity2)mod; + if (pqs.snapToSurface) + { + pqs.snapHeightOffset += fixAltitude; + Debug.Log(" > Fixed snapHeightOffset = " + pqs.snapHeightOffset); + } + else { - pqs.alt += (body.pqsController.GetSurfaceHeight(movedKSC.vector) - body.Radius) / (resize * landscape) - 64.7846885412; + pqs.alt += terrainShift + fixAltitude; + Debug.Log(" > Fixed PQSCity2.alt = " + pqs.alt); } } } + void Rotate(object mod, float angle) + { + string type = mod.GetType().ToString(); + if (type == "PQSCity") + ((PQSCity)mod).reorientFinalAngle += angle; + else if (type == "PQSCity2") + ((PQSCity2)mod).rotation += angle; + } + public class LatLon { double[] data = { 1, 1, 1 }; @@ -291,14 +327,16 @@ void Update() { v = Utility.LLAtoECEF(data[0], data[1], 0, data[2]); } - public LatLon() //LLA() + + public LatLon() { } - public LatLon(Vector3 input)//LLA(Vector3 input) + + public LatLon(Vector3 input) { vector = input; } - public LatLon(LatLon input)//LLA(LatLon input) + public LatLon(LatLon input) { data[0] = input.lat; data[1] = input.lon; diff --git a/[Source]/SigmaDimensions/SigmaDimensions.csproj b/[Source]/SigmaDimensions/SigmaDimensions.csproj index a618285..4fcc110 100644 --- a/[Source]/SigmaDimensions/SigmaDimensions.csproj +++ b/[Source]/SigmaDimensions/SigmaDimensions.csproj @@ -42,27 +42,27 @@ False - ..\..\..\Sigma-Binary\[Source]\KerbalSpaceProgram\KSP_Data\Managed\Assembly-CSharp.dll + ..\..\..\[References]\KerbalSpaceProgram\Assembly-CSharp.dll False - ..\..\..\Sigma-Binary\[Source]\Kopernicus\Kopernicus.dll + ..\..\..\[References]\Kopernicus\Kopernicus.dll False - ..\..\..\Sigma-Binary\[Source]\Kopernicus\Kopernicus.Components.dll + ..\..\..\[References]\Kopernicus\Kopernicus.Components.dll False - ..\..\..\Sigma-Binary\[Source]\Kopernicus\Kopernicus.OnDemand.dll + ..\..\..\[References]\Kopernicus\Kopernicus.OnDemand.dll False - ..\..\..\Sigma-Binary\[Source]\Kopernicus\Kopernicus.Parser.dll + ..\..\..\[References]\Kopernicus\Kopernicus.Parser.dll False - ..\..\..\Sigma-Binary\[Source]\KerbalSpaceProgram\KSP_Data\Managed\UnityEngine.dll + ..\..\..\[References]\KerbalSpaceProgram\UnityEngine.dll