Ejemplo n.º 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");
        }
Ejemplo n.º 2
0
 public double TemperatureAt (Tuple3 position, ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals (referenceFrame, null))
         throw new ArgumentNullException (nameof (referenceFrame));
     return StockAerodynamics.GetTemperature(referenceFrame.PositionToWorldSpace(position.ToVector()), InternalBody);
 }
Ejemplo n.º 3
0
 public Tuple3 Direction(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.DirectionFromWorldSpace(InternalBody.transform.up).ToTuple());
 }
Ejemplo n.º 4
0
 public static Tuple3 ReferencePlaneDirection(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.DirectionFromWorldSpace(Planetarium.right).normalized.ToTuple());
 }
Ejemplo n.º 5
0
        public static Tuple3 TransformVelocity(Tuple3 position, Tuple3 velocity, ReferenceFrame from, ReferenceFrame to)
        {
            CheckReferenceFrames(from, to);
            var worldPosition = from.PositionToWorldSpace(position.ToVector());
            var worldVelocity = from.VelocityToWorldSpace(position.ToVector(), velocity.ToVector());

            return(to.VelocityFromWorldSpace(worldPosition, worldVelocity).ToTuple());
        }
Ejemplo n.º 6
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.PositionFromWorldSpace(InternalBody.position).ToTuple());
 }
Ejemplo n.º 7
0
 public static void DrawDirection(Tuple3 direction, ReferenceFrame referenceFrame, Tuple3 color, float length = 10f)
 {
     DrawAddon.AddDirection(direction.ToVector(), referenceFrame, color, length);
 }
Ejemplo n.º 8
0
 public Tuple4 Rotation(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.RotationFromWorldSpace(InternalVessel.ReferenceTransform.rotation).ToTuple());
 }
Ejemplo n.º 9
0
 public Tuple3 AngularVelocity (ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals (referenceFrame, null))
         throw new ArgumentNullException (nameof (referenceFrame));
     return referenceFrame.AngularVelocityFromWorldSpace (InternalBody.angularVelocity).ToTuple ();
 }
Ejemplo n.º 10
0
 public static Tuple3 TransformDirection(Tuple3 direction, ReferenceFrame from, ReferenceFrame to)
 {
     return(to.DirectionFromWorldSpace(from.DirectionToWorldSpace(direction.ToVector())).ToTuple());
 }
Ejemplo n.º 11
0
 public Tuple3 Direction (ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals (referenceFrame, null))
         throw new ArgumentNullException (nameof (referenceFrame));
     return referenceFrame.DirectionFromWorldSpace (InternalBody.transform.up).ToTuple ();
 }
Ejemplo n.º 12
0
 public Tuple3 Velocity (ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals (referenceFrame, null))
         throw new ArgumentNullException (nameof (referenceFrame));
     return referenceFrame.VelocityFromWorldSpace (InternalBody.position, InternalBody.GetWorldVelocity ()).ToTuple ();
 }
Ejemplo n.º 13
0
 public Tuple3 Position (ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals (referenceFrame, null))
         throw new ArgumentNullException (nameof (referenceFrame));
     return referenceFrame.PositionFromWorldSpace (InternalBody.position).ToTuple ();
 }
Ejemplo n.º 14
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.PositionFromWorldSpace(InternalVessel.GetWorldPos3D()).ToTuple());
 }
Ejemplo n.º 15
0
 public static void DrawLine(Tuple3 start, Tuple3 end, ReferenceFrame referenceFrame, Tuple3 color)
 {
     DrawAddon.AddLine(start.ToVector(), end.ToVector(), referenceFrame, color);
 }
Ejemplo n.º 16
0
 public Tuple3 Velocity(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.VelocityFromWorldSpace(InternalVessel.CoM, InternalVessel.GetOrbit().GetVel()).ToTuple());
 }
Ejemplo n.º 17
0
 public Tuple3 PositionAtAltitude(double latitude, double longitude, double altitude, ReferenceFrame referenceFrame)
 {
     return(PositionAt(latitude, longitude, altitude, referenceFrame));
 }
Ejemplo n.º 18
0
 public static Tuple4 TransformRotation(Tuple4 rotation, ReferenceFrame from, ReferenceFrame to)
 {
     CheckReferenceFrames(from, to);
     return(to.RotationFromWorldSpace(from.RotationToWorldSpace(rotation.ToQuaternion())).ToTuple());
 }
Ejemplo n.º 19
0
 public Tuple3 Position(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.PositionFromWorldSpace(InternalNode.patch.getPositionAtUT(InternalNode.UT)).ToTuple());
 }
Ejemplo n.º 20
0
        public Tuple3 MSLPosition(double latitude, double longitude, ReferenceFrame referenceFrame)
        {
            var position = InternalBody.GetWorldSurfacePosition(latitude, longitude, 0);

            return(referenceFrame.PositionFromWorldSpace(position).ToTuple());
        }
Ejemplo n.º 21
0
 public Tuple3 Direction(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.DirectionFromWorldSpace(WorldBurnVector.normalized).ToTuple());
 }
Ejemplo n.º 22
0
 public Tuple3 Velocity(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.VelocityFromWorldSpace(InternalBody.position, InternalBody.GetWorldVelocity()).ToTuple());
 }
Ejemplo n.º 23
0
 public Tuple3 MSLPosition(double latitude, double longitude, ReferenceFrame referenceFrame)
 {
     return(PositionAt(latitude, longitude, 0, referenceFrame));
 }
Ejemplo n.º 24
0
 public Tuple3 AngularVelocity(ReferenceFrame referenceFrame)
 {
     return(referenceFrame.AngularVelocityFromWorldSpace(InternalBody.angularVelocity).ToTuple());
 }
Ejemplo n.º 25
0
 public Tuple3 SurfacePosition(double latitude, double longitude, ReferenceFrame referenceFrame)
 {
     return(PositionAt(latitude, longitude, SurfaceHeight(latitude, longitude), referenceFrame));
 }
Ejemplo n.º 26
0
 internal Flight(global::Vessel vessel, ReferenceFrame referenceFrame)
 {
     vesselId            = vessel.id;
     this.referenceFrame = referenceFrame;
 }
Ejemplo n.º 27
0
 public Tuple3 BedrockPosition(double latitude, double longitude, ReferenceFrame referenceFrame)
 {
     return(PositionAt(latitude, longitude, BedrockHeight(latitude, longitude), referenceFrame));
 }
Ejemplo n.º 28
0
 public static Tuple3 TransformPosition(Tuple3 position, ReferenceFrame from, ReferenceFrame to)
 {
     CheckReferenceFrames(from, to);
     return(to.PositionFromWorldSpace(from.PositionToWorldSpace(position.ToVector())).ToTuple());
 }
Ejemplo n.º 29
0
 public double AltitudeAtPosition (Tuple3 position, ReferenceFrame referenceFrame)
 {
     if (ReferenceEquals(referenceFrame, null))
         throw new ArgumentNullException(nameof(referenceFrame));
     return InternalBody.GetAltitude(referenceFrame.PositionToWorldSpace(position.ToVector()));
 }