Beispiel #1
0
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Quaternion rotRef = Quaternion.identity;

            switch (reference)
            {
            case AttitudeReference.ORBIT:
                rotRef = Quaternion.LookRotation(velocityVesselOrbitNorm, up);
                break;

            case AttitudeReference.ORBIT_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(up, velocityVesselOrbitNorm), up);
                break;

            case AttitudeReference.SURFACE_NORTH:
                rotRef = rotationSurface;
                break;

            case AttitudeReference.SURFACE_VELOCITY:
                rotRef = Quaternion.LookRotation(velocityVesselSurfaceUnit, up);
                break;

            case AttitudeReference.CURFRAME:
                if (vessel.altitude > vessel.mainBody.maxAtmosphereAltitude)
                {
                    rotRef = Quaternion.LookRotation(velocityVesselOrbitNorm, up);
                }
                else
                {
                    rotRef = Quaternion.LookRotation(velocityVesselSurfaceUnit, up);
                }
                break;
            }
            return(rotRef);
        }
Beispiel #2
0
        public void attitudeTo(Vector3d direction, AttitudeReference reference)
        {
            Vector3d up;

            up = attitudeWorldToReference(vessel.ReferenceTransform.rotation * Quaternion.Euler(-90, 0, 0) * Vector3d.up, reference);
            attitudeTo(Quaternion.LookRotation(direction, up), reference);
        }
Beispiel #3
0
        public bool attitudeTo(Vector3d direction, AttitudeReference reference, object controller)
        {
            bool    ok = false;
            double  ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Vector3d.forward, attitudeGetReferenceRotation(reference) * direction));
            Vector3 up, dir = direction;

            if (!enabled || (ang_diff > 45))
            {
                up = attitudeWorldToReference(-vessel.GetTransform().forward, reference);
            }
            else
            {
                up = attitudeWorldToReference(attitudeReferenceToWorld(attitudeTarget * Vector3d.up, attitudeReference), reference);
            }
            Vector3.OrthoNormalize(ref dir, ref up);
            ok = attitudeTo(Quaternion.LookRotation(dir, up), reference, controller);
            if (ok)
            {
                _attitudeRollMatters = false;
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public bool attitudeTo(Quaternion attitude, AttitudeReference reference, object controller, bool AxisCtrlPitch = true, bool AxisCtrlYaw = true, bool AxisCtrlRoll = true)
 {
     users.Add(controller);
     attitudeReference = reference;
     attitudeTarget    = attitude;
     AxisControl(AxisCtrlPitch, AxisCtrlYaw, AxisCtrlRoll);
     return(true);
 }
Beispiel #5
0
 public bool attitudeTo(Quaternion attitude, AttitudeReference reference, object controller)
 {
     users.Add(controller);
     attitudeReference = reference;
     attitudeTarget    = attitude;
     AxisControl(true, true, true);
     return(true);
 }
Beispiel #6
0
        public bool attitudeTo(Quaternion attitude, AttitudeReference reference, object controller)
        {
            users.Add(controller);
            attitudeReference    = reference;
            attitudeTarget       = attitude;
            _attitudeRollMatters = true;

            return(true);
        }
Beispiel #7
0
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3    fwd, up;
            Quaternion rotRef = Quaternion.identity;


            if ((reference == AttitudeReference.MANEUVER_NODE) && (vessel.patchedConicSolver.maneuverNodes.Count == 0))
            {
                attitudeDeactivate();
                return(rotRef);
            }

            switch (reference)
            {
            case AttitudeReference.ORBIT:
                rotRef = Quaternion.LookRotation(vesselState.orbitalVelocity.normalized, vesselState.up);
                break;

            case AttitudeReference.ORBIT_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.orbitalVelocity.normalized), vesselState.up);
                break;

            case AttitudeReference.SURFACE_NORTH:
                rotRef = vesselState.rotationSurface;
                break;

            case AttitudeReference.SURFACE_VELOCITY:
                rotRef = Quaternion.LookRotation(vesselState.surfaceVelocity.normalized, vesselState.up);
                break;

            case AttitudeReference.MANEUVER_NODE:
                fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.SUN:
                Orbit baseOrbit = vessel.mainBody == Planetarium.fetch.Sun ? vessel.orbit : orbit.TopParentOrbit();
                up     = vesselState.CoM - Planetarium.fetch.Sun.transform.position;
                fwd    = Vector3d.Cross(-baseOrbit.GetOrbitNormal().Reorder(132).normalized, up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.SURFACE_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.surfaceVelocity.normalized), vesselState.up);
                break;
            }
            return(rotRef);
        }
Beispiel #8
0
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3d fwd, up;

            switch (reference)
            {
            case AttitudeReference.INERTIAL:
                return(Quaternion.identity);

            case AttitudeReference.ORBIT:
                return(Quaternion.LookRotation(vessel.GetObtVelocity(), vessel.up));

            case AttitudeReference.ORBIT_HORIZONTAL:
                return(Quaternion.LookRotation(Vector3d.Exclude(vessel.up, vessel.GetObtVelocity()), vessel.up));

            case AttitudeReference.SURFACE_NORTH:
                return(vesselState.rotationSurface);

            case AttitudeReference.SURFACE_VELOCITY:
                return(Quaternion.LookRotation(vesselState.surfaceVelocity.normalized, vesselState.up));

            case AttitudeReference.TARGET:
                fwd = FlightGlobals.fetch.VesselTarget.GetTransform().position - vessel.GetTransform().position;
                up  = Vector3.Cross(fwd, vesselState.normalPlus);
                return(Quaternion.LookRotation(fwd, up));

            /* case AttitudeReference.RELATIVE_VELOCITY:
             *  throw new Exception("RELATIVE_VELOCTY unimplemented");
             * case AttitudeReference.TARGET_ORIENTATION:
             *  throw new Exception("TARGET_ORIENTATION unimplemented"); */
            case AttitudeReference.MANEUVER_NODE:
                fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                up  = Vector3.Cross(fwd, vesselState.normalPlus);
                return(Quaternion.LookRotation(fwd, up));

            case AttitudeReference.SUN:
                Orbit baseOrbit = vessel.mainBody == Planetarium.fetch.Sun ? vessel.orbit : orbit.TopParentOrbit();
                up  = vessel.CoMD - Planetarium.fetch.Sun.transform.position;
                fwd = Vector3d.Cross(-baseOrbit.GetOrbitNormal().xzy.normalized, up);
                return(Quaternion.LookRotation(fwd, up));

            case AttitudeReference.SURFACE_HORIZONTAL:
                return(Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vessel.srf_velocity.normalized), vesselState.up));

            default:
                return(Quaternion.identity);
            }
        }
Beispiel #9
0
        public Quaternion Direction(Vector3d d, AttitudeReference referer)
        {
            double  ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(referer) * Target * Vector3d.forward, attitudeGetReferenceRotation(referer) * d));
            Vector3 up, dir = d;

            if ((ang_diff > 45))
            {
                up = attitudeWorldToReference(-vessel.ReferenceTransform.forward, referer);
            }
            else
            {
                up = attitudeWorldToReference(attitudeReferenceToWorld(Target * Vector3d.up, Reference), referer);
            }
            Vector3.OrthoNormalize(ref dir, ref up);
            return(Quaternion.LookRotation(dir, up));
        }
 override public void activateAction()
 {
     base.activateAction();
     this.smartAss.mode         = Target2Mode[(int)target];
     this.smartAss.target       = target;
     this.smartAss.srfHdg       = this.srfHdg;
     this.smartAss.srfPit       = this.srfPit;
     this.smartAss.srfRol       = this.srfRol;
     this.smartAss.srfVelYaw    = this.srfVelYaw;
     this.smartAss.srfVelPit    = this.srfVelPit;
     this.smartAss.srfVelRol    = this.srfVelRol;
     this.smartAss.rol          = this.rol;
     this.smartAss.advReference = this.advReference;
     this.smartAss.advDirection = this.advDirection;
     this.smartAss.forceRol     = this.forceRol;
     this.smartAss.forcePitch   = this.forcePitch;
     this.smartAss.forceYaw     = this.forceYaw;
     this.smartAss.Engage();
 }
