예제 #1
0
            private void LateUpdate()
            {
                if (map_renderer_ == null) {
                  map_renderer_ =
                  PlanetariumCamera.Camera.gameObject.AddComponent<RenderingActions>();
                  map_renderer_.post_render = RenderTrajectories;
                }

                if (galaxy_cube_rotator_ == null) {
                  galaxy_cube_rotator_ = ScaledCamera.Instance.galaxyCamera.gameObject
                                 .AddComponent<RenderingActions>();
                  galaxy_cube_rotator_.pre_cull = RotateGalaxyCube;
                }

                // Orient the celestial bodies.
                if (PluginRunning()) {
                  foreach (var body in FlightGlobals.Bodies) {
                body.scaledBody.transform.rotation =
                (UnityEngine.QuaternionD)plugin_.CelestialRotation(
                body.flightGlobalsIndex);
                  }
                }

                override_rsas_target_ = false;
                Vessel active_vessel = FlightGlobals.ActiveVessel;
                if (active_vessel != null &&
                !FlightGlobals.ActiveVessel.isEVA) {
                  if (navball_ == null) {
                navball_ = (KSP.UI.Screens.Flight.NavBall)FindObjectOfType(
                       typeof(KSP.UI.Screens.Flight.NavBall));
                  }
                  var navball_material =
                  navball_.navBall.GetComponent<UnityEngine.Renderer>().material;

                  if (compass_navball_texture_ == null) {
                compass_navball_texture_ = navball_material.GetTexture("_MainTexture");
                  }

                  Action<UnityEngine.Texture> set_navball_texture = (texture) =>
                  navball_material.SetTexture("_MainTexture", texture);

                  if (navball_changed_) {
                // Texture the ball.
                navball_changed_ = false;
                // TODO(egg): switch over all frame types and have more navball textures
                // when more frames are available.
                if (!fix_navball_in_plotting_frame_ || !PluginRunning()) {
                  set_navball_texture(compass_navball_texture_);
                } else if (plotting_frame_selector_.get().frame_type ==
                   ReferenceFrameSelector.FrameType.BODY_CENTRED_NON_ROTATING) {
                  set_navball_texture(inertial_navball_texture_);
                } else {
                  set_navball_texture(barycentric_navball_texture_);
                }
                  }

                  // Orient the ball.
                  if (PluginRunning() && fix_navball_in_plotting_frame_) {
                navball_.navBall.rotation =
                (UnityEngine.QuaternionD)navball_.attitudeGymbal *  // sic.
                (UnityEngine.QuaternionD)plugin_.NavballOrientation(
                (XYZ)Planetarium.fetch.Sun.position,
                (XYZ)(Vector3d)active_vessel.ReferenceTransform.position);
                  }

                  if (PluginRunning() &&
                  has_active_vessel_in_space() &&
                  plugin_.HasVessel(active_vessel.id.ToString()) &&
                  FlightGlobals.speedDisplayMode ==
                  FlightGlobals.SpeedDisplayModes.Orbit) {
                KSP.UI.Screens.Flight.SpeedDisplay speed_display =
                KSP.UI.Screens.Flight.SpeedDisplay.Instance;
                if (speed_display?.textTitle != null &&
                speed_display?.textSpeed != null) {
                  speed_display.textTitle.text =
                  plotting_frame_selector_.get().ShortName();
                  speed_display.textSpeed.text =
                  ((Vector3d)plugin_.VesselVelocity(active_vessel.id.ToString()))
                  .magnitude.ToString("F1") + "m/s";
                }

                // Orient the Frenet trihedron.
                Vector3d prograde =
                (Vector3d)plugin_.VesselTangent(active_vessel.id.ToString());
                Vector3d radial =
                (Vector3d)plugin_.VesselNormal(active_vessel.id.ToString());
                // Yes, the astrodynamicist's normal is the mathematician's binormal.
                // Don't ask.
                Vector3d normal =
                (Vector3d)plugin_.VesselBinormal(active_vessel.id.ToString());

                SetNavballVector(navball_.progradeVector, prograde);
                SetNavballVector(navball_.radialInVector, radial);
                SetNavballVector(navball_.normalVector, normal);
                SetNavballVector(navball_.retrogradeVector, -prograde);
                SetNavballVector(navball_.radialOutVector, -radial);
                SetNavballVector(navball_.antiNormalVector, -normal);

                // Make the autopilot target our Frenet trihedron.
                if (active_vessel.OnAutopilotUpdate.GetInvocationList()[0] !=
                (Delegate)(FlightInputCallback)OverrideRSASTarget) {
                  Log.Info("Prepending RSAS override");
                  active_vessel.OnAutopilotUpdate =
                  (FlightInputCallback)Delegate.Combine(
                  new FlightInputCallback(OverrideRSASTarget),
                  active_vessel.OnAutopilotUpdate);
                }
                if (active_vessel.Autopilot.Enabled) {
                  override_rsas_target_ = true;
                  switch (active_vessel.Autopilot.Mode) {
                case VesselAutopilot.AutopilotMode.Prograde:
                  rsas_target_ = prograde;
                  break;
                case VesselAutopilot.AutopilotMode.Retrograde:
                  rsas_target_ = -prograde;
                  break;
                case VesselAutopilot.AutopilotMode.RadialIn:
                  rsas_target_ = radial;
                  break;
                case VesselAutopilot.AutopilotMode.RadialOut:
                  rsas_target_ = -radial;
                  break;
                case VesselAutopilot.AutopilotMode.Normal:
                  rsas_target_ = normal;
                  break;
                case VesselAutopilot.AutopilotMode.Antinormal:
                  rsas_target_ = -normal;
                  break;
                default:
                  override_rsas_target_ = false;
                  break;
                  }
                }
                  }
                }
            }
예제 #2
0
 private void Cleanup()
 {
     UnityEngine.Object.Destroy(map_renderer_);
     map_node_pool_.Clear();
     map_renderer_ = null;
     Interface.DeletePlugin(ref plugin_);
     plotting_frame_selector_.reset();
     flight_planner_.reset();
     navball_changed_ = true;
 }