public static void logLongLatAlt(Vector3 v, CelestialBody planet) { double lng = planet.GetLongitude(v); double lat = planet.GetLatitude(v); double alt = planet.GetAltitude(v); Utils.Log("Long: {}, Lat: {}, Alt: {}", lng, lat, alt); }
public static Vector3d planetaryPosition(Vector3 v, CelestialBody planet) { double lng = planet.GetLongitude(v); double lat = planet.GetLatitude(v); double alt = planet.GetAltitude(v); return(planet.GetWorldSurfacePosition(lat, lng, alt)); }
public Vector3d LocalUp() { //return body.LocalUp (center); double lat = body.GetLatitude(center); double lon = body.GetLongitude(center); return(body.GetSurfaceNVector(lat, lon)); }
/// <summary> /// Place target at cursor in the map mode. Borrowed Waypoint Manager and changed. /// Returns latitude and longitude of a target or double.MinValue, if target is not valid /// </summary> /// <param name="targetBody"></param> /// <returns>[latitude, longitude]</returns> internal static double[] PlaceTargetAtCursor(CelestialBody targetBody) { if (targetBody.pqsController == null) { return new double[2] { double.MinValue, double.MinValue } } ; Ray mouseRay = PlanetariumCamera.Camera.ScreenPointToRay(Input.mousePosition); mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin); var bodyToOrigin = mouseRay.origin - targetBody.position; double curRadius = targetBody.pqsController.radiusMax; double lastRadius = 0; int loops = 0; while (loops < 50) { Vector3d relSurfacePosition; if (PQS.LineSphereIntersection(bodyToOrigin, mouseRay.direction, curRadius, out relSurfacePosition)) { var surfacePoint = targetBody.position + relSurfacePosition; double alt = targetBody.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(targetBody.GetLongitude(surfacePoint), Vector3d.down) * QuaternionD.AngleAxis(targetBody.GetLatitude(surfacePoint), Vector3d.forward) * Vector3d.right); double error = Math.Abs(curRadius - alt); if (error < (targetBody.pqsController.radiusMax - targetBody.pqsController.radiusMin) / 100) { return(new double[2] { (targetBody.GetLatitude(surfacePoint) + 360) % 360, (targetBody.GetLongitude(surfacePoint) + 360) % 360 }); } else { lastRadius = curRadius; curRadius = alt; loops++; } } else { if (loops == 0) { break; } else // Went too low, needs to try higher { curRadius = (lastRadius * 9 + curRadius) / 10; loops++; } } } return(new double[2] { double.MinValue, double.MinValue }); }
public void UpdateCoordinates(CelestialBody body) { if (target == null) { return; } Name = target.GetName(); switch (TargetInfo.targetType) { case ProtoTargetInfo.Type.Vessel: var v = target as Vessel; if (v == null) { break; } set_coordinates(v); return; case ProtoTargetInfo.Type.PartModule: var m = target as PartModule; if (m == null || m.vessel == null) { break; } set_coordinates(m.vessel); return; case ProtoTargetInfo.Type.Part: // There may be ITargetable Part derivatives in some mods // ReSharper disable once SuspiciousTypeConversion.Global var p = target as Part; if (p == null || p.vessel == null) { // ProtoTargetInfo.FindTarget() may return a Vessel when the Type == Part goto case ProtoTargetInfo.Type.Vessel; } set_coordinates(p.vessel); return; case ProtoTargetInfo.Type.Generic: var t = target.GetTransform(); if (t == null) { break; } var position = t.position; set_coordinates(body.GetLatitude(position), body.GetLongitude(position), body.GetAltitude(position)); return; } TargetInfo.targetType = ProtoTargetInfo.Type.Null; target = null; Valid = false; }
private static float GetHeading(Transform transform) { CelestialBody body = FlightGlobals.ActiveVessel.mainBody; Vector3 upVector = body.GetSurfaceNVector(body.GetLatitude((Vector3d)transform.position), body.GetLongitude((Vector3d)transform.position)).normalized; Vector3 north = Vector3.ProjectOnPlane(body.transform.up, upVector).normalized; Vector3 east = Vector3.Cross(upVector, north).normalized; Vector3 forward = Vector3.ProjectOnPlane(transform.forward, upVector); return(Vector3.Angle(forward, north)); }
public void UpdateCoordinates(CelestialBody body) { if (target == null) { return; } Name = target.GetName(); switch (TargetInfo.targetType) { case ProtoTargetInfo.Type.Vessel: var v = target as Vessel; if (v == null) { break; } set_coordinates(v); return; case ProtoTargetInfo.Type.PartModule: var m = target as PartModule; if (m == null || m.vessel == null) { break; } set_coordinates(m.vessel); return; case ProtoTargetInfo.Type.Part: var p = target as Part; if (p == null || p.vessel == null) { break; } set_coordinates(p.vessel); return; case ProtoTargetInfo.Type.Generic: var t = target.GetTransform(); if (t == null) { break; } set_coordinates(body.GetLatitude(t.position), body.GetLongitude(t.position)); return; // case ProtoTargetInfo.Type.CelestialBody: default: break; } TargetInfo.targetType = ProtoTargetInfo.Type.Null; Name += " last location"; target = null; }
public static Vector3d WorldPositionToGeoCoords(Vector3d worldPosition, CelestialBody body) { if (!body) { return Vector3d.zero; } double lat = body.GetLatitude(worldPosition); double longi = body.GetLongitude(worldPosition); double alt = body.GetAltitude(worldPosition); return new Vector3d(lat, longi, alt); }
public static Location GetLocation(PQSCity city) { if (city == null) { return(null); } Vector3d position = city.transform.position; CelestialBody body = Part.GetComponentUpwards <CelestialBody>(city.sphere.gameObject); return(new Location(body, body.GetLatitude(position), body.GetLongitude(position))); }
protected float getAnomalyBonus() { CelestialBody mainBody = this.part.vessel.mainBody; PQSSurfaceObject[] anomalies = mainBody.pqsSurfaceObjects; double longitude; double latitude; double distance = 0f; ConfigNode[] anomalyBlacklists = GameDatabase.Instance.GetConfigNodes(kAnomalyBlacklistNode); string blacklist = kAnomalyBlacklist; //We've covered the stock anomalies, now make sure we can blacklist anomalies from mods. try { foreach (ConfigNode blacklistNode in anomalyBlacklists) { blacklist += ";" + blacklistNode.GetValue("anomalies"); } } catch { } if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH) { for (int index = 0; index < anomalies.Length; index++) { //If the anomaly is on the blacklist, skip it. if (blacklist.Contains(anomalies[index].SurfaceObjectName)) { continue; } //Get the longitude and latitude of the anomaly longitude = mainBody.GetLongitude(anomalies[index].transform.position); latitude = mainBody.GetLatitude(anomalies[index].transform.position); //Get the distance (in kilometers) from the anomaly. distance = Utils.HaversineDistance(longitude, latitude, this.part.vessel.longitude, this.part.vessel.latitude, this.part.vessel.mainBody); //If we're near the anomaly, then we get a big location bonus. if (distance < kMinAnomalyDistance) { anomalyName = anomalies[index].SurfaceObjectName; return(kAnomalyBonus); } } } //No bonus anomalyName = string.Empty; return(0f); }
public double PositionToLongitude(Vector pos) { CelestialBody parent = Orbit.referenceBody; if (parent == null) //happens when this Orbitable is the Sun { return(0.0); } Vector3d unityWorldPos = GetPosition() + Shared.Vessel.GetWorldPos3D(); return(Utils.DegreeFix(parent.GetLongitude(unityWorldPos), -180.0)); }
public static Vector3d WorldPositionToGeoCoords(Vector3d worldPosition, CelestialBody body) { if(!body) { return Vector3d.zero; } double lat = body.GetLatitude(worldPosition); double longi = body.GetLongitude(worldPosition); double alt = body.GetAltitude(worldPosition); return new Vector3d(lat,longi,alt); }
public double PositionToLongitude(Vector pos) { CelestialBody parent = GetParentBody(); if (parent == null) //happens when this Orbitable is the Sun { return(0.0); } Vector3d unityWorldPos = GetPosition() + (Vector3d)Shared.Vessel.findWorldCenterOfMass(); return(Utils.DegreeFix(parent.GetLongitude(unityWorldPos), -180.0)); }
public static Vector3d WorldPositionToGeoCoords(Vector3d worldPosition, CelestialBody body) { if (!body) { return(Vector3d.zero); } double lat = body.GetLatitude(worldPosition); double longi = body.GetLongitude(worldPosition); double alt = body.GetAltitude(worldPosition); Debug.Log("[Spawn OrX Waldo Attack] Lat: " + lat + " - Lon:" + longi + " - Alt: " + alt); return(new Vector3d(lat, longi, alt)); }
public static bool CBhit(CelestialBody body, out Vector2 latlon) { Vector3d hitA; Vector3 origin, dir; if (MapView.MapIsEnabled) { //Use Scaled camera and don't attempt physics raycast if in map view. Ray ray = ScaledCamera.Instance.camera.ScreenPointToRay(Input.mousePosition); origin = ScaledSpace.ScaledToLocalSpace(ray.origin); dir = ray.direction.normalized; } else { //Attempt ray cast and return results if successfull. Ray ray = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hitB; float dist = (float)(Vector3.Distance(body.position, ray.origin) - body.Radius / 2); if (Physics.Raycast(ray, out hitB, dist)) { latlon = new Vector2((float)body.GetLatitude(hitB.point), (float)body.GetLongitude(hitB.point)); return(true); } //if all else fails, try with good oldfashioned arithmetic. origin = ray.origin; dir = ray.direction.normalized; } if (CBhit(body, origin, dir, out hitA)) { latlon = new Vector2((float)body.GetLatitude(hitA), (float)body.GetLongitude(hitA)); return(true); } else { latlon = Vector2.zero; return(false); } }
void FixedUpdate() { if (param != null && param.starJeb != null) { if (param.velocity != null) { param.starJeb.SetPosition(param.starJeb.transform.position + (param.velocity.Value * Time.fixedDeltaTime)); } else if (param.Destination != null) { Vector3 direction = (param.starJeb.transform.position - param.Destination.Value).normalized; float t = Time.fixedTime - param.stepTime; float x = t / 8.0f - 1.0f; if (t + Time.fixedDeltaTime * 2.0f > 8.0f) { x = 0.0f; } if (param.starJeb.altitude < param.starJeb.terrainAltitude + 10.0f) { CelestialBody body = param.DestinationBody; double lat = body.GetLatitude(param.starJeb.transform.position); double lon = body.GetLongitude(param.starJeb.transform.position); param.starJeb.SetPosition(body.GetWorldSurfacePosition(lat, lon, param.starJeb.terrainAltitude + 10.0f)); } else { param.starJeb.SetPosition(param.Destination.Value + direction * param.startDistance * x * x); } } if (param.Destination != null) { // Adjust the velocity, but only every frame - adjusting this too frequently // seems to cause the velocity to resonate back and forth if (Time.frameCount != lastAdjustment) { lastAdjustment = Time.frameCount; param.starJeb.ChangeWorldVelocity(-param.starJeb.GetSrfVelocity()); // Keep us safe! foreach (Part p in param.starJeb.parts) { p.crashTolerance = 10000000.0f; } CheatOptions.NoCrashDamage = true; } } } }
/// <summary> /// Converts world position to Lat,Long,Alt form. /// </summary> /// <returns>The position in geo coords.</returns> /// <param name="worldPosition">World position.</param> /// <param name="body">Body.</param> public static Vector3d WorldPositionToGeoCoords(Vector3d worldPosition, CelestialBody body) { if (!body) { //Debug.Log ("BahaTurret.VectorUtils.WorldPositionToGeoCoords body is null"); return(Vector3d.zero); } double lat = body.GetLatitude(worldPosition); double longi = body.GetLongitude(worldPosition); double alt = body.GetAltitude(worldPosition); return(new Vector3d(lat, longi, alt)); }
Vector3d WorldPositionToGeoCoords(Vector3d worldPosition, CelestialBody body) { if (!body) { Debug.LogWarning("WorldPositionToGeoCoords body is null"); return(Vector3d.zero); } double lat = body.GetLatitude(worldPosition); double longi = body.GetLongitude(worldPosition); double alt = body.GetAltitude(worldPosition); return(new Vector3d(lat, longi, alt)); }
internal static double getElevation(this CelestialBody body, Vector3d worldPosition) { if (body.pqsController == null) { return(0); } Vector3d pqsRadialVector = QuaternionD.AngleAxis(body.GetLongitude(worldPosition), Vector3d.down) * QuaternionD.AngleAxis(body.GetLatitude(worldPosition), Vector3d.forward) * Vector3d.right; double ret = body.pqsController.GetSurfaceHeight(pqsRadialVector) - body.pqsController.radius; if (ret < 0) { ret = 0; } return(ret); }
static Coordinates Search(CelestialBody body, Ray mouseRay) { Vector3d relSurfacePosition; Vector3d relOrigin = mouseRay.origin - body.position; double curRadius = body.pqsController.radiusMax; double lastRadius = 0; double error = 0; int loops = 0; float st = Time.time; while (loops < 50) { if (PQS.LineSphereIntersection(relOrigin, mouseRay.direction, curRadius, out relSurfacePosition)) { var alt = body.pqsController.GetSurfaceHeight(relSurfacePosition); if (body.ocean && alt < body.Radius) { alt = body.Radius; } error = Math.Abs(curRadius - alt); if (error < (body.pqsController.radiusMax - body.pqsController.radiusMin) / 100) { var surfacePoint = body.position + relSurfacePosition; return(new Coordinates(body.GetLatitude(surfacePoint), body.GetLongitude(surfacePoint))); } else { lastRadius = curRadius; curRadius = alt; loops++; } } else { if (loops == 0) { break; } else { // Went too low, needs to try higher curRadius = (lastRadius * 9 + curRadius) / 10; loops++; } } } return(null); }
public static KRPC.Utils.Tuple <Double, Double> ImpactPos() { if (Available()) { CelestialBody body = FlightGlobals.ActiveVessel.orbit.referenceBody; Vector3? impactVect = TRWrapper.ImpactVector(); if (impactVect != null) { var worldImpactPos = (Vector3d)impactVect + body.position; var lat = body.GetLatitude(worldImpactPos); var lng = DegreeFix(body.GetLongitude(worldImpactPos), -180); return(new KRPC.Utils.Tuple <Double, Double>(lat, lng)); } throw new Exception("Impact position is not available. Remember to check addons:tr:HasImpact"); } throw new Exception("Trajectories is not available"); }
private GeoCoordinates ImpactPos(VesselTarget vessel) { //Class1 pr = new Class1(vessel.Vessel); //if(!isEngaged) // throw new KOSException("please use engage"); CelestialBody body = vessel.Vessel.orbit.referenceBody; Vector3? impactVect = GetImpactPosition(vessel); if (impactVect != null) { var worldImpactPos = (Vector3d)impactVect + body.position; var lat = body.GetLatitude(worldImpactPos); var lng = DegreeFix(body.GetLongitude(worldImpactPos), -180); return(new GeoCoordinates(vessel.Shared, lat, lng)); } throw new KOSException("Impact position is null"); }
public static Coordinates GetMouseCoordinates(this CelestialBody targetBody) { Ray mouseRay = PlanetariumCamera.Camera.ScreenPointToRay(Input.mousePosition); mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin); var bodyToOrigin = mouseRay.origin - targetBody.position; double curRadius = targetBody.pqsController.radiusMax; double lastRadius = 0; int loops = 0; while (loops < 50) { Vector3d relSurfacePosition; if (PQS.LineSphereIntersection(bodyToOrigin, mouseRay.direction, curRadius, out relSurfacePosition)) { var surfacePoint = targetBody.position + relSurfacePosition; double alt = targetBody.pqsController.GetSurfaceHeight( QuaternionD.AngleAxis(targetBody.GetLongitude(surfacePoint), Vector3d.down) * QuaternionD.AngleAxis(targetBody.GetLatitude(surfacePoint), Vector3d.forward) * Vector3d.right); double error = Math.Abs(curRadius - alt); if (error < (targetBody.pqsController.radiusMax - targetBody.pqsController.radiusMin) / 100) { return(new Coordinates(targetBody.GetLatitude(surfacePoint), Utilities.ClampDegrees(targetBody.GetLongitude(surfacePoint)))); } else { lastRadius = curRadius; curRadius = alt; loops++; } } else { if (loops == 0) { break; } else { // Went too low, needs to try higher curRadius = (lastRadius * 9 + curRadius) / 10; loops++; } } } return(null); }
public SCANanomaly[] getAnomalies() { if (anomalies == null) { PQSCity[] sites = body.GetComponentsInChildren <PQSCity>(true); anomalies = new SCANanomaly[sites.Length]; for (int i = 0; i < sites.Length; ++i) { anomalies[i] = new SCANanomaly(sites[i].name, body.GetLongitude(sites[i].transform.position), body.GetLatitude(sites[i].transform.position), sites[i]); } } for (int i = 0; i < anomalies.Length; ++i) { anomalies[i].known = isCovered(anomalies[i].longitude, anomalies[i].latitude, SCANtype.Anomaly); anomalies[i].detail = isCovered(anomalies[i].longitude, anomalies[i].latitude, SCANtype.AnomalyDetail); } return(anomalies); }
public void Apply() { //Find vessel and body Vessel v = FlightGlobals.Vessels.Find(findVessel => findVessel.id == vesselID); if (v == null) { Debug.Log("Vessel not found"); return; } CelestialBody cb = FlightGlobals.Bodies.Find(findBody => findBody.name == planet); if (cb == null) { Debug.Log("Body not found"); return; } //Set orbit & position if (orbit != null) { v.orbitDriver.orbit.SetOrbit(orbit[0], orbit[1], orbit[2], orbit[3], orbit[4], orbit[5], orbit[6], cb); } if (position != null && velocity != null) { Vector3d pos = new Vector3d(position[0], position[1], position[2]); Vector3d vel = new Vector3d(velocity[0], velocity[1], velocity[2]); v.orbitDriver.orbit.UpdateFromFixedVectors(pos, vel, cb, universeTime); } v.orbitDriver.orbit.UpdateFromOrbitAtUT(v.orbitDriver.orbit, Planetarium.GetUniversalTime(), cb); //Set rotation Quaternion surfaceRotation = new Quaternion(rotation[0], rotation[1], rotation[2], rotation[3]); v.SetRotation(v.mainBody.bodyTransform.rotation * surfaceRotation); v.srfRelRotation = surfaceRotation; //Update fields that KSP uses elsewhere v.precalc.CalculatePhysicsStats(); v.latitude = cb.GetLatitude(cb.position + v.orbitDriver.pos); v.longitude = cb.GetLongitude(cb.position + v.orbitDriver.pos); v.altitude = v.orbitDriver.orbit.altitude; }
public static void updateCoordinates(CelestialBody b) { if (anomalies.Contains(b.name)) { for (int i = 0; i < anomalies[b.name].AnomalyCount; i++) { DMAnomalyObject anom = anomalies[b.name].getAnomaly(i); if (anom == null) { continue; } anom.WorldLocation = b.GetWorldSurfacePosition(anom.Lat, anom.Lon, anom.Alt); anom.Lat = b.GetLatitude(anom.WorldLocation); anom.Lon = b.GetLongitude(anom.WorldLocation); } } }
public DMAnomalyObject(PQSCity City) { city = City; name = city.name; try { body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == city.transform.parent.name); } catch (Exception e) { DMUtils.Logging("Something Went Wrong Here: {0}", e); } if (body != null) { worldLocation = city.transform.position; lat = clampLat(body.GetLatitude(worldLocation)); lon = clampLon(body.GetLongitude(worldLocation)); } }
/// <summary> /// relativePosition is in world frame, but relative to the body (i.e. inertial body space) /// returns the altitude above sea level (can be negative for bodies without ocean) /// </summary> internal static double GetGroundAltitude(CelestialBody body, Vector3d relativePosition) { if (body.pqsController == null) { return(0); } double lat = body.GetLatitude(relativePosition + body.position) / 180.0 * Math.PI; double lon = body.GetLongitude(relativePosition + body.position) / 180.0 * Math.PI; Vector3d rad = new Vector3d(Math.Cos(lat) * Math.Cos(lon), Math.Sin(lat), Math.Cos(lat) * Math.Sin(lon)); double elevation = body.pqsController.GetSurfaceHeight(rad) - body.Radius; if (body.ocean) { elevation = Math.Max(elevation, 0.0); } return(elevation); }
public static KRPC.Utils.Tuple <Double, Double> ImpactPos(KRPC.SpaceCenter.Services.Vessel vessel) { Class1 pr = new Class1(vessel.InternalVessel); CelestialBody body = vessel.InternalVessel.orbit.referenceBody; Vector3? impactVect = GetImpactPosition(pr, vessel.InternalVessel); /*if (vessel.Situation.Equals("Flying") || vessel.Situation.Equals(VesselSituation.SubOrbital)) * {*/ while (impactVect != null) { var worldImpactPos = (Vector3d)impactVect + body.position; var lat = body.GetLatitude(worldImpactPos); var lng = DegreeFix(body.GetLongitude(worldImpactPos), -180); return(new KRPC.Utils.Tuple <Double, Double>(lat, lng)); } throw new Exception("No impact pos"); /*} * throw new Exception("Cannot calculate, the vessel is in not in flight. ("+ vessel.Situation+")");*/ }
public static RadiationDose GetRadiationDose(this Vessel vessel) { CelestialBody cur_ref_body = vessel.mainBody; CelestialBody crefkerbin = FlightGlobals.fetch.bodies[PluginHelper.REF_BODY_KERBIN]; ORSPlanetaryResourcePixel res_pixel = ORSPlanetaryResourceMapData.getResourceAvailability( vessel.mainBody.flightGlobalsIndex, InterstellarResourcesConfiguration.Instance.ThoriumTetraflouride, cur_ref_body.GetLatitude(vessel.transform.position), cur_ref_body.GetLongitude(vessel.transform.position)); double ground_rad = Math.Sqrt(res_pixel.getAmount() * 9e6) / 24 / 365.25 / Math.Max(vessel.altitude / 870, 1); double proton_rad = cur_ref_body.GetProtonRadiationLevel(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude); double electron_rad = cur_ref_body.GetElectronRadiationLevel(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude); double divisor = Math.Pow(cur_ref_body.Radius / crefkerbin.Radius, 2.0); double proton_rad_level = proton_rad / divisor; double electron_rad_level = electron_rad / divisor; double inv_square_mult = Math.Pow(Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2) / Math.Pow(Vector3d.Distance(vessel.transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2); double solar_radiation = 0.19 * inv_square_mult; double mag_field_strength = cur_ref_body.GetBeltMagneticFieldMagnitude(FlightGlobals.ship_altitude, FlightGlobals.ship_latitude); while (cur_ref_body.referenceBody != null) { CelestialBody old_ref_body = cur_ref_body; cur_ref_body = cur_ref_body.referenceBody; if (cur_ref_body == old_ref_body) { break; } mag_field_strength += cur_ref_body.GetBeltMagneticFieldMagnitude(Vector3d.Distance(FlightGlobals.ship_position, cur_ref_body.transform.position) - cur_ref_body.Radius, FlightGlobals.ship_latitude); } if (vessel.mainBody != FlightGlobals.fetch.bodies[PluginHelper.REF_BODY_KERBOL]) { solar_radiation = solar_radiation * Math.Exp(-73840.5645666 * mag_field_strength) * Math.Exp(-vessel.atmDensity * 4.5); } RadiationDose dose = new RadiationDose(Math.Pow(electron_rad_level / 3e-5, 3.0) * 3.2, ground_rad, solar_radiation + Math.Pow(proton_rad_level / 3e-5, 3.0) * 3.2, 0.0); return(dose); }
private void ApplyOrbit(OrbitalData orbitData) { Vessel updateVessel = FlightGlobals.ActiveVessel; updateVessel.GoOnRails(); CelestialBody updateBody = FlightGlobals.GetBodyByName(orbitData.celestialBody); Orbit updateOrbit = orbitData.GetOrbit(); updateOrbit.Init(); updateOrbit.UpdateFromUT(Planetarium.GetUniversalTime()); //Positional Error Tracking double latitude = updateBody.GetLatitude(updateOrbit.pos); double longitude = updateBody.GetLongitude(updateOrbit.pos); double altitude = updateBody.GetAltitude(updateOrbit.pos); updateVessel.latitude = latitude; updateVessel.longitude = longitude; updateVessel.altitude = altitude; updateVessel.protoVessel.latitude = latitude; updateVessel.protoVessel.longitude = longitude; updateVessel.protoVessel.altitude = altitude; VesselUtil.CopyOrbit(updateOrbit, updateVessel.orbitDriver.orbit); updateVessel.orbitDriver.updateFromParameters(); /* * if (!updateVessel.packed) * { * var fudgeVel = updateBody.inverseRotation ? updateBody.getRFrmVelOrbit(updateVessel.orbitDriver.orbit) : Vector3d.zero; * updateVessel.SetWorldVelocity(updateVessel.orbitDriver.orbit.vel.xzy - fudgeVel - Krakensbane.GetFrameVelocity()); * } */ updateVessel.SetRotation(updateVessel.mainBody.bodyTransform.rotation * orbitData.rot); if (updateVessel.packed) { updateVessel.srfRelRotation = orbitData.rot; updateVessel.protoVessel.rotation = updateVessel.srfRelRotation; } }
public static string traceTrans(string prev, Transform tr, CelestialBody body = null) { string tmp; if (body != null) { tmp = prev + "." + tr.name + " - (" + body.GetLatitude(tr.position) + ", " + body.GetLongitude(tr.position) + ", " + body.GetAltitude(tr.position) + ")\n"; } else { tmp = prev + "." + tr.name + " - (" + tr.position + ", " + tr.rotation + ")\n"; } Component[] comps = tr.gameObject.GetComponents<Component>(); foreach (Component comp in comps) { tmp += "\t" + comp.GetType().Name + " - " + comp.name + "\n"; } for (int i = 0; i < tr.childCount; i++) { tmp += traceTrans(prev + "." + tr.name, tr.GetChild(i), body); } return tmp; }
static Coordinates Search(CelestialBody body, Ray mouseRay) { Vector3d relSurfacePosition; Vector3d relOrigin = mouseRay.origin - body.position; double curRadius = body.pqsController.radiusMax; double lastRadius = 0; double error = 0; int loops = 0; float st = Time.time; while(loops < 50) { if(PQS.LineSphereIntersection(relOrigin, mouseRay.direction, curRadius, out relSurfacePosition)) { var alt = body.pqsController.GetSurfaceHeight(relSurfacePosition); if(body.ocean && alt < body.Radius) alt = body.Radius; error = Math.Abs(curRadius - alt); if(error < (body.pqsController.radiusMax - body.pqsController.radiusMin) / 100) { var surfacePoint = body.position + relSurfacePosition; return new Coordinates(body.GetLatitude(surfacePoint), body.GetLongitude(surfacePoint)); } else { lastRadius = curRadius; curRadius = alt; loops++; } } else { if(loops == 0) break; else { // Went too low, needs to try higher curRadius = (lastRadius * 9 + curRadius) / 10; loops++; } } } return null; }
public static Coordinates GetMouseCoordinates(CelestialBody body) { Ray mouseRay = PlanetariumCamera.Camera.ScreenPointToRay(Input.mousePosition); mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin); Vector3d relOrigin = mouseRay.origin - body.position; Vector3d relSurfacePosition; double curRadius = body.pqsController.radiusMax; double lastRadius = 0; double error = 0; int loops = 0; float st = Time.time; while (loops < 50) { if (PQS.LineSphereIntersection(relOrigin, mouseRay.direction, curRadius, out relSurfacePosition)) { Vector3d surfacePoint = body.position + relSurfacePosition; double alt = body.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(body.GetLongitude(surfacePoint), Vector3d.down) * QuaternionD.AngleAxis(body.GetLatitude(surfacePoint), Vector3d.forward) * Vector3d.right); error = Math.Abs(curRadius - alt); if (error < (body.pqsController.radiusMax - body.pqsController.radiusMin) / 100) { return new Coordinates(body.GetLatitude(surfacePoint), MuUtils.ClampDegrees180(body.GetLongitude(surfacePoint))); } else { lastRadius = curRadius; curRadius = alt; loops++; } } else { if (loops == 0) { break; } else { // Went too low, needs to try higher curRadius = (lastRadius * 9 + curRadius) / 10; loops++; } } } return null; }
Vector3d WorldPositionToGeoCoords(Vector3d worldPosition, CelestialBody body) { if(!body) { Debug.LogWarning ("WorldPositionToGeoCoords body is null"); return Vector3d.zero; } double lat = body.GetLatitude(worldPosition); double longi = body.GetLongitude(worldPosition); double alt = body.GetAltitude(worldPosition); return new Vector3d(lat,longi,alt); }
public static double PQSAltitude(Vector3d pos, CelestialBody body) { return (pos - body.position).magnitude - body.Radius - PQSSurfaceHeight(body.GetLatitude(pos), body.GetLongitude(pos), body); }
// relativePosition is in world frame, but relative to the body (i.e. inertial body space) // returns the altitude above sea level (can be negative for bodies without ocean) private double GetGroundAltitude(CelestialBody body, Vector3 relativePosition) { if (body.pqsController == null) return 0; double lat = body.GetLatitude(relativePosition + body.position) / 180.0 * Math.PI; double lon = body.GetLongitude(relativePosition + body.position) / 180.0 * Math.PI; Vector3d rad = new Vector3d(Math.Cos(lat) * Math.Cos(lon), Math.Sin(lat), Math.Cos(lat) * Math.Sin(lon)); double elevation = body.pqsController.GetSurfaceHeight(rad) - body.Radius; if (body.ocean) elevation = Math.Max(elevation, 0.0); return elevation; }
private void GeneratePQSCityCoordinates(WaypointData wpData, CelestialBody body) { LoggingUtil.LogVerbose(this, " pqs city: " + wpData.pqsCity); LoggingUtil.LogVerbose(this, " Generating a waypoint based on PQS city " + wpData.pqsCity.name + "..."); Vector3d position = wpData.pqsCity.transform.position; LoggingUtil.LogVerbose(this, " pqs city position = " + position); // Translate by the PQS offset (inverse transform of coordinate system) Vector3d v = wpData.pqsOffset; Vector3d i = wpData.pqsCity.transform.right; Vector3d j = wpData.pqsCity.transform.forward; Vector3d k = wpData.pqsCity.transform.up; LoggingUtil.LogVerbose(this, " i, j, k = " + i + ", " + j + "," + k); LoggingUtil.LogVerbose(this, " pqs transform = " + wpData.pqsCity.transform); LoggingUtil.LogVerbose(this, " parent transform = " + wpData.pqsCity.transform.parent); Vector3d offsetPos = new Vector3d( (j.y * k.z - j.z * k.y) * v.x + (i.z * k.y - i.y * k.z) * v.y + (i.y * j.z - i.z * j.y) * v.z, (j.z * k.x - j.x * k.z) * v.x + (i.x * k.z - i.z * k.x) * v.y + (i.z * j.x - i.x * j.z) * v.z, (j.x * k.y - j.y * k.x) * v.x + (i.y * k.x - i.x * k.y) * v.y + (i.x * j.y - i.y * j.x) * v.z ); offsetPos *= (i.x * j.y * k.z) + (i.y * j.z * k.x) + (i.z * j.x * k.y) - (i.z * j.y * k.x) - (i.y * j.x * k.z) - (i.x * j.z * k.y); wpData.waypoint.latitude = body.GetLatitude(position + offsetPos); wpData.waypoint.longitude = body.GetLongitude(position + offsetPos); LoggingUtil.LogVerbose(this, " resulting lat, lon = (" + wpData.waypoint.latitude + ", " + wpData.waypoint.longitude + ")"); }
private IEnumerator updateCoordinates(CelestialBody b) { yield return new WaitForSeconds(3); currentBodyAnomalies.Clear(); if (anomalies.ContainsKey(b.name)) { foreach (var anom in anomalies[b.name].Values) { anom.WorldLocation = anom.City.transform.position; anom.Lat = b.GetLatitude(anom.WorldLocation); anom.Lon = b.GetLongitude(anom.WorldLocation); } currentBodyAnomalies = anomalies[b.name].Values.ToList(); } else currentBodyAnomalies = new List<DMAnomalyObject>(); }
/// <summary> /// Converts world position to Lat,Long,Alt form. /// </summary> /// <returns>The position in geo coords.</returns> /// <param name="worldPosition">World position.</param> /// <param name="body">Body.</param> public static Vector3d WorldPositionToGeoCoords(Vector3d worldPosition, CelestialBody body) { if(!body) { //Debug.Log ("BahaTurret.VectorUtils.WorldPositionToGeoCoords body is null"); return Vector3d.zero; } double lat = body.GetLatitude(worldPosition); double longi = body.GetLongitude(worldPosition); double alt = body.GetAltitude(worldPosition); return new Vector3d(lat,longi,alt); }
public static Coordinates GetMouseCoordinates(CelestialBody body) { Ray mouseRay = PlanetariumCamera.Camera.ScreenPointToRay(Input.mousePosition); mouseRay.origin = ScaledSpace.ScaledToLocalSpace(mouseRay.origin); Vector3d relOrigin = mouseRay.origin - body.position; Vector3d relSurfacePosition; if (PQS.LineSphereIntersection(relOrigin, mouseRay.direction, body.Radius, out relSurfacePosition)) { Vector3d surfacePoint = body.position + relSurfacePosition; return new Coordinates(body.GetLatitude(surfacePoint), MuUtils.ClampDegrees180(body.GetLongitude(surfacePoint))); } else { return null; } }