Beispiel #11
0
        public bool attitudeTo(Vector3d direction, AttitudeReference reference, object controller)
        {
            //double ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(reference) * direction, vesselState.forward));
            double ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Vector3d.forward, attitudeGetReferenceRotation(reference) * direction));

            Vector3 up, dir = direction;

            // TODO : Fix that so it does not roll when it should not. Current fix is a "hack" that set required roll to 0 if !attitudeRollMatters

            if (!enabled || (ang_diff > 45))
            {
                up = attitudeWorldToReference(-vessel.GetTransform().forward, reference);
            }
            else
            {
                up = attitudeWorldToReference(attitudeReferenceToWorld(attitudeTarget * Vector3d.up, attitudeReference), reference);
            }
            Vector3.OrthoNormalize(ref dir, ref up);
            attitudeTo(Quaternion.LookRotation(dir, up), reference, controller);
            _attitudeRollMatters = false;
            return(true);
        }
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3 fwd, up;
            Quaternion rotRef = Quaternion.identity;

            if (core.target.Target == null && (reference == AttitudeReference.TARGET || reference == AttitudeReference.TARGET_ORIENTATION || reference == AttitudeReference.RELATIVE_VELOCITY))
            {
                attitudeDeactivate();
                return rotRef;
            }

            if ((reference == AttitudeReference.MANEUVER_NODE) && (vessel.patchedConicSolver.maneuverNodes.Count == 0))
            {
                attitudeDeactivate();
                return rotRef;
            }

            switch (reference)
            {
                case AttitudeReference.ORBIT:
                    rotRef = Quaternion.LookRotation(vesselState.orbitalVelocity.normalized, vesselState.up);
                    break;
                case AttitudeReference.ORBIT_HORIZONTAL:
                    rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.orbitalVelocity.normalized), vesselState.up);
                    break;
                case AttitudeReference.SURFACE_NORTH:
                    rotRef = vesselState.rotationSurface;
                    break;
                case AttitudeReference.SURFACE_VELOCITY:
                    rotRef = Quaternion.LookRotation(vesselState.surfaceVelocity.normalized, vesselState.up);
                    break;
                case AttitudeReference.TARGET:
                    fwd = (core.target.Position - vessel.GetTransform().position).normalized;
                    up = Vector3d.Cross(fwd, vesselState.normalPlus);
                    Vector3.OrthoNormalize(ref fwd, ref up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.RELATIVE_VELOCITY:
                    fwd = core.target.RelativeVelocity.normalized;
                    up = Vector3d.Cross(fwd, vesselState.normalPlus);
                    Vector3.OrthoNormalize(ref fwd, ref up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.TARGET_ORIENTATION:
                    Transform targetTransform = core.target.Transform;
                    if (core.target.CanAlign)
                    {
                        rotRef = Quaternion.LookRotation(targetTransform.forward, targetTransform.up);
                    }
                    else
                    {
                        rotRef = Quaternion.LookRotation(targetTransform.up, targetTransform.right);
                    }
                    break;
                case AttitudeReference.MANEUVER_NODE:
                    fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                    up = Vector3d.Cross(fwd, vesselState.normalPlus);
                    Vector3.OrthoNormalize(ref fwd, ref up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.SUN:
                    Orbit baseOrbit = vessel.mainBody == Planetarium.fetch.Sun ? vessel.orbit : orbit.TopParentOrbit();
                    up = vesselState.CoM - Planetarium.fetch.Sun.transform.position;
                    fwd = Vector3d.Cross(-baseOrbit.GetOrbitNormal().Reorder(132).normalized, up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.SURFACE_HORIZONTAL:
                    rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.surfaceVelocity.normalized), vesselState.up);
                    break;
            }
            return rotRef;
        }
Beispiel #13
0
 public Vector3d attitudeReferenceToWorld(Vector3d vector, AttitudeReference reference)
 {
     return(attitudeGetReferenceRotation(reference) * vector);
 }
Beispiel #14
0
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3    fwd, up;
            Quaternion rotRef = Quaternion.identity;

            if (core.target.Target == null && (reference == AttitudeReference.TARGET || reference == AttitudeReference.TARGET_ORIENTATION || reference == AttitudeReference.RELATIVE_VELOCITY))
            {
                attitudeDeactivate();
                return(rotRef);
            }

            if ((reference == AttitudeReference.MANEUVER_NODE) && (vessel.patchedConicSolver.maneuverNodes.Count == 0))
            {
                attitudeDeactivate();
                return(rotRef);
            }

            switch (reference)
            {
            case AttitudeReference.ORBIT:
                rotRef = Quaternion.LookRotation(vesselState.orbitalVelocity.normalized, vesselState.up);
                break;

            case AttitudeReference.ORBIT_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.orbitalVelocity.normalized), vesselState.up);
                break;

            case AttitudeReference.SURFACE_NORTH:
                rotRef = vesselState.rotationSurface;
                break;

            case AttitudeReference.SURFACE_VELOCITY:
                rotRef = Quaternion.LookRotation(vesselState.surfaceVelocity.normalized, vesselState.up);
                break;

            case AttitudeReference.TARGET:
                fwd = (core.target.Position - vessel.GetTransform().position).normalized;
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.RELATIVE_VELOCITY:
                fwd = core.target.RelativeVelocity.normalized;
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.TARGET_ORIENTATION:
                Transform targetTransform = core.target.Transform;
                if (core.target.CanAlign)
                {
                    rotRef = Quaternion.LookRotation(targetTransform.forward, targetTransform.up);
                }
                else
                {
                    rotRef = Quaternion.LookRotation(targetTransform.up, targetTransform.right);
                }
                break;

            case AttitudeReference.MANEUVER_NODE:
                fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.SUN:
                Orbit baseOrbit = vessel.mainBody == Planetarium.fetch.Sun ? vessel.orbit : orbit.TopParentOrbit();
                up     = vesselState.CoM - Planetarium.fetch.Sun.transform.position;
                fwd    = Vector3d.Cross(-baseOrbit.GetOrbitNormal().Reorder(132).normalized, up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.SURFACE_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.surfaceVelocity.normalized), vesselState.up);
                break;
            }
            return(rotRef);
        }
