internal override void Awake() { settings = KSPAlternateResourcePanel.settings; TooltipMouseOffset = new Vector2d(-10, 10); ddlSettingsTab = new DropDownList(EnumExtensions.ToEnumDescriptions<SettingsTabs>(),this); ddlSettingsSkin = new DropDownList(EnumExtensions.ToEnumDescriptions<Settings.DisplaySkin>(), (Int32)settings.SelectedSkin,this); ddlSettingsSkin.OnSelectionChanged += ddlSettingsSkin_SelectionChanged; ddlSettingsAlarmsWarning = LoadSoundsList(Resources.clipAlarms.Keys.ToArray(),settings.AlarmsWarningSound); ddlSettingsAlarmsAlert = LoadSoundsList(Resources.clipAlarms.Keys.ToArray(), settings.AlarmsAlertSound); ddlSettingsAlarmsWarning.OnSelectionChanged += ddlSettingsAlarmsWarning_OnSelectionChanged; ddlSettingsAlarmsAlert.OnSelectionChanged += ddlSettingsAlarmsAlert_OnSelectionChanged; ddlSettingsRateStyle = new DropDownList(EnumExtensions.ToEnumDescriptions<Settings.RateDisplayEnum>(),(Int32)settings.RateDisplayType, this); ddlSettingsRateStyle.OnSelectionChanged += ddlSettingsRateStyle_OnSelectionChanged; ddlSettingsButtonStyle = new DropDownList(EnumExtensions.ToEnumDescriptions<ButtonStyleEnum>(), (Int32)settings.ButtonStyleChosen, this); ddlSettingsButtonStyle.OnSelectionChanged += ddlSettingsButtonStyle_OnSelectionChanged; ddlManager.AddDDL(ddlSettingsButtonStyle); ddlManager.AddDDL(ddlSettingsAlarmsWarning); ddlManager.AddDDL(ddlSettingsAlarmsAlert); ddlManager.AddDDL(ddlSettingsRateStyle); ddlManager.AddDDL(ddlSettingsTab); ddlManager.AddDDL(ddlSettingsSkin); }
public Notes_VesselLog(Notes_VesselLog copy, Notes_Archive_Container n) { targetLocation = copy.targetLocation; archive_Root = n; vessel = null; archived = true; }
internal override void Awake() { //WindowRect = new Rect(mbTWP.windowMain.WindowRect.x + mbTWP.windowMain.WindowRect.width, mbTWP.windowMain.WindowRect.y, 300, 200); WindowRect = new Rect(0, 0, WindowWidth, WindowHeight); settings = TransferWindowPlanner.settings; TooltipMouseOffset = new Vector2d(-10, 10); ddlSettingsTab = new DropDownList(EnumExtensions.ToEnumDescriptions<SettingsTabs>(), this); ddlSettingsSkin = new DropDownList(EnumExtensions.ToEnumDescriptions<Settings.DisplaySkin>(), (Int32)settings.SelectedSkin, this); ddlSettingsSkin.OnSelectionChanged += ddlSettingsSkin_SelectionChanged; ddlSettingsButtonStyle = new DropDownList(EnumExtensions.ToEnumDescriptions<Settings.ButtonStyleEnum>(), (Int32)settings.ButtonStyleChosen, this); ddlSettingsButtonStyle.OnSelectionChanged += ddlSettingsButtonStyle_OnSelectionChanged; ddlSettingsCalendar = new DropDownList(EnumExtensions.ToEnumDescriptions<CalendarTypeEnum>(), this); //NOTE:Pull out the custom option for now ddlSettingsCalendar.Items.Remove(CalendarTypeEnum.Custom.Description()); ddlSettingsCalendar.OnSelectionChanged += ddlSettingsCalendar_OnSelectionChanged; ddlManager.AddDDL(ddlSettingsCalendar); ddlManager.AddDDL(ddlSettingsButtonStyle); ddlManager.AddDDL(ddlSettingsSkin); ddlManager.AddDDL(ddlSettingsTab); onWindowVisibleChanged += TWPWindowSettings_onWindowVisibleChanged; }
protected override void Awake() { WindowCaption = "S.C.A.N. Planetary Mapping"; WindowRect = sessionRect; WindowOptions = new GUILayoutOption[2] { GUILayout.Width(380), GUILayout.Height(230) }; WindowStyle = SCANskins.SCAN_window; Visible = false; DragEnabled = true; TooltipMouseOffset = new Vector2d(-10, -25); ClampToScreenOffset = new RectOffset(-300, -300, -200, -200); SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); SCAN_SkinsLibrary.SetCurrentTooltip(); }
protected override void Awake() { WindowCaption = "Map of "; WindowRect = defaultRect; WindowSize_Min = new Vector2(550, 225); WindowOptions = new GUILayoutOption[2] { GUILayout.Width(600), GUILayout.Height(300) }; WindowStyle = SCANskins.SCAN_window; Visible = false; DragEnabled = true; ClampEnabled = false; TooltipMouseOffset = new Vector2d(-10, -25); SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); SCAN_SkinsLibrary.SetCurrentTooltip(); }
protected override void Awake() { WindowCaption = "S.C.A.N. Settings"; WindowRect = defaultRect; WindowStyle = SCANskins.SCAN_window; WindowOptions = new GUILayoutOption[2] { GUILayout.Width(360), GUILayout.Height(300) }; Visible = false; DragEnabled = true; TooltipMouseOffset = new Vector2d(-10, -25); ClampToScreenOffset = new RectOffset(-280, -280, -600, -600); SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); removeControlLocks(); }
public static Vector2d CalcCoordinatesFromInitialPointBearingDistance(Vector2d initPoint, double bearingDeg, double distMeters, double bodyRadius) { var φ1 = CalcRadiansFromDeg(initPoint.x); var λ1 = CalcRadiansFromDeg(initPoint.y); bearingDeg = makeAngle0to360(bearingDeg); bearingDeg = CalcRadiansFromDeg(bearingDeg); var φ2 = Math.Asin(Math.Sin(φ1) * Math.Cos(distMeters / bodyRadius) + Math.Cos(φ1) * Math.Sin(distMeters / bodyRadius) * Math.Cos(bearingDeg)); var λ2 = λ1 + Math.Atan2(Math.Sin(bearingDeg) * Math.Sin(distMeters / bodyRadius) * Math.Cos(φ1), Math.Cos(distMeters / bodyRadius) - Math.Sin(φ1) * Math.Sin(φ2)); return new Vector2d(CalcDegFromRadians(φ2), CalcDegFromRadians(λ2)); }
protected override void Awake() { WindowCaption = "Map of "; WindowRect = sessionRect; WindowOptions = new GUILayoutOption[2] { GUILayout.Width(740), GUILayout.Height(420) }; WindowStyle = SCANskins.SCAN_window; Visible = false; DragEnabled = true; TooltipMouseOffset = new Vector2d(-10, -25); ClampToScreenOffset = new RectOffset(-600, -600, -400, -400); waypoints = HighLogic.LoadedScene != GameScenes.SPACECENTER; SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); SCAN_SkinsLibrary.SetCurrentTooltip(); removeControlLocks(); }
protected override void Awake() { WindowRect = sessionRect; WindowSize_Min = new Vector2(310, 180); WindowSize_Max = new Vector2(540, 400); WindowOptions = new GUILayoutOption[2] { GUILayout.Width(340), GUILayout.Height(240) }; WindowStyle = SCANskins.SCAN_window; showInfo = true; Visible = false; DragEnabled = true; ClampEnabled = true; TooltipMouseOffset = new Vector2d(-10, -25); ClampToScreenOffset = new RectOffset(-200, -200, -160, -160); SCAN_SkinsLibrary.SetCurrent("SCAN_Unity"); SCAN_SkinsLibrary.SetCurrentTooltip(); removeControlLocks(); Startup(); }
public static BiomeData Load(ConfigNode node) { BiomeData biomeData = new BiomeData(ConfigNodeUtil.ParseValue<string>(node, "name")); biomeData.landCount = ConfigNodeUtil.ParseValue<int>(node, "landCount"); biomeData.waterCount = ConfigNodeUtil.ParseValue<int>(node, "waterCount"); foreach (ConfigNode location in node.GetNodes("LAND_LOCATION")) { Vector2d v = new Vector2d(); v.y = ConfigNodeUtil.ParseValue<double>(location, "lat"); v.x = ConfigNodeUtil.ParseValue<double>(location, "lon"); biomeData.landLocations.Add(v); } foreach (ConfigNode location in node.GetNodes("WATER_LOCATION")) { Vector2d v = new Vector2d(); v.y = ConfigNodeUtil.ParseValue<double>(location, "lat"); v.x = ConfigNodeUtil.ParseValue<double>(location, "lon"); biomeData.waterLocations.Add(v); } return biomeData; }
internal void Startup() { tfScenario = TestFlightManagerScenario.Instance; tfScenario.userSettings.Load(); tfManager = TestFlightManager.Instance; Log("Starting coroutine to add toolbar icon"); StartCoroutine("AddToToolbar"); TestFlight.Resources.LoadTextures(); if (HighLogic.LoadedSceneIsFlight && tfScenario.userSettings.enableHUD && hud == null) { hud = gameObject.AddComponent(typeof(TestFlightHUD)) as TestFlightHUD; if (hud != null) { Log("Starting up TestFlightHUD"); hud.Startup(this); } GameEvents.onGameSceneLoadRequested.Add(Event_OnGameSceneLoadRequested); } // Default position and size -- will get proper bounds calculated when needed WindowRect = new Rect(0, 50, 500, 50); DragEnabled = !tfScenario.userSettings.mainWindowLocked; ClampToScreen = true; TooltipsEnabled = true; TooltipMouseOffset = new Vector2d(10, 10); TooltipStatic = true; WindowCaption = ""; List<string> views = new List<string>() { "Visual Settings", "Difficulty/Performance Settings", "Miscellaneous", "SaveGame Settings" }; ddlSettingsPage = new DropDownList(views, this); ddlManager.AddDDL(ddlSettingsPage); ddlSettingsPage.OnSelectionChanged += SettingsPage_OnSelectionChanged; WindowMoveEventsEnabled = true; onWindowMoveComplete += MainWindow_OnWindowMoveComplete; CalculateWindowBounds(); Visible = tfScenario.userSettings.showMSD; }
public override void Drive(FlightCtrlState s) { if (useSAS) { _requestedAttitude = attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Quaternion.Euler(90, 0, 0); if (!part.vessel.ActionGroups[KSPActionGroup.SAS]) { part.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); part.vessel.Autopilot.SAS.LockHeading(_requestedAttitude); lastSAS = _requestedAttitude; } else if (Quaternion.Angle(lastSAS, _requestedAttitude) > 10) { part.vessel.Autopilot.SAS.LockHeading(_requestedAttitude); lastSAS = _requestedAttitude; } else { part.vessel.Autopilot.SAS.LockHeading(_requestedAttitude, true); } core.thrust.differentialThrottleDemandedTorque = Vector3d.zero; } else { // Direction we want to be facing _requestedAttitude = attitudeGetReferenceRotation(attitudeReference) * attitudeTarget; Quaternion delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vessel.GetTransform().rotation) * _requestedAttitude); Vector3d deltaEuler = new Vector3d( (delta.eulerAngles.x > 180) ? (delta.eulerAngles.x - 360.0F) : delta.eulerAngles.x, -((delta.eulerAngles.y > 180) ? (delta.eulerAngles.y - 360.0F) : delta.eulerAngles.y), (delta.eulerAngles.z > 180) ? (delta.eulerAngles.z - 360.0F) : delta.eulerAngles.z ); Vector3d torque = vesselState.torqueAvailable + vesselState.torqueFromEngine * vessel.ctrlState.mainThrottle; if (core.thrust.differentialThrottleSuccess) torque += vesselState.torqueFromDiffThrottle * vessel.ctrlState.mainThrottle / 2; Vector3d inertia = Vector3d.Scale( vesselState.angularMomentum.Sign(), Vector3d.Scale( Vector3d.Scale(vesselState.angularMomentum, vesselState.angularMomentum), Vector3d.Scale(torque, vesselState.MoI).Invert() ) ); // ( MoI / avaiable torque ) factor: Vector3d NormFactor = Vector3d.Scale(vesselState.MoI, torque.Invert()).Reorder(132); // Find out the real shorter way to turn were we wan to. // Thanks to HoneyFox Vector3d tgtLocalUp = vessel.ReferenceTransform.transform.rotation.Inverse() * _requestedAttitude * Vector3d.forward; Vector3d curLocalUp = Vector3d.up; double turnAngle = Math.Abs(Vector3d.Angle(curLocalUp, tgtLocalUp)); Vector2d rotDirection = new Vector2d(tgtLocalUp.x, tgtLocalUp.z); rotDirection = rotDirection.normalized * turnAngle / 180.0f; Vector3d err = new Vector3d( -rotDirection.y * Math.PI, rotDirection.x * Math.PI, attitudeRollMatters ? ((delta.eulerAngles.z > 180) ? (delta.eulerAngles.z - 360.0F) : delta.eulerAngles.z) * Math.PI / 180.0F : 0F ); err += inertia.Reorder(132) / 2; err = new Vector3d(Math.Max(-Math.PI, Math.Min(Math.PI, err.x)), Math.Max(-Math.PI, Math.Min(Math.PI, err.y)), Math.Max(-Math.PI, Math.Min(Math.PI, err.z))); err.Scale(NormFactor); // angular velocity: Vector3d omega; omega.x = vessel.angularVelocity.x; omega.y = vessel.angularVelocity.z; // y <=> z omega.z = vessel.angularVelocity.y; // z <=> y omega.Scale(NormFactor); pidAction = pid.Compute(err, omega); // low pass filter, wf = 1/Tf: Vector3d act = lastAct + (pidAction - lastAct) * (1 / ((Tf / TimeWarp.fixedDeltaTime) + 1)); lastAct = act; SetFlightCtrlState(act, deltaEuler, s, 1); act = new Vector3d(s.pitch, s.yaw, s.roll); // Feed the control torque to the differential throttle if (core.thrust.differentialThrottleSuccess) core.thrust.differentialThrottleDemandedTorque = -Vector3d.Scale(act.xzy, vesselState.torqueFromDiffThrottle * vessel.ctrlState.mainThrottle); } }
public static bool operator ==(Vector2d lhs, Vector2d rhs) { return(Vector2d.SqrMagnitude(lhs - rhs) < 0.0 / 1.0); }
public override void OnInspectorGUI() { if (Application.isPlaying) { EditorGUILayout.LabelField("Debug Information",EditorStyles.boldLabel); base.DrawDefaultInspector(); return; } EditorGUI.BeginChangeCheck (); if (leTarget == null) { leTarget = (LSBody)target; } if (leTarget.cachedTransform == null) leTarget.cachedTransform = leTarget.GetComponent<Transform>(); if (leTarget.cachedGameObject == null) leTarget.cachedGameObject = leTarget.GetComponent<GameObject>(); Vector3 transformPos = leTarget.cachedTransform.position; leTarget.Position.x = FixedMath.Create (transformPos.x); leTarget.Position.y = FixedMath.Create (transformPos.z); Vector3 transformRot = leTarget.cachedTransform.eulerAngles; leTarget.Rotation = Vector2d.up; leTarget.Rotation.Rotate (FixedMath.Create (Mathf.Sin (transformRot.y * Mathf.Deg2Rad)), FixedMath.Create (Mathf.Cos (transformRot.y * Mathf.Deg2Rad))); //leTarget.Interpolate = EditorGUILayout.Toggle ("Interpolate", leTarget.Interpolate); EditorGUILayout.Space(); EditorGUILayout.LabelField ("Collider Settings",EditorStyles.boldLabel); leTarget.Shape = (ColliderType)EditorGUILayout.EnumPopup("Shape", leTarget.Shape); if (leTarget.Shape == ColliderType.None) return; leTarget.IsTrigger = EditorGUILayout.Toggle ("Is Trigger", leTarget.IsTrigger); if (!leTarget.IsTrigger && !leTarget.Immovable) { GUIContent PriorityContent = new GUIContent ("Priority", "The priority of this object in collisions. Objects of lower priority yield to objects of higher priority."); leTarget.Priority = EditorGUILayout.IntField (PriorityContent, leTarget.Priority); } switch (leTarget.Shape) { case ColliderType.Circle: GUIContent ImmovableContent = new GUIContent ("Immovable", "Is this object immovable, i.e. a wall. Note: non-immovable objects are not supported for any shape except circle."); leTarget.Immovable = EditorGUILayout.Toggle (ImmovableContent, leTarget.Immovable); EditorGUILayout.BeginHorizontal (); LSEditorUtility.FixedNumberField ("Radius", ref leTarget.Radius); EditorGUILayout.EndHorizontal (); break; case ColliderType.AABox: leTarget.Immovable = true; EditorGUILayout.BeginHorizontal (); LSEditorUtility.FixedNumberField ("Half Width", ref leTarget.HalfWidth); EditorGUILayout.EndHorizontal (); EditorGUILayout.BeginHorizontal (); LSEditorUtility.FixedNumberField ("Half Height", ref leTarget.HalfHeight); EditorGUILayout.EndHorizontal (); break; case ColliderType.Polygon: leTarget.Immovable = true; if (leTarget.Vertices == null || leTarget.Vertices.Length == 0) { leTarget.Vertices = new Vector2d[4]; leTarget.Vertices[0] = new Vector2d(FixedMath.Half, FixedMath.Half); leTarget.Vertices[1] = new Vector2d (FixedMath.Half, -FixedMath.Half); leTarget.Vertices[2] = new Vector2d (-FixedMath.Half, -FixedMath.Half); leTarget.Vertices[3] = new Vector2d (-FixedMath.Half, FixedMath.Half); } EditorGUILayout.BeginHorizontal(); int VerticesCount = EditorGUILayout.IntField ("Vertices count", leTarget.Vertices.Length); EditorGUILayout.EndHorizontal(); if (VerticesCount > leTarget.Vertices.Length) { Vector2d[] NewVertices = new Vector2d[VerticesCount]; leTarget.Vertices.CopyTo (NewVertices, 0); for (int i = leTarget.Vertices.Length; i < VerticesCount; i++) { NewVertices[i] = new Vector2d (-FixedMath.One, 0); } leTarget.Vertices = NewVertices; } else if (VerticesCount < leTarget.Vertices.Length) { Vector2d[] NewVertices = new Vector2d[VerticesCount]; for (int i = 0; i < VerticesCount; i++) { NewVertices[i] = leTarget.Vertices[i]; } leTarget.Vertices = NewVertices; } for (int i = 0; i < leTarget.Vertices.Length; i++) { EditorGUILayout.BeginHorizontal(); LSEditorUtility.Vector2dField ("V" + i.ToString () + ":", ref leTarget.Vertices[i]); EditorGUILayout.EndHorizontal(); } break; } SceneView.RepaintAll (); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo (leTarget,"LSBody Change"); EditorUtility.SetDirty (leTarget); } }
public static Vector2d Max(Vector2d lhs, Vector2d rhs) { return(new Vector2d(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y))); }
public static bool operator !=(Vector2d lhs, Vector2d rhs) { return((double)Vector2d.SqrMagnitude(lhs - rhs) >= 0.0 / 1.0); }
protected override void LateUpdate() { if (shutdown) return; if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready) return; if (SCANcontroller.controller == null) { way = null; return; } if (!SCANcontroller.controller.mechJebTargetSelection) { way = null; return; } v = FlightGlobals.ActiveVessel; if (v == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (v.mainBody != SCANcontroller.controller.LandingTargetBody) SCANcontroller.controller.LandingTargetBody = v.mainBody; data = SCANUtil.getData(v.mainBody); if (data == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (v.FindPartModulesImplementing<MechJebCore>().Count <= 0) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } core = v.GetMasterMechJeb(); if (core == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX) { if (guidanceModule == null) guidanceModule = (DisplayModule)core.GetComputerModule("MechJebModuleLandingGuidance"); if (guidanceModule == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (!guidanceModule.unlockChecked) return; if (guidanceModule.hidden) { SCANcontroller.controller.MechJebLoaded = false; shutdown = true; way = null; return; } } target = core.target; if (target == null) { SCANcontroller.controller.MechJebLoaded = false; way = null; return; } if (!SCANcontroller.controller.MechJebLoaded) { SCANcontroller.controller.MechJebLoaded = true; RenderingManager.AddToPostDrawQueue(1, drawTarget); } if (SCANcontroller.controller.LandingTarget != null) { way = SCANcontroller.controller.LandingTarget; } if (SCANcontroller.controller.TargetSelecting) { way = null; selectingTarget = true; if (SCANcontroller.controller.TargetSelectingActive) selectingInMap = true; else selectingInMap = false; coords = SCANcontroller.controller.LandingTargetCoords; return; } else if (selectingTarget) { selectingTarget = false; if (selectingInMap) { selectingInMap = false; coords = SCANcontroller.controller.LandingTargetCoords; way = new SCANwaypoint(coords.y, coords.x, siteName); target.SetPositionTarget(SCANcontroller.controller.LandingTargetBody, way.Latitude, way.Longitude); } } selectingInMap = false; selectingTarget = false; if (target.Target == null) { way = null; return; } if (target.targetBody != v.mainBody) { way = null; return; } if (!(target.Target is PositionTarget)) { way = null; return; } coords.x = target.targetLongitude; coords.y = target.targetLatitude; if (way != null) { if (!SCANUtil.ApproxEq(coords.x, way.Longitude) || !SCANUtil.ApproxEq(coords.y, way.Latitude)) { way = new SCANwaypoint(coords.y, coords.x, siteName); SCANcontroller.controller.LandingTarget = way; data.addToWaypoints(); } } else { way = new SCANwaypoint(coords.y, coords.x, siteName); SCANcontroller.controller.LandingTarget = way; data.addToWaypoints(); } }
public override void OnInspectorGUI() { if (Application.isPlaying) { EditorGUILayout.LabelField ("Debug Information", EditorStyles.boldLabel); base.DrawDefaultInspector (); return; } EditorGUI.BeginChangeCheck (); LSBody[] Bodies = GenerateTargets (); LSBody Body = Bodies[0]; if (Bodies.Length == 1) { Body._positionalTransform = (Transform)EditorGUILayout.ObjectField ( "Positional Transform", Body._positionalTransform, typeof(Transform), true); Body._rotationalTransform = (Transform)EditorGUILayout.ObjectField ( "Rotational Transform", Body._rotationalTransform, typeof(Transform), true); EditorGUILayout.Space (); } Body.Layer = EditorGUILayout.LayerField ("Layer", Body.Layer); for (int i = 0; i < Bodies.Length; i++) { LSBody body = Bodies[i]; Transform posTransform = body._positionalTransform != null ? body._positionalTransform : body.transform; body.Position = new Vector2d (posTransform.position); Transform rotTransform = body._rotationalTransform != null ? body._rotationalTransform : body.transform; body.Rotation = new Vector2d (Mathf.Sin (rotTransform.rotation.x), Mathf.Cos (rotTransform.rotation.y)); } EditorGUILayout.LabelField ("Collider Settings", EditorStyles.boldLabel); Body.Shape = (ColliderType)EditorGUILayout.EnumPopup ("Shape", Body.Shape); for (int i = 1; i < Bodies.Length; i++) { Bodies[i].Shape = Body.Shape; } if (Body.Shape == ColliderType.None) { return; } Body.IsTrigger = EditorGUILayout.Toggle ("Is Trigger", Body.IsTrigger); if (!Body.IsTrigger && !Body.Immovable) { var PriorityContent = new GUIContent ("Priority", "The priority of this object in collisions. Objects of lower priority yield to objects of higher priority."); SerializedProperty sp = serializedObject.FindProperty ("_priority"); sp.intValue = EditorGUILayout.IntField (PriorityContent, sp.intValue); } switch (Body.Shape) { case ColliderType.Circle: var ImmovableContent = new GUIContent ("Immovable", "Is this object immovable, i.e. a wall. Note: non-immovable objects are not supported for any shape except circle."); Body.Immovable = EditorGUILayout.Toggle (ImmovableContent, Body.Immovable); LSEditorUtility.FixedNumberField ("Radius", ref Body.Radius); for (int i = 1; i < Bodies.Length; i++) { Bodies[i].Radius = Body.Radius; } break; case ColliderType.AABox: LSEditorUtility.FixedNumberField ("Half Width", ref Body.HalfWidth); LSEditorUtility.FixedNumberField ("Half Height", ref Body.HalfHeight); for (int i = 1; i < Bodies.Length; i++) { Bodies[i].HalfWidth = Body.HalfWidth; Bodies[i].HalfHeight = Body.HalfHeight; } break; case ColliderType.Polygon: if (Body.Vertices == null || Body.Vertices.Length == 0) { Body.Vertices = new Vector2d[4]; Body.Vertices [0] = new Vector2d (FixedMath.Half, FixedMath.Half); Body.Vertices [1] = new Vector2d (FixedMath.Half, -FixedMath.Half); Body.Vertices [2] = new Vector2d (-FixedMath.Half, -FixedMath.Half); Body.Vertices [3] = new Vector2d (-FixedMath.Half, FixedMath.Half); } int VerticesCount = EditorGUILayout.IntField ("Vertices count", Body.Vertices.Length); if (VerticesCount > Body.Vertices.Length) { var NewVertices = new Vector2d[VerticesCount]; Body.Vertices.CopyTo (NewVertices, 0); for (int i = Body.Vertices.Length; i < VerticesCount; i++) { NewVertices [i] = new Vector2d (-FixedMath.One, 0); } Body.Vertices = NewVertices; } else if (VerticesCount < Body.Vertices.Length) { var NewVertices = new Vector2d[VerticesCount]; for (int i = 0; i < VerticesCount; i++) { NewVertices [i] = Body.Vertices [i]; } Body.Vertices = NewVertices; } for (int i = 0; i < Body.Vertices.Length; i++) { LSEditorUtility.Vector2dField ("V" + i.ToString () + ":", ref Body.Vertices [i]); } for (int i = 1; i < Bodies.Length; i++) { Bodies[i].Vertices = Body.Vertices; } break; } for (int i = 1; i < Bodies.Length; i++) { Bodies[i].IsTrigger = Body.IsTrigger; Bodies[i].Immovable = Body.Immovable; Bodies[i].IsTrigger = Body.IsTrigger; } if (EditorGUI.EndChangeCheck ()) { Undo.RegisterCompleteObjectUndo (Body, "LSBody Change"); serializedObject.ApplyModifiedProperties (); SceneView.RepaintAll (); } }
public static Vector2d parse(this ConfigNode node, string name, Vector2d original) { if (!node.HasValue(name)) return original; Vector2d v = original; string[] values = node.GetValue(name).Split('|'); if (values.Length != 2) return v; double first = original.x; double second = original.y; if (!double.TryParse(values[0], out first)) first = original.x; if (!double.TryParse(values[1], out second)) second = original.y; v.x = first; v.y = second; return v; }
public static Vector2d Scale(Vector2d a, Vector2d b) { return(new Vector2d(a.x * b.x, a.y * b.y)); }
public static double Distance(Vector2d a, Vector2d b) { return((a - b).magnitude); }
internal static bool LineSegmentIntersection(Vector2d p1, Vector2d p2, Vector2d p3, Vector2d p4, ref Vector2d result) { double num1 = p2.x - p1.x; double num2 = p2.y - p1.y; double num3 = p4.x - p3.x; double num4 = p4.y - p3.y; double num5 = (num1 * num4 - num2 * num3); if (num5 == 0.0d) { return(false); } double num6 = p3.x - p1.x; double num7 = p3.y - p1.y; double num8 = (num6 * num4 - num7 * num3) / num5; if (num8 < 0.0d || num8 > 1.0d) { return(false); } double num9 = (num6 * num2 - num7 * num1) / num5; if (num9 < 0.0d || num9 > 1.0d) { return(false); } result = new Vector2d(p1.x + num8 * num1, p1.y + num8 * num2); return(true); }
public static double Angle(Vector2d from, Vector2d to) { return(Mathd.Acos(Mathd.Clamp(Vector2d.Dot(from.normalized, to.normalized), -1d, 1d)) * 57.29578d); }
internal void Startup() { CalculateWindowBounds(); WindowMoveEventsEnabled = true; ClampToScreen = true; TooltipsEnabled = true; TooltipMouseOffset = new Vector2d(10, 10); TooltipStatic = true; WindowCaption = ""; StartCoroutine("AddToToolbar"); TestFlight.Resources.LoadTextures(); List<string> views = new List<string>() { "Visual Settings", "Difficulty/Performance Settings", "Miscellaneous", "SaveGame Settings" }; ddlSettingsPage = new DropDownList(views, this); ddlManager.AddDDL(ddlSettingsPage); ddlSettingsPage.OnSelectionChanged += SettingsPage_OnSelectionChanged; isReady = true; }
private void focusOnSite(Vector2d loc) { Debug.Log("Focusing on site"); PlanetariumCamera camera = PlanetariumCamera.fetch; CelestialBody Kerbin = getKSCBody(); Vector3d point = ScaledSpace.LocalToScaledSpace(Kerbin.GetWorldSurfacePosition(loc.x, loc.y, 0)); Vector3 vec = ScaledSpace.LocalToScaledSpace(Kerbin.transform.localPosition); point = (point - vec).normalized * Kerbin.Radius; camera.SetCamCoordsFromPosition(new Vector3((float) point.x, (float) point.y, (float) point.z)); // this works for RSS, may have to change for other sizes. // float distance = camera.startDistance * 3.5f; float distance = (float) (Kerbin.Radius * 0.00035); camera.SetDistance(distance); }
/// <summary> /// Automatically guides the ship to face a desired orientation /// </summary> /// <param name="target">The desired orientation</param> /// <param name="c">The FlightCtrlState for the current vessel.</param> /// <param name="fc">The flight computer carrying out the slew</param> /// <param name="ignoreRoll">[optional] to ignore the roll</param> public static void SteerShipToward(Quaternion target, FlightCtrlState c, FlightComputer fc, bool ignoreRoll) { // Add support for roll-less targets later -- Starstrider42 bool fixedRoll = !ignoreRoll; Vessel vessel = fc.Vessel; Vector3d momentOfInertia = GetTrueMoI(vessel); Transform vesselReference = vessel.GetTransform(); //--------------------------------------- // Copied almost verbatim from MechJeb master on June 27, 2014 -- Starstrider42 Quaternion delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vesselReference.rotation) * target); Vector3d torque = GetTorque(vessel, c.mainThrottle); Vector3d spinMargin = GetStoppingAngle(vessel, torque); // Allow for zero torque around some but not all axes Vector3d normFactor; normFactor.x = (torque.x != 0 ? momentOfInertia.x / torque.x : 0.0); normFactor.y = (torque.y != 0 ? momentOfInertia.y / torque.y : 0.0); normFactor.z = (torque.z != 0 ? momentOfInertia.z / torque.z : 0.0); normFactor = SwapYZ(normFactor); // Find out the real shorter way to turn were we want to. // Thanks to HoneyFox Vector3d tgtLocalUp = vesselReference.transform.rotation.Inverse() * target * Vector3d.forward; Vector3d curLocalUp = Vector3d.up; double turnAngle = Math.Abs(Vector3d.Angle(curLocalUp, tgtLocalUp)); var rotDirection = new Vector2d(tgtLocalUp.x, tgtLocalUp.z); rotDirection = rotDirection.normalized * turnAngle / 180.0f; var err = new Vector3d( -rotDirection.y * Math.PI, rotDirection.x * Math.PI, fixedRoll ? ((delta.eulerAngles.z > 180) ? (delta.eulerAngles.z - 360.0F) : delta.eulerAngles.z) * Math.PI / 180.0F : 0F ); err += SwapYZ(spinMargin); err = new Vector3d(Math.Max(-Math.PI, Math.Min(Math.PI, err.x)), Math.Max(-Math.PI, Math.Min(Math.PI, err.y)), Math.Max(-Math.PI, Math.Min(Math.PI, err.z))); err.Scale(normFactor); // angular velocity: Vector3d omega = SwapYZ(vessel.angularVelocity); omega.Scale(normFactor); Vector3d pidAction = fc.pid.Compute(err, omega); // low pass filter, wf = 1/Tf: Vector3d act = fc.lastAct + (pidAction - fc.lastAct) * (1 / ((fc.Tf / TimeWarp.fixedDeltaTime) + 1)); fc.lastAct = act; // end MechJeb import //--------------------------------------- float precision = Mathf.Clamp((float)(torque.x * 20f / momentOfInertia.magnitude), 0.5f, 10f); float driveLimit = Mathf.Clamp01((float)(err.magnitude * 380.0f / precision)); act.x = Mathf.Clamp((float)act.x, -driveLimit, driveLimit); act.y = Mathf.Clamp((float)act.y, -driveLimit, driveLimit); act.z = Mathf.Clamp((float)act.z, -driveLimit, driveLimit); c.roll = Mathf.Clamp((float)(c.roll + act.z), -driveLimit, driveLimit); c.pitch = Mathf.Clamp((float)(c.pitch + act.x), -driveLimit, driveLimit); c.yaw = Mathf.Clamp((float)(c.yaw + act.y), -driveLimit, driveLimit); }
public Vector2d times(Vector2d vec) { return new Vector2d(a * vec.x + b * vec.y, c * vec.x + d * vec.y); }
public static double Dot(Vector2d lhs, Vector2d rhs) { return(lhs.x * rhs.x + lhs.y * rhs.y); }
protected override void Awake() { WindowRect = new Rect(100, 100, 300, 120); WindowOptions = new GUILayoutOption[3] { GUILayout.Width(300), GUILayout.Height(120), GUILayout.MaxHeight(120) }; WindowCaption = "EVA Transfer"; Visible = false; DragEnabled = true; ClampToScreen = true; ClampToScreenOffset = new RectOffset(-100, -100, -100, -100); TooltipMouseOffset = new Vector2d(-10, -25); TooltipsEnabled = true; ET_SkinsLibrary.SetCurrent("EVA_KSPSkin"); Assembly assembly = AssemblyLoader.loadedAssemblies.GetByAssembly(Assembly.GetExecutingAssembly()).assembly; var ainfoV = Attribute.GetCustomAttribute(assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; switch (ainfoV == null) { case true: version = ""; break; default: version = ainfoV.InformationalVersion; break; } }
public static double SqrMagnitude(Vector2d a) { return(a.x * a.x + a.y * a.y); }
public static void loadPlanetaryResourceData(int body) { string celestial_body_name = FlightGlobals.Bodies[body].bodyName; UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("PLANETARY_RESOURCE_DEFINITION"); Debug.Log("[ORS] Loading Planetary Resource Data. Length: " + configs.Length); foreach (ORSResourceAbundanceMarker abundance_marker in abundance_markers) { removeAbundanceSphere(abundance_marker.getPlanetarySphere()); removeAbundanceSphere(abundance_marker.getScaledSphere()); } sphere = null; sphere_texture = null; body_resource_maps.Clear(); body_abudnance_angles.Clear(); map_body = -1; current_body = body; foreach (UrlDir.UrlConfig config in configs) { ConfigNode planetary_resource_config_node = config.config; if (planetary_resource_config_node.GetValue("celestialBodyName") == celestial_body_name && planetary_resource_config_node != null) { Debug.Log("[ORS] Loading Planetary Resource Data for " + celestial_body_name); string resource_gui_name = planetary_resource_config_node.GetValue("name"); if (body_resource_maps.ContainsKey(resource_gui_name)) continue; Texture2D map = GameDatabase.Instance.GetTexture(planetary_resource_config_node.GetValue("mapUrl"), false); try { map.GetPixel(1, 1); } catch (UnityException e) { Debug.Log("Stop Doing Dumb Things With Your Map Textures: " + e); continue; } if (map == null) { continue; } ORSPlanetaryResourceInfo resource_info = new ORSPlanetaryResourceInfo(resource_gui_name, map, body); if (planetary_resource_config_node.HasValue("resourceName")) { string resource_name = planetary_resource_config_node.GetValue("resourceName"); resource_info.setResourceName(resource_name); } if (planetary_resource_config_node.HasValue("resourceScale")) { string resource_scale = planetary_resource_config_node.GetValue("resourceScale"); resource_info.setResourceScale(resource_scale); } if (planetary_resource_config_node.HasValue("scaleFactor")) { string scale_factorstr = planetary_resource_config_node.GetValue("scaleFactor"); double scale_factor = double.Parse(scale_factorstr); resource_info.setScaleFactor(scale_factor); } if (planetary_resource_config_node.HasValue("scaleMultiplier")) { string scale_multstr = planetary_resource_config_node.GetValue("scaleMultiplier"); double scale_mult = double.Parse(scale_multstr); resource_info.setScaleMultiplier(scale_mult); } if (planetary_resource_config_node.HasValue("displayTexture")) { string tex_path = planetary_resource_config_node.GetValue("displayTexture"); resource_info.setDisplayTexture(tex_path); } else { string tex_path = planetary_resource_config_node.GetValue("WarpPlugin/resource_point"); resource_info.setDisplayTexture(tex_path); } if (planetary_resource_config_node.HasValue("displayThreshold")) { string display_threshold_str = planetary_resource_config_node.GetValue("displayThreshold"); double display_threshold = double.Parse(display_threshold_str); resource_info.setDisplayThreshold(display_threshold); } body_resource_maps.Add(resource_gui_name, resource_info); List<Vector2d> abundance_points_list = new List<Vector2d>(); for (int i = 0; i < map.height; ++i) { for (int j = 0; j < map.width; ++j) { if (getPixelAbundanceValue(j, i, resource_info) >= resource_info.getDisplayThreshold()) { //high value location, mark it double theta = (j - map.width / 2) * 2.0 * 180.0 / map.width; double phi = (i - map.height / 2) * 2.0 * 90.0 / map.height; Vector2d angles = new Vector2d(theta, phi); //body_abudnance_angles.Add(resource_gui_name, angles); abundance_points_list.Add(angles); } } } body_abudnance_angles.Add(resource_gui_name, abundance_points_list.ToArray()); Debug.Log("[ORS] " + abundance_points_list.Count + " high value " + resource_gui_name + " locations detected"); } } }
public static Vector2d Lerp(Vector2d from, Vector2d to, double t) { t = Mathd.Clamp01(t); return(new Vector2d(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t)); }
public void Drive(FlightCtrlState s) { if (useSAS) { _requestedAttitude = attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Quaternion.Euler(90, 0, 0); if (!vessel.ActionGroups[KSPActionGroup.SAS]) { vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); vessel.Autopilot.SAS.LockHeading(_requestedAttitude); lastSAS = _requestedAttitude; } else if (Quaternion.Angle(lastSAS, _requestedAttitude) > 10) { vessel.Autopilot.SAS.LockHeading(_requestedAttitude); lastSAS = _requestedAttitude; } else { vessel.Autopilot.SAS.LockHeading(_requestedAttitude, true); } } else { // Direction we want to be facing _requestedAttitude = attitudeGetReferenceRotation(attitudeReference) * attitudeTarget; Transform vesselTransform = vessel.ReferenceTransform; Quaternion delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vesselTransform.rotation) * _requestedAttitude); Vector3d deltaEuler = delta.DeltaEuler(); // ( MoI / available torque ) factor: Vector3d NormFactor = Vector3d.Scale(vesselState.MoI, torque.Invert()).Reorder(132); // Find out the real shorter way to turn were we wan to. // Thanks to HoneyFox Vector3d tgtLocalUp = vesselTransform.transform.rotation.Inverse() * _requestedAttitude * Vector3d.forward; Vector3d curLocalUp = Vector3d.up; double turnAngle = Math.Abs(Vector3d.Angle(curLocalUp, tgtLocalUp)); Vector2d rotDirection = new Vector2d(tgtLocalUp.x, tgtLocalUp.z); rotDirection = rotDirection.normalized * turnAngle / 180.0; // And the lowest roll // Thanks to Crzyrndm Vector3 normVec = Vector3.Cross(_requestedAttitude * Vector3.forward, vesselTransform.up); Quaternion targetDeRotated = Quaternion.AngleAxis((float)turnAngle, normVec) * _requestedAttitude; float rollError = Vector3.Angle(vesselTransform.right, targetDeRotated * Vector3.right) * Math.Sign(Vector3.Dot(targetDeRotated * Vector3.right, vesselTransform.forward)); error = new Vector3d( -rotDirection.y * Math.PI, rotDirection.x * Math.PI, rollError * Mathf.Deg2Rad ); error.Scale(_axisControl); Vector3d err = error + inertia.Reorder(132) / 2d; err = new Vector3d( Math.Max(-Math.PI, Math.Min(Math.PI, err.x)), Math.Max(-Math.PI, Math.Min(Math.PI, err.y)), Math.Max(-Math.PI, Math.Min(Math.PI, err.z))); err.Scale(NormFactor); // angular velocity: Vector3d omega; omega.x = vessel.angularVelocity.x; omega.y = vessel.angularVelocity.z; // y <=> z omega.z = vessel.angularVelocity.y; // z <=> y omega.Scale(NormFactor); if (Tf_autoTune) tuneTf(torque); setPIDParameters(); // angular velocity limit: var Wlimit = new Vector3d(Math.Sqrt(NormFactor.x * Math.PI * kWlimit), Math.Sqrt(NormFactor.y * Math.PI * kWlimit), Math.Sqrt(NormFactor.z * Math.PI * kWlimit)); pidAction = pid.Compute(err, omega, Wlimit); // deadband pidAction.x = Math.Abs(pidAction.x) >= deadband ? pidAction.x : 0.0f; pidAction.y = Math.Abs(pidAction.y) >= deadband ? pidAction.y : 0.0f; pidAction.z = Math.Abs(pidAction.z) >= deadband ? pidAction.z : 0.0f; // low pass filter, wf = 1/Tf: Vector3d act = lastAct; act.x += (pidAction.x - lastAct.x) * (1.0 / ((TfV.x / TimeWarp.fixedDeltaTime) + 1.0)); act.y += (pidAction.y - lastAct.y) * (1.0 / ((TfV.y / TimeWarp.fixedDeltaTime) + 1.0)); act.z += (pidAction.z - lastAct.z) * (1.0 / ((TfV.z / TimeWarp.fixedDeltaTime) + 1.0)); lastAct = act; SetFlightCtrlState(act, deltaEuler, s, 1); act = new Vector3d(s.pitch, s.yaw, s.roll); // Feed the control torque to the differential throttle } }
public void Scale(Vector2d scale) { this.x *= scale.x; this.y *= scale.y; }
internal static bool LineSegmentIntersection(Vector2d p1, Vector2d p2, Vector2d p3, Vector2d p4, ref Vector2d result) { double num1 = p2.x - p1.x; double num2 = p2.y - p1.y; double num3 = p4.x - p3.x; double num4 = p4.y - p3.y; double num5 = (num1 * num4 - num2 * num3); if (num5 == 0.0d) return false; double num6 = p3.x - p1.x; double num7 = p3.y - p1.y; double num8 = (num6 * num4 - num7 * num3) / num5; if (num8 < 0.0d || num8 > 1.0d) return false; double num9 = (num6 * num2 - num7 * num1) / num5; if (num9 < 0.0d || num9 > 1.0d) return false; result = new Vector2d(p1.x + num8 * num1, p1.y + num8 * num2); return true; }
private static bool GetPositionAtT(Vessel thatVessel, Orbit thatOrbit, double initial, double timePoint, out Vector2d coordinates, out bool collision) { coordinates = Vector2d.zero; collision = false; if (double.IsNaN(thatOrbit.getObtAtUT(initial + timePoint))) return false; double rotOffset = 0; if (thatVessel.mainBody.rotates) { rotOffset = (360 * ((timePoint - initial) / thatVessel.mainBody.rotationPeriod)) % 360; } Vector3d pos = thatOrbit.getPositionAtUT(timePoint); if (thatOrbit.Radius(timePoint) < thatVessel.mainBody.Radius + thatVessel.mainBody.getElevation(pos)) { collision = true; return false; } coordinates = new Vector2d(thatVessel.mainBody.GetLongitude(pos) - rotOffset, thatVessel.mainBody.GetLatitude(pos)); return true; }
internal override void Awake() { TooltipMouseOffset = new Vector2d(-10, 10); onWindowMoveComplete += ARPWindow_onWindowMoveComplete; }
private void DrawTrail(IList<Vector2d> points, Color32 lineColor, Vector2d endPoint, bool hasEndpoint = false) { if (points.Count < 2) return; GL.Begin(GL.LINES); trailMaterial.SetPass(0); GL.Color(lineColor); float xStart, yStart; // actualMapWidth is the width of the virtual map (accounting for // zoom level). We use this value to determine if a particular // line segment wraps around from the right edge to the left edge. // We compute the value once here, instead of doing it every single // segment. float actualMapWidth = (float)mapSizeScale.x * screenWidth; xStart = (float)longitudeToPixels(points[0].x, points[0].y); yStart = (float)latitudeToPixels(points[0].x, points[0].y); for (int i = 1; i < points.Count; i++) { float xEnd = (float)longitudeToPixels(points[i].x, points[i].y); float yEnd = (float)latitudeToPixels(points[i].x, points[i].y); DrawLine(xStart, yStart, xEnd, yEnd, screenSpace, actualMapWidth); xStart = xEnd; yStart = yEnd; } if (hasEndpoint) DrawLine(xStart, yStart, (float)longitudeToPixels(endPoint.x, endPoint.y), (float)latitudeToPixels(endPoint.x, endPoint.y), screenSpace, actualMapWidth); GL.End(); }
// Estimate the delta-V of the correction burn that would be required to put us on // course for the target public Vector3d ComputeCourseCorrection(bool allowPrograde) { // actualLandingPosition is the predicted actual landing position Vector3d actualLandingPosition = RotatedLandingSite - mainBody.position; // orbitLandingPosition is the point where our current orbit intersects the planet double endRadius = mainBody.Radius + DecelerationEndAltitude() - 100; // Seems we are already landed ? if (endRadius > orbit.ApR || vessel.LandedOrSplashed) StopLanding(); Vector3d orbitLandingPosition; if (orbit.PeR < endRadius) orbitLandingPosition = orbit.SwappedRelativePositionAtUT(orbit.NextTimeOfRadius(vesselState.time, endRadius)); else orbitLandingPosition = orbit.SwappedRelativePositionAtUT(orbit.NextPeriapsisTime(vesselState.time)); // convertOrbitToActual is a rotation that rotates orbitLandingPosition on actualLandingPosition Quaternion convertOrbitToActual = Quaternion.FromToRotation(orbitLandingPosition, actualLandingPosition); // Consider the effect small changes in the velocity in each of these three directions Vector3d[] perturbationDirections = { vesselState.surfaceVelocity.normalized, vesselState.radialPlusSurface, vesselState.normalPlusSurface }; // Compute the effect burns in these directions would // have on the landing position, where we approximate the landing position as the place // the perturbed orbit would intersect the planet. Vector3d[] deltas = new Vector3d[3]; for (int i = 0; i < 3; i++) { const double perturbationDeltaV = 1; //warning: hard experience shows that setting this too low leads to bewildering bugs due to finite precision of Orbit functions Orbit perturbedOrbit = orbit.PerturbedOrbit(vesselState.time, perturbationDeltaV * perturbationDirections[i]); //compute the perturbed orbit double perturbedLandingTime; if (perturbedOrbit.PeR < endRadius) perturbedLandingTime = perturbedOrbit.NextTimeOfRadius(vesselState.time, endRadius); else perturbedLandingTime = perturbedOrbit.NextPeriapsisTime(vesselState.time); Vector3d perturbedLandingPosition = perturbedOrbit.SwappedRelativePositionAtUT(perturbedLandingTime); //find where it hits the planet Vector3d landingDelta = perturbedLandingPosition - orbitLandingPosition; //find the difference between that and the original orbit's intersection point landingDelta = convertOrbitToActual * landingDelta; //rotate that difference vector so that we can now think of it as starting at the actual landing position landingDelta = Vector3d.Exclude(actualLandingPosition, landingDelta); //project the difference vector onto the plane tangent to the actual landing position deltas[i] = landingDelta / perturbationDeltaV; //normalize by the delta-V considered, so that deltas now has units of meters per (meter/second) [i.e., seconds] } // Now deltas stores the predicted offsets in landing position produced by each of the three perturbations. // We now figure out the offset we actually want // First we compute the target landing position. We have to convert the latitude and longitude of the target // into a position. We can't just get the current position of those coordinates, because the planet will // rotate during the descent, so we have to account for that. Vector3d desiredLandingPosition = mainBody.GetRelSurfacePosition(core.target.targetLatitude, core.target.targetLongitude, 0); float bodyRotationAngleDuringDescent = (float)(360 * (prediction.endUT - vesselState.time) / mainBody.rotationPeriod); Quaternion bodyRotationDuringFall = Quaternion.AngleAxis(bodyRotationAngleDuringDescent, mainBody.angularVelocity.normalized); desiredLandingPosition = bodyRotationDuringFall * desiredLandingPosition; Vector3d desiredDelta = desiredLandingPosition - actualLandingPosition; desiredDelta = Vector3d.Exclude(actualLandingPosition, desiredDelta); // Now desiredDelta gives the desired change in our actual landing position (projected onto a plane // tangent to the actual landing position). Vector3d downrangeDirection; Vector3d downrangeDelta; if (allowPrograde) { // Construct the linear combination of the prograde and radial+ perturbations // that produces the largest effect on the landing position. The Math.Sign is to // detect and handle the case where radial+ burns actually bring the landing sign closer // (e.g. when we are traveling close to straight up) downrangeDirection = (deltas[0].magnitude * perturbationDirections[0] + Math.Sign(Vector3d.Dot(deltas[0], deltas[1])) * deltas[1].magnitude * perturbationDirections[1]).normalized; downrangeDelta = Vector3d.Dot(downrangeDirection, perturbationDirections[0]) * deltas[0] + Vector3d.Dot(downrangeDirection, perturbationDirections[1]) * deltas[1]; } else { // If we aren't allowed to burn prograde, downrange component of the landing // position has to be controlled by radial+/- burns: downrangeDirection = perturbationDirections[1]; downrangeDelta = deltas[1]; } // Now solve a 2x2 system of linear equations to determine the linear combination // of perturbationDirection01 and normal+ that will give the desired offset in the // predicted landing position. Matrix2x2 A = new Matrix2x2( downrangeDelta.sqrMagnitude, Vector3d.Dot(downrangeDelta, deltas[2]), Vector3d.Dot(downrangeDelta, deltas[2]), deltas[2].sqrMagnitude ); Vector2d b = new Vector2d(Vector3d.Dot(desiredDelta, downrangeDelta), Vector3d.Dot(desiredDelta, deltas[2])); Vector2d coeffs = A.inverse() * b; Vector3d courseCorrection = coeffs.x * downrangeDirection + coeffs.y * perturbationDirections[2]; return courseCorrection; }
private void RedrawMap() { map = new SCANmap(); map.setProjection(MapProjection.Rectangular); orbitingBody = vessel.mainBody; map.setBody(vessel.mainBody); map.setSize(screenWidth, screenHeight); map.MapScale *= (zoomLevel * zoomLevel + zoomModifier); mapCenterLong = vessel.longitude; mapCenterLat = vessel.latitude; // That's really just sweeping the problem under the carpet instead of fixing it, but meh. if (zoomLevel == 0) mapCenterLat = 0; map.centerAround(mapCenterLong, mapCenterLat); map.resetMap((mapType)mapMode, false); // Compute and store the map scale factors in mapSizeScale. We // use these values for every segment when drawing trails, so it // makes sense to compute it only when it changes. mapSizeScale = new Vector2d(360.0 * map.MapScale / map.MapWidth, 180.0 * map.MapScale / map.MapHeight); redrawDeviation = redrawEdge * 180 / (zoomLevel * zoomLevel + zoomModifier); try { SCANdata data = SCANUtil.getData(vessel.mainBody); if (data != null) { localAnomalies = data.Anomalies; localWaypoints = data.Waypoints; } } catch { Debug.Log("JSISCANsatRPM: Could not get a list of anomalies, what happened?"); } // MATH! double kmPerDegreeLon = (2 * Math.PI * (orbitingBody.Radius / 1000d)) / 360d; double pixelsPerDegree = Math.Abs(longitudeToPixels(mapCenterLong + (((mapCenterLong + 1) > 360) ? -1 : 1), mapCenterLat) - longitudeToPixels(mapCenterLong, mapCenterLat)); pixelsPerKm = pixelsPerDegree / kmPerDegreeLon; }
internal void Startup() { if (!tfScenario.SettingsEnabled) return; Log("Startup"); CalculateWindowBounds(); DragEnabled = !tfScenario.userSettings.editorWindowLocked; WindowMoveEventsEnabled = true; WindowMoveCompleteAfter = 0.1f; ClampToScreen = true; TooltipsEnabled = true; TooltipMouseOffset = new Vector2d(10, 10); TooltipStatic = true; WindowCaption = ""; // StartCoroutine("AddToToolbar"); onWindowMoveComplete += EditorWindow_OnWindowMoveComplete; isReady = true; }
public Vector3d(Vector2d v, double z) { x = v.x; y = v.y; this.z = z; }