Example #1
0
        /// <summary>
        /// This quickly checks if a given position is in any natural gravity.
        /// </summary>
        /// <param name="position">Position to check</param>
        /// <param name="sphereSize">Sphere size to test with.</param>
        /// <returns>True if there is natural gravity at this position, false otherwise.</returns>
        public static bool IsPositionInNaturalGravity(Vector3D position, double sphereSize = 0)
        {
            // Clamp sphere size to be at least 0.
            sphereSize = MathHelper.Max(sphereSize, 0);

            for (int i = 0; i < m_planetGenerators.Count; i++)
            {
                IMyGravityProvider provider = m_planetGenerators[i];
                if (provider == null)
                {
                    continue;
                }

                MyPlanet planet = provider as MyPlanet;
                if (planet == null)
                {
                    continue;
                }

                //we don't really care which planet's gravity we're in, so return as soon as we find one
                if (planet.IsPositionInGravityWell(position))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static Vector3D GetNaturalGravityAtPoint(Vector3D point)
        {
            var gravity = Vector3D.Zero;

            foreach (var planet in _planets)
            {
                IMyGravityProvider gravityProvider = planet.Components.Get <MyGravityProviderComponent>();
                if (gravityProvider != null)
                {
                    gravity += gravityProvider.GetWorldGravity(point);
                }
            }
            return(gravity);
        }
        /// <summary>
        /// Returns the planet that has the most influential gravity well in the given world point.
        /// The most influential gravity well is defined as the planet that has the highest gravity in the point and
        /// if no such planet is found, it returns the planet, whose gravity well is the closest to the given point.
        /// </summary>
        /// <param name="worldPosition">Position to test for the strongest gravity well</param>
        /// <returns>Planet that has the most influential gravity well in the given world point</returns>
        public static double GetStrongestNaturalGravityWell(Vector3D worldPosition, out IMyGravityProvider nearestProvider)
        {
            double maxMetricValue = double.MinValue;

            nearestProvider = null;

            foreach (IMyGravityProvider gravityProvider in m_naturalGravityGenerators)
            {
                var grav = gravityProvider.GetWorldGravity(worldPosition).Length();

                if (grav > maxMetricValue)
                {
                    maxMetricValue  = grav;
                    nearestProvider = gravityProvider;
                }
            }

            return(maxMetricValue);
        }
        /// <summary>
        /// Checks if the specified trajectory intersects any natural gravity wells.
        /// </summary>
        /// <param name="start">Starting point of the trajectory.</param>
        /// <param name="end">Destination of the trajectory.</param>
        /// <param name="raySize">Size of the ray to test with. (Cylinder test)</param>
        /// DI: Do you mean capsule?
        /// <returns></returns>
        public static bool DoesTrajectoryIntersectNaturalGravity(Vector3D start, Vector3D end, double raySize = 0)
        {
            // If the start and end point are identical, do a sphere test instead.
            Vector3D direction = start - end;

            if (Vector3D.IsZero(direction))
            {
                return(IsPositionInNaturalGravity(start, raySize));
            }

            Ray trajectory = new Ray(start, Vector3.Normalize(direction));

            // Clamp ray size to be at least 0.
            raySize = MathHelper.Max(raySize, 0);

            for (int i = 0; i < m_naturalGravityGenerators.Count; i++)
            {
                IMyGravityProvider provider = m_naturalGravityGenerators[i];
                if (provider == null)
                {
                    continue;
                }

                // This should be done some other way, but works for nau
                MySphericalNaturalGravityComponent spherical = provider as MySphericalNaturalGravityComponent;
                if (spherical == null)
                {
                    continue;
                }

                //create a bounding sphere to represent the gravity sphere around the planet
                BoundingSphereD gravitySphere = new BoundingSphereD(spherical.Position, spherical.GravityLimit + raySize);

                //check for intersections
                float?intersect = trajectory.Intersects(gravitySphere);
                if (intersect.HasValue)
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// This quickly checks if a given position is in any natural gravity.
        /// </summary>
        /// <param name="position">Position to check</param>
        /// <param name="sphereSize">Sphere size to test with.</param>
        /// <returns>True if there is natural gravity at this position, false otherwise.</returns>
        public static bool IsPositionInNaturalGravity(Vector3D position, double sphereSize = 0)
        {
            // Clamp sphere size to be at least 0.
            // TODO (DI/TT): Finish dis and add grav gens to a tree or smthing
            sphereSize = MathHelper.Max(sphereSize, 0);

            for (int i = 0; i < m_naturalGravityGenerators.Count; i++)
            {
                IMyGravityProvider provider = m_naturalGravityGenerators[i];
                if (provider == null)
                {
                    continue;
                }

                //we don't really care which planet's gravity we're in, so return as soon as we find one
                if (provider.IsPositionInRange(position))
                {
                    return(true);
                }
            }

            return(false);
        }
 public static void RemoveGravityGenerator(IMyGravityProvider gravityGenerator)
 {
     m_gravityGenerators.Remove(gravityGenerator);
 }
 public static void AddGravityGenerator(IMyGravityProvider gravityGenerator)
 {
     m_gravityGenerators.Add(gravityGenerator);
 }
        /// <summary>
        /// Returns the planet that has the most influential gravity well in the given world point.
        /// The most influential gravity well is defined as the planet that has the highest gravity in the point and
        /// if no such planet is found, it returns the planet, whose gravity well is the closest to the given point.
        /// </summary>
        /// <param name="worldPosition">Position to test for the strongest gravity well</param>
        /// <returns>Planet that has the most influential gravity well in the given world point</returns>
        public static double GetStrongestNaturalGravityWell(Vector3D worldPosition, out IMyGravityProvider nearestProvider)
        {
            double maxMetricValue = double.MinValue;
            nearestProvider = null;

            foreach (IMyGravityProvider gravityProvider in m_naturalGravityGenerators)
            {
                var grav = gravityProvider.GetWorldGravity(worldPosition).Length();

                if (grav > maxMetricValue)
                {
                    maxMetricValue = grav;
                    nearestProvider = gravityProvider;
                }
            }

            return maxMetricValue;
        }
Example #9
0
 public static void RemovePlanet(IMyGravityProvider gravityGenerator)
 {
     m_planetGenerators.Remove(gravityGenerator);
 }
Example #10
0
 public static void AddPlanet(IMyGravityProvider gravityGenerator)
 {
     m_planetGenerators.Add(gravityGenerator);
 }
Example #11
0
 public static void RemoveGravityGenerator(IMyGravityProvider gravityGenerator)
 {
     m_gravityGenerators.Remove(gravityGenerator);
 }
 public static void RemovePlanet(IMyGravityProvider gravityGenerator)
 {
     m_planetGenerators.Remove(gravityGenerator);
     m_gravityGenerators.Remove(gravityGenerator);
 }
 public static void RemoveNaturalGravityProvider(IMyGravityProvider gravityGenerator)
 {
     m_naturalGravityGenerators.Remove(gravityGenerator);
 }
 public static void AddNaturalGravityProvider(IMyGravityProvider gravityGenerator)
 {
     m_naturalGravityGenerators.Add(gravityGenerator);
 }
 public static void AddNaturalGravityProvider(IMyGravityProvider gravityGenerator)
 {
     m_naturalGravityGenerators.Add(gravityGenerator);
 }
Example #16
0
 public static void AddGravityGenerator(IMyGravityProvider gravityGenerator)
 {
     m_gravityGenerators.Add(gravityGenerator);
 }
 public static void RemoveNaturalGravityProvider(IMyGravityProvider gravityGenerator)
 {
     m_naturalGravityGenerators.Remove(gravityGenerator);
 }
 public static void AddPlanet(IMyGravityProvider gravityGenerator)
 {
     m_planetGenerators.Add(gravityGenerator);
     m_gravityGenerators.Add(gravityGenerator);
 }