Beispiel #15
0
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor   = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor    = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding            = new RectOffset(8, 8, 8, 8);

                btActive           = new GUIStyle(btNormal);
                btActive.active    = btActive.onActive;
                btActive.normal    = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover     = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive         = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            // If any other module use the attitude controler then let them do it
            if (core.attitude.enabled && core.attitude.users.Count(u => !this.Equals(u)) > 0)
            {
                if (autoDisableSmartASS)
                {
                    target = Target.OFF;
                    if (core.attitude.users.Contains(this))
                    {
                        core.attitude.users.Remove(this);                                     // so we don't suddenly turn on when the other autopilot finishes
                    }
                }
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                if (vessel.patchedConicsUnlocked())
                {
                    TargetButton(Target.NODE);
                }
                else
                {
                    GUILayout.Button("-", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                }
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                case Mode.ORBITAL:

                    GUILayout.BeginHorizontal();
                    TargetButton(Target.PROGRADE);
                    TargetButton(Target.NORMAL_PLUS);
                    TargetButton(Target.RADIAL_PLUS);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.RETROGRADE);
                    TargetButton(Target.NORMAL_MINUS);
                    TargetButton(Target.RADIAL_MINUS);
                    GUILayout.EndHorizontal();

                    ForceRoll();

                    break;

                case Mode.SURFACE:
                    double val = (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1);     // change by 5 if the mod_key is held down, else by 1
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.SURFACE_PROGRADE);
                    TargetButton(Target.SURFACE_RETROGRADE);
                    TargetButtonNoEngage(Target.SURFACE);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.HORIZONTAL_PLUS);
                    TargetButton(Target.HORIZONTAL_MINUS);
                    TargetButton(Target.VERTICAL_PLUS);
                    GUILayout.EndHorizontal();
                    if (target == Target.SURFACE)
                    {
                        bool changed = false;
                        GUILayout.BeginHorizontal();
                        forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("HDG", srfHdg, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfHdg -= val;
                            changed = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfHdg += val;
                            changed = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfHdg  = 0;
                            changed = true;
                        }
                        if (GUILayout.Button("90", GUILayout.Width(35)))
                        {
                            srfHdg  = 90;
                            changed = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("PIT", srfPit, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfPit -= val;
                            changed = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfPit += val;
                            changed = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfPit  = 0;
                            changed = true;
                        }
                        if (GUILayout.Button("90", GUILayout.Width(35)))
                        {
                            srfPit  = 90;
                            changed = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("ROL", srfRol, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfRol -= val;
                            changed = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfRol += val;
                            changed = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfRol  = 0;
                            changed = true;
                        }
                        if (GUILayout.Button("180", GUILayout.Width(35)))
                        {
                            srfRol  = 180;
                            changed = true;
                        }
                        GUILayout.EndHorizontal();
                        if (GUILayout.Button("EXECUTE"))
                        {
                            Engage();
                        }
                        if (changed)
                        {
                            Engage(false);
                        }
                        core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                    }
                    else if (target == Target.SURFACE_PROGRADE || target == Target.SURFACE_RETROGRADE)
                    {
                        bool changed = false;
                        GUILayout.BeginHorizontal();
                        forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("ROL", srfVelRol, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol -= val;
                            changed    = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol += val;
                            changed    = true;
                        }
                        if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol = -vesselState.vesselRoll.value;
                            changed   = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfVelRol = 0;
                            changed   = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("PIT", srfVelPit, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit -= val;
                            changed    = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit += val;
                            changed    = true;
                        }
                        if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit = vesselState.AoA.value;
                            changed   = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfVelPit = 0;
                            changed   = true;
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                        GuiUtils.SimpleTextBox("YAW", srfVelYaw, "°", 37);
                        if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw -= val;
                            changed    = true;
                        }
                        if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw += val;
                            changed    = true;
                        }
                        if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw = -vesselState.AoS.value;
                            changed   = true;
                        }
                        if (GUILayout.Button("0", GUILayout.ExpandWidth(false)))
                        {
                            srfVelYaw = 0;
                            changed   = true;
                        }
                        GUILayout.EndHorizontal();
                        if (GUILayout.Button("EXECUTE"))
                        {
                            Engage();
                        }
                        if (changed)
                        {
                            Engage(false);
                        }
                        core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                    }
                    break;

                case Mode.TARGET:
                    if (core.target.NormalTargetExists)
                    {
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_PLUS);
                        TargetButton(Target.RELATIVE_PLUS);
                        TargetButton(Target.PARALLEL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_MINUS);
                        TargetButton(Target.RELATIVE_MINUS);
                        TargetButton(Target.PARALLEL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();
                    }
                    else
                    {
                        GUILayout.Label("Please select a target");
                    }
                    break;

                case Mode.ADVANCED:
                    GUILayout.Label("Reference:");
                    advReference = (AttitudeReference)GuiUtils.ComboBox.Box((int)advReference, ReferenceTexts, this);

                    GUILayout.Label("Direction:");
                    advDirection = (Vector6.Direction)GuiUtils.ComboBox.Box((int)advDirection, directionTexts, directionTexts);

                    ForceRoll();

                    if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                    {
                        target = Target.ADVANCED;
                        Engage();
                    }
                    break;

                case Mode.AUTO:
                    break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }
 public bool attitudeTo(Quaternion attitude, AttitudeReference reference, object controller)
 {
     //users.Add(controller);
     attitudeReference = reference;
     attitudeTarget = attitude;
     AxisControl(true, true, true);
     return true;
 }
 public Vector3d attitudeWorldToReference(Vector3d vector, AttitudeReference reference)
 {
     return Quaternion.Inverse(attitudeGetReferenceRotation(reference)) * vector;
 }
Beispiel #18
0
 public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
 {
     Quaternion rotRef = Quaternion.identity;
     switch (reference)
     {
         case AttitudeReference.ORBIT:
             rotRef = Quaternion.LookRotation(vesselState.velocityVesselOrbitUnit, vesselState.up);
             break;
         case AttitudeReference.ORBIT_HORIZONTAL:
             rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.velocityVesselOrbitUnit), vesselState.up);
             break;
         case AttitudeReference.SURFACE_NORTH:
             rotRef = vesselState.rotationSurface;
             break;
         case AttitudeReference.SURFACE_VELOCITY:
             rotRef = Quaternion.LookRotation(vesselState.velocityVesselSurfaceUnit, vesselState.up);
             break;
         case AttitudeReference.TARGET:
             switch (targetType)
             {
                 case TargetType.VESSEL:
                     rotRef = Quaternion.LookRotation((targetVessel.findWorldCenterOfMass() - vesselState.CoM).normalized, -part.vessel.transform.forward);
                     break;
                 case TargetType.BODY:
                     rotRef = Quaternion.LookRotation((targetBody.position - vesselState.CoM).normalized, -part.vessel.transform.forward);
                     break;
             }
             break;
     }
     return rotRef;
 }
Beispiel #19
0
        public bool attitudeTo(Quaternion attitude, AttitudeReference reference, ComputerModule controller)
        {
            if ((controlModule != null) && (controller != null) && (controlModule != controller))
            {
                return false;
            }

            attitudeReference = reference;
            attitudeTarget = attitude;
            _attitudeActive = true;
            _attitudeRollMatters = true;

            return true;
        }
Beispiel #20
0
 public Quaternion Direction(Vector3d d, AttitudeReference referer)
 {
     double ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(referer) * Target * Vector3d.forward, attitudeGetReferenceRotation(referer) * d));
     Vector3 up, dir = d;
     if ((ang_diff > 45))
     {
         up = attitudeWorldToReference(-vessel.ReferenceTransform.forward, referer);
     }
     else
     {
         up = attitudeWorldToReference(attitudeReferenceToWorld(Target * Vector3d.up, Reference), referer);
     }
     Vector3.OrthoNormalize(ref dir, ref up);
     return Quaternion.LookRotation(dir, up);
 }
Beispiel #21
0
 public void SetMode(AttitudeMode mode, AttitudeButtonState input)
 {
     this.attitideActive = input.Active;
     if (!input.Active)
     {
         return;
     }
     switch (mode)
     {
         case AttitudeMode.MANEUVERNODE:
             if (input.MN != Quaternion.identity)
             {
                 Target = input.MN;
                 Reference = AttitudeReference.INERTIAL;
             }
             else
             {
                 Target = Quaternion.LookRotation(vessel.ReferenceTransform.up, -vessel.ReferenceTransform.forward);
                 Reference = AttitudeReference.INERTIAL;
             }
             break;
         case AttitudeMode.KILLROT:
             Target = Quaternion.LookRotation(vessel.ReferenceTransform.up, -vessel.ReferenceTransform.forward);
             Reference = AttitudeReference.INERTIAL;
             break;
         case AttitudeMode.PROGRADE:
             Target = Direction(Vector3d.forward, AttitudeReference.ORBIT);
             Reference = AttitudeReference.ORBIT;
             break;
         case AttitudeMode.RETROGRADE:
             Target = Direction(Vector3d.back, AttitudeReference.ORBIT);
             Reference = AttitudeReference.ORBIT;
             break;
         case AttitudeMode.SRF_PROGRADE:
             Target = Direction(Vector3d.forward, AttitudeReference.SURFACE_VELOCITY);
             Reference = AttitudeReference.SURFACE_VELOCITY;
             break;
         case AttitudeMode.SRF_RETROGRADE:
             Target = Direction(Vector3d.back, AttitudeReference.SURFACE_VELOCITY);
             Reference = AttitudeReference.SURFACE_VELOCITY;
             break;
         case AttitudeMode.NORMAL_PLUS:
             Target = Direction(Vector3d.left, AttitudeReference.ORBIT);
             Reference = AttitudeReference.ORBIT;
             break;
         case AttitudeMode.NORMAL_MINUS:
             Target = Direction(Vector3d.right, AttitudeReference.ORBIT);
             Reference = AttitudeReference.ORBIT;
             break;
         case AttitudeMode.RADIAL_PLUS:
             Target = Direction(Vector3d.up, AttitudeReference.ORBIT);
             Reference = AttitudeReference.ORBIT;
             break;
         case AttitudeMode.RADIAL_MINUS:
             Target = Direction(Vector3d.down, AttitudeReference.ORBIT);
             Reference = AttitudeReference.ORBIT;
             break;
         case AttitudeMode.SURFACE:
             if (input.USEROL)
                 Target = Quaternion.AngleAxis(input.HDG, Vector3.up) * Quaternion.AngleAxis(-input.PIT, Vector3.right) * Quaternion.AngleAxis(-input.ROL, Vector3.forward);
             else
                 Target = Direction(Quaternion.AngleAxis(input.HDG, Vector3.up) * Quaternion.AngleAxis(-input.PIT, Vector3.right) * Vector3d.forward, AttitudeReference.SURFACE_NORTH);
             Reference = AttitudeReference.SURFACE_NORTH;
             break;
     }
 }
