Пример #1
0
        private void UpdateExitOrbit(Vessel nearObject, Vessel farObject)
        {
            if (predictionsDrawn)
            {
                if (!IsPatchedConicsAvailable)
                {
                    HideExitOrbit();
                }
                else
                {
                    Vector3   a      = ScaledSpace.ScaledToLocalSpace(MapView.MapCamera.transform.position);
                    MapObject target = MapView.MapCamera.target;
                    Vector3   b      = ScaledSpace.ScaledToLocalSpace(target.transform.position);
                    Vector3.Distance(a, b);
                    Vector3d vel = ESLDBeacon.GetJumpVelOffset(nearObject, farObject);
                    predictionOrbitRenderer.driver.referenceBody       = farObject.mainBody;
                    predictionOrbitRenderer.driver.orbit.referenceBody = farObject.mainBody;
                    predictionOrbitRenderer.driver.pos    = farObject.orbit.pos;
                    predictionOrbitRenderer.celestialBody = farObject.mainBody;
                    predictionOrbitRenderer.SetColor(Color.red);
                    predictionOrbitDriver.orbit.UpdateFromStateVectors(farObject.orbit.pos, vel, farObject.mainBody, Planetarium.GetUniversalTime());

                    /* Direction indicator is broken/not required
                     *      float baseWidth = 20.0f;
                     *      double baseStart = 10;
                     *      double baseEnd = 50;
                     *      oDirection.transform.position = ScaledSpace.LocalToScaledSpace(far.transform.position);
                     *      if (dirScalar / 325000 > baseWidth) baseWidth = dirScalar / 325000f;
                     *      oDirection.SetWidth(baseWidth, 0.01f);
                     *      if (dirScalar / 650000 > baseStart) baseStart = dirScalar / 650000;
                     *      if (dirScalar / 130000 > baseEnd) baseEnd = dirScalar / 130000;
                     * //               log.debug("Camera distance is " + dirScalar + " results: " + baseWidth + " " + baseStart + " " + baseEnd);
                     *      oDirection.SetPosition(0, Vector3d.zero + exitTraj.xzy.normalized * baseStart);
                     *  oDirection.SetPosition(1, exitTraj.xzy.normalized * baseEnd);
                     *      oDirection.transform.eulerAngles = Vector3d.zero;*/
                }
            }
        }
