Added more rendezvous readouts.
[VesselSimulator.git] / KerbalEngineer / Flight / Readouts / Rendezvous / RendezvousProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Project:  KerbalEngineer
// Author:      CYBUTEK
// License:     Attribution-NonCommercial-ShareAlike 3.0 Unported
 
namespace KerbalEngineer.Flight.Readouts.Rendezvous
{
    public class RendezvousProcessor : IUpdatable, IUpdateRequest
    {
        #region Instance
 
        private static readonly RendezvousProcessor instance = new RendezvousProcessor();
 
        /// <summary>
        ///     Gets the current instance of the rendezvous processor.
        /// </summary>
        public static RendezvousProcessor Instance
        {
            get { return instance; }
        }
 
        #endregion
 
        #region Fields
 
        private Orbit sourceOrbit;
        private Orbit targetOrbit;
 
        #endregion
 
        #region Properties
 
        /// <summary>
        ///     Gets whether the details are ready to be shown.
        /// </summary>
        public static bool ShowDetails { get; private set; }
 
        /// <summary>
        ///     Gets the angular difference between the source and target orbits.
        /// </summary>
        public static double RelativeInclination { get; private set; }
 
        #endregion
 
        #region IUpdatable Members
 
        /// <summary>
        ///     Updates the details by recalculating if requested.
        /// </summary>
        public void Update()
        {
            if (FlightGlobals.fetch.VesselTarget == null)
            {
                ShowDetails = false;
                return;
            }
 
            ShowDetails = true;
 
            this.targetOrbit = FlightGlobals.fetch.VesselTarget.GetOrbit();
            this.sourceOrbit = (FlightGlobals.ship_orbit.referenceBody == Planetarium.fetch.Sun || FlightGlobals.ship_orbit.referenceBody == FlightGlobals.ActiveVessel.targetObject.GetOrbit().referenceBody)
                ? FlightGlobals.ship_orbit
                : FlightGlobals.ship_orbit.referenceBody.orbit;
 
            RelativeInclination = Vector3d.Angle(this.sourceOrbit.GetOrbitNormal(), this.targetOrbit.GetOrbitNormal());
        }
 
        #endregion
 
        #region IUpdateRequest Members
 
        /// <summary>
        ///     Gets and sets whether the updatable object should be updated.
        /// </summary>
        public bool UpdateRequested { get; set; }
 
        #endregion
 
        /// <summary>
        ///     Request and update to calculate the details.
        /// </summary>
        public static void RequestUpdate()
        {
            instance.UpdateRequested = true;
        }
    }
}