Beispiel #22
0
 public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
 {
     Quaternion rotRef = Quaternion.identity;
     switch (reference)
     {
         case AttitudeReference.ORBIT:
             rotRef = Quaternion.LookRotation(velocityVesselOrbitNorm, up);
             break;
         case AttitudeReference.ORBIT_HORIZONTAL:
             rotRef = Quaternion.LookRotation(Vector3d.Exclude(up, velocityVesselOrbitNorm), up);
             break;
         case AttitudeReference.SURFACE_NORTH:
             rotRef = rotationSurface;
             break;
         case AttitudeReference.SURFACE_VELOCITY:
             rotRef = Quaternion.LookRotation(velocityVesselSurfaceUnit, up);
             break;
         case AttitudeReference.CURFRAME:
             if(vessel.altitude > vessel.mainBody.maxAtmosphereAltitude)
                 rotRef = Quaternion.LookRotation(velocityVesselOrbitNorm, up);
             else
                 rotRef = Quaternion.LookRotation(velocityVesselSurfaceUnit, up);
             break;
     }
     return rotRef;
 }
        public bool attitudeTo(Vector3d direction, AttitudeReference reference, object controller)
        {
            //double ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(reference) * direction, vesselState.forward));
            double ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Vector3d.forward, attitudeGetReferenceRotation(reference) * direction));

            Vector3 up, dir = direction;

            // TODO : Fix that so it does not roll when it should not. Current fix is a "hack" that set required roll to 0 if !attitudeRollMatters

            if (!enabled || (ang_diff > 45))
            {
                up = attitudeWorldToReference(-vessel.GetTransform().forward, reference);
            }
            else
            {
                up = attitudeWorldToReference(attitudeReferenceToWorld(attitudeTarget * Vector3d.up, attitudeReference), reference);
            }
            Vector3.OrthoNormalize(ref dir, ref up);
            attitudeTo(Quaternion.LookRotation(dir, up), reference, controller);
            _attitudeRollMatters = false;
            return true;
        }
        public bool attitudeTo(Quaternion attitude, AttitudeReference reference, object controller)
        {
            users.Add(controller);
            attitudeReference = reference;
            attitudeTarget = attitude;
            _attitudeRollMatters = true;

            return true;
        }
Beispiel #25
0
        public void SetMode(AttitudeMode mode, AttitudeButtonState input)
        {
            this.attitideActive = input.Active;
            if (!input.Active)
            {
                return;
            }
            switch (mode)
            {
            case AttitudeMode.MANEUVERNODE:
                if (input.MN != Quaternion.identity)
                {
                    Target    = input.MN;
                    Reference = AttitudeReference.INERTIAL;
                }
                else
                {
                    Target    = Quaternion.LookRotation(vessel.ReferenceTransform.up, -vessel.ReferenceTransform.forward);
                    Reference = AttitudeReference.INERTIAL;
                }
                break;

            case AttitudeMode.KILLROT:
                Target    = Quaternion.LookRotation(vessel.ReferenceTransform.up, -vessel.ReferenceTransform.forward);
                Reference = AttitudeReference.INERTIAL;
                break;

            case AttitudeMode.PROGRADE:
                Target    = Direction(Vector3d.forward, AttitudeReference.ORBIT);
                Reference = AttitudeReference.ORBIT;
                break;

            case AttitudeMode.RETROGRADE:
                Target    = Direction(Vector3d.back, AttitudeReference.ORBIT);
                Reference = AttitudeReference.ORBIT;
                break;

            case AttitudeMode.SRF_PROGRADE:
                Target    = Direction(Vector3d.forward, AttitudeReference.SURFACE_VELOCITY);
                Reference = AttitudeReference.SURFACE_VELOCITY;
                break;

            case AttitudeMode.SRF_RETROGRADE:
                Target    = Direction(Vector3d.back, AttitudeReference.SURFACE_VELOCITY);
                Reference = AttitudeReference.SURFACE_VELOCITY;
                break;

            case AttitudeMode.NORMAL_PLUS:
                Target    = Direction(Vector3d.left, AttitudeReference.ORBIT);
                Reference = AttitudeReference.ORBIT;
                break;

            case AttitudeMode.NORMAL_MINUS:
                Target    = Direction(Vector3d.right, AttitudeReference.ORBIT);
                Reference = AttitudeReference.ORBIT;
                break;

            case AttitudeMode.RADIAL_PLUS:
                Target    = Direction(Vector3d.up, AttitudeReference.ORBIT);
                Reference = AttitudeReference.ORBIT;
                break;

            case AttitudeMode.RADIAL_MINUS:
                Target    = Direction(Vector3d.down, AttitudeReference.ORBIT);
                Reference = AttitudeReference.ORBIT;
                break;

            case AttitudeMode.SURFACE:
                if (input.USEROL)
                {
                    Target = Quaternion.AngleAxis(input.HDG, Vector3.up) * Quaternion.AngleAxis(-input.PIT, Vector3.right) * Quaternion.AngleAxis(-input.ROL, Vector3.forward);
                }
                else
                {
                    Target = Direction(Quaternion.AngleAxis(input.HDG, Vector3.up) * Quaternion.AngleAxis(-input.PIT, Vector3.right) * Vector3d.forward, AttitudeReference.SURFACE_NORTH);
                }
                Reference = AttitudeReference.SURFACE_NORTH;
                break;
            }
        }
Beispiel #26
0
 public bool attitudeTo(Vector3d direction, AttitudeReference reference, ComputerModule controller)
 {
     bool ok = false;
     double ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Vector3d.forward, attitudeGetReferenceRotation(reference) * direction));
     if (!attitudeActive || (ang_diff > 45))
     {
         ok = attitudeTo(Quaternion.LookRotation(direction, attitudeWorldToReference(-part.vessel.transform.forward, reference)), reference, controller);
     }
     else
     {
         ok = attitudeTo(Quaternion.LookRotation(direction, attitudeWorldToReference(attitudeReferenceToWorld(attitudeTarget * Vector3d.up, attitudeReference), reference)), reference, controller);
     }
     if (ok)
     {
         _attitudeRollMatters = false;
         return true;
     }
     else
     {
         return false;
     }
 }
