Exemple #1
0
        /// <summary>
        /// The direction vector that the SAS autopilot is trying to hold in world space
        /// </summary>
        Vector3d SASTargetDirection()
        {
            // Stability assist
            if (SASMode == SASMode.StabilityAssist)
            {
                throw new InvalidOperationException("No target direction in stability assist mode");
            }

            // Maneuver node
            if (SASMode == SASMode.Maneuver)
            {
                var node = InternalVessel.patchedConicSolver.maneuverNodes.OrderBy(x => x.UT).FirstOrDefault();
                if (node == null)
                {
                    throw new InvalidOperationException("No maneuver node");
                }
                return(new Node(InternalVessel, node).WorldBurnVector);
            }

            // Orbital directions, in different speed modes
            if (SASMode == SASMode.Prograde || SASMode == SASMode.Retrograde ||
                SASMode == SASMode.Normal || SASMode == SASMode.AntiNormal ||
                SASMode == SASMode.Radial || SASMode == SASMode.AntiRadial)
            {
                if (Control.GetSpeedMode() == SpeedMode.Orbit)
                {
                    switch (SASMode)
                    {
                    case SASMode.Prograde:
                        return(ReferenceFrame.Orbital(InternalVessel).DirectionToWorldSpace(Vector3d.up));

                    case SASMode.Retrograde:
                        return(ReferenceFrame.Orbital(InternalVessel).DirectionToWorldSpace(Vector3d.down));

                    case SASMode.Normal:
                        return(ReferenceFrame.Orbital(InternalVessel).DirectionToWorldSpace(Vector3d.forward));

                    case SASMode.AntiNormal:
                        return(ReferenceFrame.Orbital(InternalVessel).DirectionToWorldSpace(Vector3d.back));

                    case SASMode.Radial:
                        return(ReferenceFrame.Orbital(InternalVessel).DirectionToWorldSpace(Vector3d.left));

                    case SASMode.AntiRadial:
                        return(ReferenceFrame.Orbital(InternalVessel).DirectionToWorldSpace(Vector3d.right));
                    }
                }
                else if (Control.GetSpeedMode() == SpeedMode.Surface)
                {
                    switch (SASMode)
                    {
                    case SASMode.Prograde:
                        return(ReferenceFrame.SurfaceVelocity(InternalVessel).DirectionToWorldSpace(Vector3d.up));

                    case SASMode.Retrograde:
                        return(ReferenceFrame.SurfaceVelocity(InternalVessel).DirectionToWorldSpace(Vector3d.down));

                    case SASMode.Normal:
                        return(ReferenceFrame.Object(InternalVessel.orbit.referenceBody).DirectionToWorldSpace(Vector3d.up));

                    case SASMode.AntiNormal:
                        return(ReferenceFrame.Object(InternalVessel.orbit.referenceBody).DirectionToWorldSpace(Vector3d.down));

                    case SASMode.Radial:
                        return(ReferenceFrame.Surface(InternalVessel).DirectionToWorldSpace(Vector3d.right));

                    case SASMode.AntiRadial:
                        return(ReferenceFrame.Surface(InternalVessel).DirectionToWorldSpace(Vector3d.left));
                    }
                }
                else if (Control.GetSpeedMode() == SpeedMode.Target)
                {
                    switch (SASMode)
                    {
                    case SASMode.Prograde:
                        return(InternalVessel.GetWorldVelocity() - FlightGlobals.fetch.VesselTarget.GetWorldVelocity());

                    case SASMode.Retrograde:
                        return(FlightGlobals.fetch.VesselTarget.GetWorldVelocity() - InternalVessel.GetWorldVelocity());

                    case SASMode.Normal:
                        return(ReferenceFrame.Object(InternalVessel.orbit.referenceBody).DirectionToWorldSpace(Vector3d.up));

                    case SASMode.AntiNormal:
                        return(ReferenceFrame.Object(InternalVessel.orbit.referenceBody).DirectionToWorldSpace(Vector3d.down));

                    case SASMode.Radial:
                        return(ReferenceFrame.Surface(InternalVessel).DirectionToWorldSpace(Vector3d.right));

                    case SASMode.AntiRadial:
                        return(ReferenceFrame.Surface(InternalVessel).DirectionToWorldSpace(Vector3d.left));
                    }
                }
                throw new InvalidOperationException("Unknown speed mode for orbital direction");
            }

            // Target and anti-target
            if (SASMode == SASMode.Target || SASMode == SASMode.AntiTarget)
            {
                var target = FlightGlobals.fetch.VesselTarget;
                if (target == null)
                {
                    throw new InvalidOperationException("No target");
                }
                var direction = target.GetWorldPosition() - InternalVessel.GetWorldPos3D();
                if (SASMode == SASMode.AntiTarget)
                {
                    direction *= -1;
                }
                return(direction);
            }

            throw new InvalidOperationException("Unknown SAS mode");
        }
Exemple #2
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.PositionFromWorldSpace(InternalVessel.GetWorldPos3D()).ToTuple());
 }