bool IMyShipController.TryGetPlanetElevation(MyPlanetElevation detail, out double elevation)
        {
            var blockPosition = this.PositionComp.GetPosition();

            if (!MyGravityProviderSystem.IsPositionInNaturalGravity(blockPosition))
            {
                elevation = double.PositiveInfinity;
                return(false);
            }
            var boundingBox   = PositionComp.WorldAABB;
            var nearestPlanet = MyGamePruningStructure.GetClosestPlanet(ref boundingBox);

            if (nearestPlanet == null)
            {
                elevation = double.PositiveInfinity;
                return(false);
            }

            switch (detail)
            {
            case MyPlanetElevation.Sealevel:
                elevation = ((boundingBox.Center - nearestPlanet.PositionComp.GetPosition()).Length() - nearestPlanet.AverageRadius);
                return(true);

            case MyPlanetElevation.Surface:
                var      controlledEntityPosition = CubeGrid.Physics.CenterOfMassWorld;
                Vector3D closestPoint             = nearestPlanet.GetClosestSurfacePointGlobal(ref controlledEntityPosition);
                elevation = Vector3D.Distance(closestPoint, controlledEntityPosition);
                return(true);

            default:
                throw new ArgumentOutOfRangeException("detail", detail, null);
            }
        }
 public void Start(float targetSpeed, Base6Directions.Direction forward, double targetAltDescending = 0, double targetAltAcending = double.MaxValue, bool useSealevel = false, bool disableOnNaturalGravityExit = true)
 {
     Enabled             = true;
     TargetSpeed         = targetSpeed;
     AdaptiveTargetSpeed = targetSpeed;
     if (forward == Base6Directions.Direction.Left)
     {
         Forward = autoForward;
     }
     else
     {
         Forward = forward;
     }
     //EnableThrusters(reverse, false);
     if (targetSpeed < 0)
     {
         descending = true;
     }
     else
     {
         descending = false;
     }
     if (useSealevel)
     {
         elevationType = MyPlanetElevation.Sealevel;
     }
     else
     {
         elevationType = MyPlanetElevation.Surface;
     }
     TargetAltAcending           = targetAltAcending;
     TargetAltDescending         = targetAltDescending;
     DisableOnNaturalGravityExit = disableOnNaturalGravityExit;
     startedInNaturalGravity     = controller.GetNaturalGravity().Length() > 0;
 }
 public bool TryGetPlanetElevation(MyPlanetElevation detail, out double elevation)
 {
     throw new NotImplementedException();
 }
        bool IMyShipController.TryGetPlanetElevation(MyPlanetElevation detail, out double elevation)
        {
            var blockPosition = this.PositionComp.GetPosition();
            if (!MyGravityProviderSystem.IsPositionInNaturalGravity(blockPosition))
            {
                elevation = double.PositiveInfinity;
                return false;
            }            
            var boundingBox = PositionComp.WorldAABB;
            var nearestPlanet = MyGamePruningStructure.GetClosestPlanet(ref boundingBox);
            if (nearestPlanet == null)
            {
                elevation = double.PositiveInfinity;
                return false;
            }

            switch (detail)
            {
                case MyPlanetElevation.Sealevel:
                    elevation = ((boundingBox.Center - nearestPlanet.PositionComp.GetPosition()).Length() - nearestPlanet.AverageRadius);
                    return true;

                case MyPlanetElevation.Surface:
                    var controlledEntityPosition = CubeGrid.Physics.CenterOfMassWorld;
                    Vector3D closestPoint = nearestPlanet.GetClosestSurfacePointGlobal(ref controlledEntityPosition);
                    elevation = Vector3D.Distance(closestPoint, controlledEntityPosition);
                    return true;

                default:
                    throw new ArgumentOutOfRangeException("detail", detail, null);
            }
        }