Beispiel #27
0
 public void attitudeTo(Quaternion attitude, AttitudeReference reference)
 {
     Enable();
     this.attitude  = attitude;
     this.reference = reference;
 }
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3    fwd, up;
            Quaternion rotRef = Quaternion.identity;

            if (core.target.Target == null && (reference == AttitudeReference.TARGET || reference == AttitudeReference.TARGET_ORIENTATION || reference == AttitudeReference.RELATIVE_VELOCITY))
            {
                attitudeDeactivate();
                return(rotRef);
            }

            if ((reference == AttitudeReference.MANEUVER_NODE) && (vessel.patchedConicSolver.maneuverNodes.Count == 0))
            {
                attitudeDeactivate();
                return(rotRef);
            }

            switch (reference)
            {
            case AttitudeReference.ORBIT:
                rotRef = Quaternion.LookRotation(vessel.obt_velocity.normalized, vesselState.up);
                break;

            case AttitudeReference.ORBIT_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vessel.obt_velocity.normalized), vesselState.up);
                break;

            case AttitudeReference.SURFACE_NORTH:
                rotRef = vesselState.rotationSurface;
                break;

            case AttitudeReference.SURFACE_VELOCITY:
                rotRef = Quaternion.LookRotation(vessel.srf_velocity.normalized, vesselState.up);
                break;

            case AttitudeReference.TARGET:
                fwd = (core.target.Position - vessel.GetTransform().position).normalized;
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.RELATIVE_VELOCITY:
                fwd = core.target.RelativeVelocity.normalized;
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.TARGET_ORIENTATION:
                Transform targetTransform = core.target.Transform;
                if (core.target.Target is ModuleDockingNode)
                {
                    rotRef = Quaternion.LookRotation(targetTransform.forward, targetTransform.up);
                }
                else
                {
                    rotRef = Quaternion.LookRotation(targetTransform.up, targetTransform.right);
                }
                break;

            case AttitudeReference.MANEUVER_NODE:
                fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;
            }
            return(rotRef);
        }
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3 fwd, up;
            Quaternion rotRef = Quaternion.identity;


            if ((reference == AttitudeReference.MANEUVER_NODE) && (vessel.patchedConicSolver.maneuverNodes.Count == 0))
            {
                attitudeDeactivate();
                return rotRef;
            }

            switch (reference)
            {
                case AttitudeReference.ORBIT:
                    rotRef = Quaternion.LookRotation(vesselState.orbitalVelocity.normalized, vesselState.up);
                    break;
                case AttitudeReference.ORBIT_HORIZONTAL:
                    rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.orbitalVelocity.normalized), vesselState.up);
                    break;
                case AttitudeReference.SURFACE_NORTH:
                    rotRef = vesselState.rotationSurface;
                    break;
                case AttitudeReference.SURFACE_VELOCITY:
                    rotRef = Quaternion.LookRotation(vesselState.surfaceVelocity.normalized, vesselState.up);
                    break;
                case AttitudeReference.MANEUVER_NODE:
                    fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                    up = Vector3d.Cross(fwd, vesselState.normalPlus);
                    Vector3.OrthoNormalize(ref fwd, ref up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.SUN:
                    Orbit baseOrbit = vessel.mainBody == Planetarium.fetch.Sun ? vessel.orbit : orbit.TopParentOrbit();
                    up = vesselState.CoM - Planetarium.fetch.Sun.transform.position;
                    fwd = Vector3d.Cross(-baseOrbit.GetOrbitNormal().Reorder(132).normalized, up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.SURFACE_HORIZONTAL:
                    rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.surfaceVelocity.normalized), vesselState.up);
                    break;
            }
            return rotRef;
        }
        override public void WindowGUI(int windowID)
        {
            base.preWindowGUI(windowID);
            base.WindowGUI(windowID);
            int modeSelectorIdx = TargetIsMode[(int)target]
                                ? targetModeSelectorIdxs[(int)target]
                                : modeModeSelectorIdxs[(int)Target2Mode[(int)target]];

            GUILayout.BeginHorizontal(GUILayout.Width(150));
            modeSelectorIdx = GuiUtils.ComboBox.Box(modeSelectorIdx, modeStrings.ToArray(), modeStrings);
            GUILayout.EndHorizontal();
            bool showForceRol = false;

            if (this.isTargetMode[modeSelectorIdx])
            {
                target       = this.targetModes[modeSelectorIdx];
                showForceRol = (target == MechJebModuleSmartASS.Target.NODE);
            }
            else
            {
                MechJebModuleSmartASS.Mode mode = this.modeModes[modeSelectorIdx];
                List <String> targetStrings     = this.targetStrings[(int)mode];
                if (targetStrings.Count == 1)
                {
                    target = this.targets[(int)mode][0];
                }
                else
                {
                    int targetSelectorIdx = (Target2Mode[(int)target] == mode) ? targetSelectorIdxs[(int)target] : 0;
                    GUILayout.BeginHorizontal(GUILayout.Width(160));
                    targetSelectorIdx = GuiUtils.ComboBox.Box(targetSelectorIdx, targetStrings.ToArray(), targetStrings);
                    GUILayout.EndHorizontal();
                    target = this.targets[(int)mode][targetSelectorIdx];
                }
                switch (mode)
                {
                case MechJebModuleSmartASS.Mode.ORBITAL:
                case MechJebModuleSmartASS.Mode.TARGET:
                    showForceRol = true;
                    break;

                case MechJebModuleSmartASS.Mode.ADVANCED:
                    GUILayout.BeginHorizontal(GUILayout.Width(220));
                    advReference = (AttitudeReference)GuiUtils.ComboBox.Box((int)advReference, ReferenceTexts, ReferenceTexts);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal(GUILayout.Width(200));
                    advDirection = (Vector6.Direction)GuiUtils.ComboBox.Box((int)advDirection, DirectionTexts, DirectionTexts);
                    GUILayout.EndHorizontal();
                    showForceRol = true;
                    break;
                }
                switch (target)
                {
                case MechJebModuleSmartASS.Target.SURFACE:
                    GUILayout.Label("", GUI.skin.label, GUILayout.ExpandWidth(true));
                    forceYaw    = GUILayout.Toggle(forceYaw, "Heading: ", GUILayout.ExpandWidth(false));
                    srfHdg.text = GUILayout.TextField(srfHdg.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forcePitch  = GUILayout.Toggle(forcePitch, "Pitch: ", GUILayout.ExpandWidth(false));
                    srfPit.text = GUILayout.TextField(srfPit.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forceRol    = GUILayout.Toggle(forceRol, "Roll: ", GUILayout.ExpandWidth(false));
                    srfRol.text = GUILayout.TextField(srfRol.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(false));
                    break;

                case MechJebModuleSmartASS.Target.SURFACE_PROGRADE:
                case MechJebModuleSmartASS.Target.SURFACE_RETROGRADE:
                    GUILayout.Label("", GUI.skin.label, GUILayout.ExpandWidth(true));
                    forcePitch     = GUILayout.Toggle(forcePitch, "Pitch: ", GUILayout.ExpandWidth(false));
                    srfVelPit.text = GUILayout.TextField(srfVelPit.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forceRol       = GUILayout.Toggle(forceRol, "Roll: ", GUILayout.ExpandWidth(false));
                    srfVelRol.text = GUILayout.TextField(srfVelRol.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(true));
                    forceYaw       = GUILayout.Toggle(forceYaw, "Yaw: ", GUILayout.ExpandWidth(false));
                    srfVelYaw.text = GUILayout.TextField(srfVelYaw.text, GUILayout.ExpandWidth(false), GUILayout.Width(37));
                    GUILayout.Label("°", GUILayout.ExpandWidth(false));
                    break;
                }
            }
            GUILayout.Label("", GUILayout.ExpandWidth(true));
            if (showForceRol)
            {
                forceRol = GUILayout.Toggle(forceRol, "Force Roll: ", GUILayout.ExpandWidth(false));
                rol.text = GUILayout.TextField(rol.text, GUILayout.Width(37));
                GUILayout.Label("°", GUILayout.ExpandWidth(false));
            }
            targetName = TargetTexts[(int)target];
            base.postWindowGUI(windowID);
        }
 public Vector3d attitudeReferenceToWorld(Vector3d vector, AttitudeReference reference)
 {
     return attitudeGetReferenceRotation(reference) * vector;
 }
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3    fwd, up;
            Quaternion rotRef = Quaternion.identity;

            if (core.target.Target == null && (reference == AttitudeReference.TARGET || reference == AttitudeReference.TARGET_ORIENTATION || reference == AttitudeReference.RELATIVE_VELOCITY))
            {
                attitudeDeactivate();
                return(rotRef);
            }

            if ((reference == AttitudeReference.MANEUVER_NODE || reference == AttitudeReference.MANEUVER_NODE_COT) && (vessel.patchedConicSolver.maneuverNodes.Count == 0))
            {
                attitudeDeactivate();
                return(rotRef);
            }

            Vector3d thrustForward = vesselState.thrustForward;

            // the off-axis thrust modifications get into a fight with the differential throttle so do not use them when diffthrottle is used
            if (core.thrust.differentialThrottle)
            {
                thrustForward = vesselState.forward;
            }

            switch (reference)
            {
            case AttitudeReference.INERTIAL_COT:
                rotRef = Quaternion.FromToRotation(thrustForward, vesselState.forward) * rotRef;
                break;

            case AttitudeReference.ORBIT:
                rotRef = Quaternion.LookRotation(vesselState.orbitalVelocity.normalized, vesselState.up);
                break;

            case AttitudeReference.ORBIT_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.orbitalVelocity.normalized), vesselState.up);
                break;

            case AttitudeReference.SURFACE_NORTH:
                rotRef = vesselState.rotationSurface;
                break;

            case AttitudeReference.SURFACE_NORTH_COT:
                rotRef = vesselState.rotationSurface;
                rotRef = Quaternion.FromToRotation(thrustForward, vesselState.forward) * rotRef;
                break;

            case AttitudeReference.SURFACE_VELOCITY:
                rotRef = Quaternion.LookRotation(vesselState.surfaceVelocity.normalized, vesselState.up);
                break;

            case AttitudeReference.TARGET:
                fwd = (core.target.Position - vessel.GetTransform().position).normalized;
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.RELATIVE_VELOCITY:
                fwd = core.target.RelativeVelocity.normalized;
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.TARGET_ORIENTATION:
                Transform targetTransform = core.target.Transform;
                if (core.target.CanAlign)
                {
                    rotRef = Quaternion.LookRotation(targetTransform.forward, targetTransform.up);
                }
                else
                {
                    rotRef = Quaternion.LookRotation(targetTransform.up, targetTransform.right);
                }
                break;

            case AttitudeReference.MANEUVER_NODE:
                fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.MANEUVER_NODE_COT:
                fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                up  = Vector3d.Cross(fwd, vesselState.normalPlus);
                Vector3.OrthoNormalize(ref fwd, ref up);
                rotRef = Quaternion.LookRotation(fwd, up);
                rotRef = Quaternion.FromToRotation(thrustForward, vesselState.forward) * rotRef;
                break;

            case AttitudeReference.SUN:
                Orbit baseOrbit = vessel.mainBody == Planetarium.fetch.Sun ? vessel.orbit : orbit.TopParentOrbit();
                up     = vesselState.CoM - Planetarium.fetch.Sun.transform.position;
                fwd    = Vector3d.Cross(-baseOrbit.GetOrbitNormal().xzy.normalized, up);
                rotRef = Quaternion.LookRotation(fwd, up);
                break;

            case AttitudeReference.SURFACE_HORIZONTAL:
                rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.surfaceVelocity.normalized), vesselState.up);
                break;
            }

            return(rotRef);
        }
        public bool attitudeTo(Vector3d direction, AttitudeReference reference, object controller)
        {
            //double ang_diff = Math.Abs(Vector3d.Angle(attitudeGetReferenceRotation(attitudeReference) * attitudeTarget * Vector3d.forward, attitudeGetReferenceRotation(reference) * direction));

            Vector3 up, dir = direction;

            if (!enabled)
            {
                up = attitudeWorldToReference(-vessel.GetTransform().forward, reference);
            }
            else
            {
                up = attitudeWorldToReference(attitudeReferenceToWorld(attitudeTarget * Vector3d.up, attitudeReference), reference);
            }
            Vector3.OrthoNormalize(ref dir, ref up);
            attitudeTo(Quaternion.LookRotation(dir, up), reference, controller);
            AxisControl(true, true, false);
            return true;
        }
        public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
        {
            Vector3 fwd, up;
            Quaternion rotRef = Quaternion.identity;

            if (core.target.Target == null && (reference == AttitudeReference.TARGET || reference == AttitudeReference.TARGET_ORIENTATION || reference == AttitudeReference.RELATIVE_VELOCITY))
            {
                attitudeDeactivate();
                return rotRef;
            }

            if ((reference == AttitudeReference.MANEUVER_NODE) && (vessel.patchedConicSolver.maneuverNodes.Count == 0))
            {
                attitudeDeactivate();
                return rotRef;
            }

            switch (reference)
            {
                case AttitudeReference.ORBIT:
                    rotRef = Quaternion.LookRotation(vesselState.velocityVesselOrbitUnit, vesselState.up);
                    break;
                case AttitudeReference.ORBIT_HORIZONTAL:
                    rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.velocityVesselOrbitUnit), vesselState.up);
                    break;
                case AttitudeReference.SURFACE_NORTH:
                    rotRef = vesselState.rotationSurface;
                    break;
                case AttitudeReference.SURFACE_VELOCITY:
                    rotRef = Quaternion.LookRotation(vesselState.velocityVesselSurfaceUnit, vesselState.up);
                    break;
                case AttitudeReference.TARGET:
                    fwd = (core.target.Position - vessel.GetTransform().position).normalized;
                    up = Vector3d.Cross(fwd, vesselState.normalPlus);
                    Vector3.OrthoNormalize(ref fwd, ref up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.RELATIVE_VELOCITY:
                    fwd = core.target.RelativeVelocity.normalized;
                    up = Vector3d.Cross(fwd, vesselState.normalPlus);
                    Vector3.OrthoNormalize(ref fwd, ref up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
                case AttitudeReference.TARGET_ORIENTATION:
                    Transform targetTransform = core.target.Transform;
                    if (core.target.Target is ModuleDockingNode)
                    {
                        rotRef = Quaternion.LookRotation(targetTransform.forward, targetTransform.up);
                    }
                    else
                    {
                        rotRef = Quaternion.LookRotation(targetTransform.up, targetTransform.right);
                    }
                    break;
                case AttitudeReference.MANEUVER_NODE:
                    fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit);
                    up = Vector3d.Cross(fwd, vesselState.normalPlus);
                    Vector3.OrthoNormalize(ref fwd, ref up);
                    rotRef = Quaternion.LookRotation(fwd, up);
                    break;
            }
            return rotRef;
        }