Пример #2
0
        // Show exit orbital predictions
        private void ShowExitOrbit(Vessel nearObject, Vessel farObject)
        {
            // Recenter map, save previous state.
            wasInMapView = MapView.MapIsEnabled;
            if (!MapView.MapIsEnabled)
            {
                MapView.EnterMapView();
            }
            MapObject mapObject = FindVesselBody(farObject);

            if ((UnityEngine.Object)mapObject != (UnityEngine.Object)null)
            {
                MapView.MapCamera.SetTarget(mapObject);
            }
            Vector3 mapCamPos = ScaledSpace.ScaledToLocalSpace(MapView.MapCamera.transform.position);
            Vector3 farTarPos = ScaledSpace.ScaledToLocalSpace(mapObject.transform.position);
            float   dirScalar = Vector3.Distance(mapCamPos, farTarPos);

            //log.Debug("Initializing, camera distance is " + dirScalar);
            if (!IsPatchedConicsAvailable)
            {
                HideExitOrbit();
            }
            else
            {
                predictionsDrawn = true;
                Vector3d vel = ESLDBeacon.GetJumpVelOffset(nearObject, farObject);
                if (predictionGameObject != null)
                {
                    Destroy(predictionGameObject);
                }

                predictionGameObject  = new GameObject("OrbitRendererGameObject");
                predictionOrbitDriver = predictionGameObject.AddComponent <OrbitDriver>();
                predictionOrbitDriver.orbit.referenceBody = farObject.mainBody;
                predictionOrbitDriver.orbit              = new Orbit();
                predictionOrbitDriver.referenceBody      = farObject.mainBody;
                predictionOrbitDriver.upperCamVsSmaRatio = 999999f;  // Took forever to figure this out - this sets at what zoom level the orbit appears.  Was causing it not to appear at small bodies.
                predictionOrbitDriver.lowerCamVsSmaRatio = 0.0001f;
                predictionOrbitDriver.orbit.UpdateFromStateVectors(farObject.orbit.pos, vel, farObject.mainBody, Planetarium.GetUniversalTime());
                predictionOrbitDriver.orbit.Init();
                Vector3d relativePositionAtUT = predictionOrbitDriver.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
                Vector3d orbitalVelocityAtUT  = predictionOrbitDriver.orbit.getOrbitalVelocityAtUT(Planetarium.GetUniversalTime());
                predictionOrbitDriver.orbit.h    = Vector3d.Cross(relativePositionAtUT, orbitalVelocityAtUT);
                predictionOrbitDriver.updateMode = OrbitDriver.UpdateMode.TRACK_Phys;
                predictionOrbitDriver.orbitColor = Color.red;
                predictionOrbitRenderer          = predictionGameObject.AddComponent <OrbitRenderer>();
                predictionOrbitRenderer.SetColor(Color.red);
                predictionOrbitRenderer.vessel             = vessel;
                predictionOrbitDriver.vessel               = vessel;
                predictionOrbitRenderer.upperCamVsSmaRatio = 999999f;
                predictionOrbitRenderer.lowerCamVsSmaRatio = 0.0001f;
                predictionOrbitRenderer.celestialBody      = farObject.mainBody;
                predictionOrbitRenderer.driver             = predictionOrbitDriver;
                predictionOrbitDriver.Renderer             = predictionOrbitRenderer;

                if (true)
                {
                    // This draws the full Patched Conics prediction.
                    predictionPatchedConicSolver      = predictionGameObject.AddComponent <PatchedConicSolver>();
                    predictionPatchedConicRenderer    = predictionGameObject.AddComponent <PatchedConicRenderer>();
                    predictionOrbitRenderer.drawIcons = OrbitRendererBase.DrawIcons.NONE;
                    predictionOrbitRenderer.drawMode  = OrbitRendererBase.DrawMode.OFF;
                }
#if false
                else
                {
                    // This draws just the first patch, similar to a Level 1 tracking station.
                    predictionOrbitRenderer.driver.drawOrbit = true;
                    predictionOrbitRenderer.drawIcons        = OrbitRenderer.DrawIcons.OBJ_PE_AP;
                    predictionOrbitRenderer.drawMode         = OrbitRenderer.DrawMode.REDRAW_AND_RECALCULATE;
                    predictionOrbitRenderer.enabled          = true;
                }
#endif
                base.StartCoroutine(NullOrbitDriverVessels());
                // Splash some color on it.

                // Directional indicator.

                /*
                 *  float baseWidth = 20.0f;
                 *  double baseStart = 10;
                 *  double baseEnd = 50;
                 *  oDirObj = new GameObject("Indicator");
                 *  oDirObj.layer = 10; // Map layer!
                 *  oDirection = oDirObj.AddComponent<LineRenderer>();
                 *  oDirection.useWorldSpace = false;
                 *  oOrigin = null;
                 *  foreach (Transform sstr in ScaledSpace.Instance.scaledSpaceTransforms)
                 *  {
                 *      if (sstr.name == far.mainBody.name)
                 *      {
                 *          oOrigin = sstr;
                 *          log.debug("Found origin: " + sstr.name);
                 *          break;
                 *      }
                 *  }
                 *  oDirection.transform.parent = oOrigin;
                 *  oDirection.transform.position = ScaledSpace.LocalToScaledSpace(far.transform.position);
                 *  oDirection.material = new Material(Shader.Find("Particles/Additive"));
                 *  oDirection.SetColors(Color.clear, Color.red);
                 *  if (dirScalar / 325000 > baseWidth) baseWidth = dirScalar / 325000f;
                 *  oDirection.SetWidth(baseWidth, 0.01f);
                 *  log.debug("Base Width set to " + baseWidth);
                 *  oDirection.SetVertexCount(2);
                 *  if (dirScalar / 650000 > baseStart) baseStart = dirScalar / 650000;
                 *  if (dirScalar / 130000 > baseEnd) baseEnd = dirScalar / 130000;
                 *  log.debug("Base Start set to " + baseStart);
                 *  log.debug("Base End set to " + baseEnd);
                 *  oDirection.SetPosition(0, Vector3d.zero + exitTraj.xzy.normalized * baseStart);
                 *  oDirection.SetPosition(1, exitTraj.xzy.normalized * baseEnd);
                 *  oDirection.enabled = true;
                 */
            }
        }