Beispiel #35
0
        public void Engage(bool resetPID = true)
        {
            Quaternion        attitude  = new Quaternion();
            Vector3d          direction = Vector3d.zero;
            AttitudeReference reference = AttitudeReference.ORBIT;

            switch (target)
            {
            case Target.OFF:
                core.attitude.attitudeDeactivate();
                return;

            case Target.KILLROT:
                core.attitude.attitudeKILLROT = true;
                attitude  = Quaternion.LookRotation(part.vessel.GetTransform().up, -part.vessel.GetTransform().forward);
                reference = AttitudeReference.INERTIAL;
                break;

            case Target.NODE:
                direction = Vector3d.forward;
                reference = AttitudeReference.MANEUVER_NODE;
                break;

            case Target.SURFACE:
                attitude = Quaternion.AngleAxis((float)srfHdg, Vector3.up)
                           * Quaternion.AngleAxis(-(float)srfPit, Vector3.right)
                           * Quaternion.AngleAxis(-(float)srfRol, Vector3.forward);
                reference = AttitudeReference.SURFACE_NORTH;
                break;

            case Target.PROGRADE:
                direction = Vector3d.forward;
                reference = AttitudeReference.ORBIT;
                break;

            case Target.RETROGRADE:
                direction = Vector3d.back;
                reference = AttitudeReference.ORBIT;
                break;

            case Target.NORMAL_PLUS:
                direction = Vector3d.left;
                reference = AttitudeReference.ORBIT;
                break;

            case Target.NORMAL_MINUS:
                direction = Vector3d.right;
                reference = AttitudeReference.ORBIT;
                break;

            case Target.RADIAL_PLUS:
                direction = Vector3d.up;
                reference = AttitudeReference.ORBIT;
                break;

            case Target.RADIAL_MINUS:
                direction = Vector3d.down;
                reference = AttitudeReference.ORBIT;
                break;

            case Target.RELATIVE_PLUS:
                direction = Vector3d.forward;
                reference = AttitudeReference.RELATIVE_VELOCITY;
                break;

            case Target.RELATIVE_MINUS:
                direction = Vector3d.back;
                reference = AttitudeReference.RELATIVE_VELOCITY;
                break;

            case Target.TARGET_PLUS:
                direction = Vector3d.forward;
                reference = AttitudeReference.TARGET;
                break;

            case Target.TARGET_MINUS:
                direction = Vector3d.back;
                reference = AttitudeReference.TARGET;
                break;

            case Target.PARALLEL_PLUS:
                direction = Vector3d.forward;
                reference = AttitudeReference.TARGET_ORIENTATION;
                break;

            case Target.PARALLEL_MINUS:
                direction = Vector3d.back;
                reference = AttitudeReference.TARGET_ORIENTATION;
                break;

            case Target.ADVANCED:
                direction = Vector6.directions[(int)advDirection];
                reference = advReference;
                break;

            case Target.SURFACE_PROGRADE:
                attitude = Quaternion.AngleAxis(-(float)srfVelRol, Vector3.forward) *
                           Quaternion.AngleAxis(-(float)srfVelPit, Vector3.right) *
                           Quaternion.AngleAxis((float)srfVelYaw, Vector3.up);
                reference = AttitudeReference.SURFACE_VELOCITY;
                break;

            case Target.SURFACE_RETROGRADE:
                attitude = Quaternion.AngleAxis((float)srfVelRol + 180, Vector3.forward) *
                           Quaternion.AngleAxis(-(float)srfVelPit + 180, Vector3.right) *
                           Quaternion.AngleAxis((float)srfVelYaw, Vector3.up);
                reference = AttitudeReference.SURFACE_VELOCITY;
                break;

            case Target.HORIZONTAL_PLUS:
                direction = Vector3d.forward;
                reference = AttitudeReference.SURFACE_HORIZONTAL;
                break;

            case Target.HORIZONTAL_MINUS:
                direction = Vector3d.back;
                reference = AttitudeReference.SURFACE_HORIZONTAL;
                break;

            case Target.VERTICAL_PLUS:
                direction = Vector3d.up;
                reference = AttitudeReference.SURFACE_NORTH;
                break;

            default:
                return;
            }

            if (forceRol && direction != Vector3d.zero)
            {
                attitude  = Quaternion.LookRotation(direction, Vector3d.up) * Quaternion.AngleAxis(-(float)rol, Vector3d.forward);
                direction = Vector3d.zero;
            }

            if (direction != Vector3d.zero)
            {
                core.attitude.attitudeTo(direction, reference, this);
            }
            else
            {
                core.attitude.attitudeTo(attitude, reference, this);
            }

            if (resetPID)
            {
                core.attitude.pid.Reset();
            }
        }
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding = new RectOffset(8, 8, 8, 8);

                btActive = new GUIStyle(btNormal);
                btActive.active = btActive.onActive;
                btActive.normal = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            // If any other module use the attitude controler then let them do it
            if (core.attitude.enabled && core.attitude.users.Count(u => !this.Equals(u)) > 0)
            {
                if (autoDisableSmartASS)
                {
                    target = Target.OFF;
                    if (core.attitude.users.Contains(this)) core.attitude.users.Remove(this); // so we don't suddenly turn on when the other autopilot finishes
                }
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                if (vessel.patchedConicsUnlocked())
                {
                    TargetButton(Target.NODE);
                }
                else
                {
                    GUILayout.Button("-", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                }
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                    case Mode.ORBITAL:

                        GUILayout.BeginHorizontal();
                        TargetButton(Target.PROGRADE);
                        TargetButton(Target.NORMAL_PLUS);
                        TargetButton(Target.RADIAL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.RETROGRADE);
                        TargetButton(Target.NORMAL_MINUS);
                        TargetButton(Target.RADIAL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();

                        break;
                    case Mode.SURFACE:
                    	double val = (GameSettings.MODIFIER_KEY.GetKey() ? 5 : 1); // change by 5 if the mod_key is held down, else by 1
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.SURFACE_PROGRADE);
                        TargetButton(Target.SURFACE_RETROGRADE);
                        TargetButtonNoEngage(Target.SURFACE);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.HORIZONTAL_PLUS);
                        TargetButton(Target.HORIZONTAL_MINUS);
                        TargetButton(Target.VERTICAL_PLUS);
                        GUILayout.EndHorizontal();
                        if (target == Target.SURFACE) {
                            bool changed = false;
                        	GUILayout.BeginHorizontal();
                            forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("HDG", srfHdg, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                            	srfHdg -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfHdg += val;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfHdg = 0;
                                changed = true;
                            }
                            if (GUILayout.Button("90", GUILayout.Width(35))) {
                                srfHdg = 90;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                        	GUILayout.BeginHorizontal();
                            forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("PIT", srfPit, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfPit -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfPit += val;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfPit = 0;
                                changed = true;
                            }
                            if (GUILayout.Button("90", GUILayout.Width(35))) {
                                srfPit = 90;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                        	GUILayout.BeginHorizontal();
                            forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("ROL", srfRol, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfRol -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfRol += val;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfRol = 0;
                                changed = true;
                            }
                            if (GUILayout.Button("180", GUILayout.Width(35))) {
                                srfRol = 180;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            if (GUILayout.Button("EXECUTE")) {
                                Engage();
                            }
                            if (changed)
                            {
                                Engage(false);
                            }
                            core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                        } else if (target == Target.SURFACE_PROGRADE || target == Target.SURFACE_RETROGRADE)
                        {
                            bool changed = false;
                            GUILayout.BeginHorizontal();
                            forceRol = GUILayout.Toggle(forceRol, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("ROL", srfVelRol, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfVelRol -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfVelRol += val;
                                changed = true;
                            }
                            if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false))) {
                                srfVelRol = -vesselState.vesselRoll.value;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfVelRol = 0;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            forcePitch = GUILayout.Toggle(forcePitch, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("PIT", srfVelPit, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfVelPit -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfVelPit += val;
                                changed = true;
                            }
                            if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false))) {
                                srfVelPit = vesselState.AoA.value;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfVelPit = 0;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            forceYaw = GUILayout.Toggle(forceYaw, "", GUILayout.ExpandWidth(false));
                            GuiUtils.SimpleTextBox("YAW", srfVelYaw, "°", 37);
                            if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) {
                                srfVelYaw -= val;
                                changed = true;
                            }
                            if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) {
                                srfVelYaw += val;
                                changed = true;
                            }
                            if (GUILayout.Button("CUR", GUILayout.ExpandWidth(false))) {
                                srfVelYaw = -vesselState.AoS.value;
                                changed = true;
                            }
                            if (GUILayout.Button("0", GUILayout.ExpandWidth(false))) {
                                srfVelYaw = 0;
                                changed = true;
                            }
                            GUILayout.EndHorizontal();
                            if (GUILayout.Button("EXECUTE"))
                            {
                                Engage();
                            }
                            if (changed)
                            {
                                Engage(false);
                            }
                            core.attitude.AxisControl(forcePitch, forceYaw, forceRol);
                        }
                        break;
                    case Mode.TARGET:
                        if (core.target.NormalTargetExists)
                        {
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_PLUS);
                            TargetButton(Target.RELATIVE_PLUS);
                            TargetButton(Target.PARALLEL_PLUS);
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_MINUS);
                            TargetButton(Target.RELATIVE_MINUS);
                            TargetButton(Target.PARALLEL_MINUS);
                            GUILayout.EndHorizontal();

                            ForceRoll();
                        }
                        else
                        {
                            GUILayout.Label("Please select a target");
                        }
                        break;
                    case Mode.ADVANCED:
                        GUILayout.Label("Reference:");
                        advReference = (AttitudeReference)GuiUtils.ComboBox.Box((int)advReference, ReferenceTexts, this);

                        GUILayout.Label("Direction:");
                        advDirection = (Vector6.Direction)GuiUtils.ComboBox.Box((int)advDirection, directionTexts, directionTexts);

                        ForceRoll();

                        if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                        {
                            target = Target.ADVANCED;
                            Engage();
                        }
                        break;
                    case Mode.AUTO:
                        break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }
Beispiel #37
0
 public Vector3d attitudeWorldToReference(Vector3d vector, AttitudeReference reference)
 {
     return(Quaternion.Inverse(attitudeGetReferenceRotation(reference)) * vector);
 }
Beispiel #38
0
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding = new RectOffset(8, 8, 8, 8);

                btActive = new GUIStyle(btNormal);
                btActive.active = btActive.onActive;
                btActive.normal = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            if (core.attitude.enabled && !core.attitude.users.Contains(this))
            {
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                TargetButton(Target.NODE);
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                    case Mode.ORBITAL:
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.PROGRADE);
                        TargetButton(Target.NORMAL_PLUS);
                        TargetButton(Target.RADIAL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.RETROGRADE);
                        TargetButton(Target.NORMAL_MINUS);
                        TargetButton(Target.RADIAL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();

                        break;
                    case Mode.SURFACE:
                        GuiUtils.SimpleTextBox("HDG:", srfHdg);
                        GuiUtils.SimpleTextBox("PIT:", srfPit);
                        GuiUtils.SimpleTextBox("ROL:", srfRol);

                        if (GUILayout.Button("EXECUTE", GUILayout.ExpandWidth(true)))
                        {
                            target = Target.SURFACE;
                            Engage();
                        }
                        break;
                    case Mode.TARGET:
                        if (core.target.NormalTargetExists)
                        {
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_PLUS);
                            TargetButton(Target.RELATIVE_PLUS);
                            TargetButton(Target.PARALLEL_PLUS);
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            TargetButton(Target.TARGET_MINUS);
                            TargetButton(Target.RELATIVE_MINUS);
                            TargetButton(Target.PARALLEL_MINUS);
                            GUILayout.EndHorizontal();

                            ForceRoll();
                        }
                        else
                        {
                            GUILayout.Label("Please select a target");
                        }
                        break;
                    case Mode.ADVANCED:
                        GUILayout.Label("Reference:");
                        advReference = (AttitudeReference)GuiUtils.ArrowSelector((int)advReference, Enum.GetValues(typeof(AttitudeReference)).Length, advReference.ToString());

                        GUILayout.Label("Direction:");
                        advDirection = (Vector6.Direction)GuiUtils.ArrowSelector((int)advDirection, Enum.GetValues(typeof(Vector6.Direction)).Length, advDirection.ToString());

                        if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                        {
                            target = Target.ADVANCED;
                            Engage();
                        }
                        break;
                    case Mode.AUTO:
                        break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }
Beispiel #39
0
 public Quaternion attitudeGetReferenceRotation(AttitudeReference reference)
 {
     Vector3 fwd, up;
     Quaternion rotRef = Quaternion.identity;
     switch (reference)
     {
         case AttitudeReference.ORBIT:
             rotRef = Quaternion.LookRotation(vesselState.velocityVesselOrbitUnit, vesselState.up);
             break;
         case AttitudeReference.ORBIT_HORIZONTAL:
             rotRef = Quaternion.LookRotation(Vector3d.Exclude(vesselState.up, vesselState.velocityVesselOrbitUnit), vesselState.up);
             break;
         case AttitudeReference.SURFACE_NORTH:
             rotRef = vesselState.rotationSurface;
             break;
         case AttitudeReference.SURFACE_VELOCITY:
             rotRef = Quaternion.LookRotation(vesselState.velocityVesselSurfaceUnit, vesselState.up);
             break;
         case AttitudeReference.TARGET:
             fwd = (((targetType == TargetType.VESSEL) ? (Vector3d)targetVessel.transform.position : targetBody.position) - vesselState.CoM).normalized;
             up = Vector3d.Cross(fwd, vesselState.leftOrbit);
             Vector3.OrthoNormalize(ref fwd, ref up);
             rotRef = Quaternion.LookRotation(fwd, up);
             break;
         case AttitudeReference.RELATIVE_VELOCITY:
             fwd = (vesselState.velocityVesselOrbit - ((targetType == TargetType.VESSEL) ? targetVessel.orbit.GetVel() : targetBody.orbit.GetVel())).normalized;
             up = Vector3d.Cross(fwd, vesselState.leftOrbit);
             Vector3.OrthoNormalize(ref fwd, ref up);
             rotRef = Quaternion.LookRotation(fwd, up);
             break;
         case AttitudeReference.TARGET_ORIENTATION:
             switch (targetType)
             {
                 case TargetType.VESSEL:
                     rotRef = Quaternion.LookRotation(targetVessel.transform.up, targetVessel.transform.right);
                     break;
                 case TargetType.BODY:
                     rotRef = vesselState.rotationSurface;
                     break;
             }
             break;
     }
     return rotRef;
 }
        protected override void WindowGUI(int windowID)
        {
            if (btNormal == null)
            {
                btNormal = new GUIStyle(GUI.skin.button);
                btNormal.normal.textColor   = btNormal.focused.textColor = Color.white;
                btNormal.hover.textColor    = btNormal.active.textColor = Color.yellow;
                btNormal.onNormal.textColor = btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
                btNormal.padding            = new RectOffset(8, 8, 8, 8);

                btActive           = new GUIStyle(btNormal);
                btActive.active    = btActive.onActive;
                btActive.normal    = btActive.onNormal;
                btActive.onFocused = btActive.focused;
                btActive.hover     = btActive.onHover;

                btAuto = new GUIStyle(btNormal);
                btAuto.normal.textColor = Color.red;
                btAuto.onActive         = btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
            }

            // If any other module use the attitude controler then let them do it
            if (core.attitude.enabled && core.attitude.users.Count(u => !this.Equals(u)) > 0)
            {
                GUILayout.Button("AUTO", btAuto, GUILayout.ExpandWidth(true));
            }
            else
            {
                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                TargetButton(Target.OFF);
                TargetButton(Target.KILLROT);
                TargetButton(Target.NODE);
                GUILayout.EndHorizontal();

                GUILayout.Label("Mode:");
                GUILayout.BeginHorizontal();
                ModeButton(Mode.ORBITAL);
                ModeButton(Mode.SURFACE);
                ModeButton(Mode.TARGET);
                ModeButton(Mode.ADVANCED);
                GUILayout.EndHorizontal();

                switch (mode)
                {
                case Mode.ORBITAL:
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.PROGRADE);
                    TargetButton(Target.NORMAL_PLUS);
                    TargetButton(Target.RADIAL_PLUS);
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    TargetButton(Target.RETROGRADE);
                    TargetButton(Target.NORMAL_MINUS);
                    TargetButton(Target.RADIAL_MINUS);
                    GUILayout.EndHorizontal();

                    ForceRoll();

                    break;

                case Mode.SURFACE:
                    GuiUtils.SimpleTextBox("HDG:", srfHdg);
                    GuiUtils.SimpleTextBox("PIT:", srfPit);
                    GuiUtils.SimpleTextBox("ROL:", srfRol);

                    if (GUILayout.Button("EXECUTE", GUILayout.ExpandWidth(true)))
                    {
                        target = Target.SURFACE;
                        Engage();
                    }
                    break;

                case Mode.TARGET:
                    if (core.target.NormalTargetExists)
                    {
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_PLUS);
                        TargetButton(Target.RELATIVE_PLUS);
                        TargetButton(Target.PARALLEL_PLUS);
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        TargetButton(Target.TARGET_MINUS);
                        TargetButton(Target.RELATIVE_MINUS);
                        TargetButton(Target.PARALLEL_MINUS);
                        GUILayout.EndHorizontal();

                        ForceRoll();
                    }
                    else
                    {
                        GUILayout.Label("Please select a target");
                    }
                    break;

                case Mode.ADVANCED:
                    GUILayout.Label("Reference:");
                    advReference = (AttitudeReference)GuiUtils.ArrowSelector((int)advReference, Enum.GetValues(typeof(AttitudeReference)).Length, advReference.ToString());

                    GUILayout.Label("Direction:");
                    advDirection = (Vector6.Direction)GuiUtils.ArrowSelector((int)advDirection, Enum.GetValues(typeof(Vector6.Direction)).Length, advDirection.ToString());

                    if (GUILayout.Button("EXECUTE", btNormal, GUILayout.ExpandWidth(true)))
                    {
                        target = Target.ADVANCED;
                        Engage();
                    }
                    break;

                case Mode.AUTO:
                    break;
                }

                GUILayout.EndVertical();
            }

            base.WindowGUI(windowID);
        }