예제 #1
0
        private static IEnumerable <IMyCubeGrid> GetStationsInRange(Vector3D playerPositon)
        {
            var sphereAroundPlayer = new VRageMath.BoundingSphereD(playerPositon, 500);
            var grids = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphereAroundPlayer);

            return(grids
                   .Where(b => (b as IMyCubeGrid) != null)
                   .OrderBy(a => (playerPositon - a.GetPosition()).Length())
                   .Select(a => a as IMyCubeGrid));
        }
예제 #2
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix    = ViewProjectionMatrix;
            BoundingFrustumFar.Matrix = ViewProjectionMatrixFar;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
예제 #3
0
        List <IMySlimBlock> IMyCubeGrid.GetBlocksInsideSphere(ref VRageMath.BoundingSphereD sphere)
        {
            HashSet <MySlimBlock> blocks = new HashSet <MySlimBlock>();

            GetBlocksInsideSphere(ref sphere, blocks);
            var result = new List <IMySlimBlock>(blocks.Count);

            foreach (var block in blocks)
            {
                result.Add(block);
            }
            return(result);
        }
        /// <summary>
        ///
        /// SERVER ONLY FUNCTION
        ///
        /// Server will periodically determine which contacts are near a grid
        /// with radar and send them out in a message.  This is a workaround
        /// for the fact that not all entities within radar range may be
        /// streamed to the client.
        /// </summary>
        private void DoAcquisitionSweep()
        {
            //_logger.debugLog("Running acquisition sweep", "DoAcquisitionSweep");

            Vector3D pos = _grid.WorldAABB.Center;

            VRageMath.BoundingSphereD sphere
                = new VRageMath.BoundingSphereD(pos, _settings.range);
            List <IMyEntity> ents
                = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

            List <RemoteContact> contacts = new List <RemoteContact>();

            foreach (IMyEntity e in ents)
            {
                if (e == _grid)
                {
                    continue;
                }

                if (e is IMyCubeGrid)
                {
                    Vector3D vecTo = e.WorldAABB.Center - pos;

                    contacts.Add(new RemoteContact()
                    {
                        entId = e.EntityId,
                        pos   = e.WorldAABB.Center,
                        xsec  = EWMath.DetermineXSection(e as IMyCubeGrid, vecTo)
                    });
                }
            }

            // Send the contact list, even if it is blank.  This is how the
            // client will know when distant contacts have gone out of range
            // or disappeared.
            //_logger.debugLog($"List<RemoteContact> -> Clients with {contacts.Count} entities", "DoAcquisitionSweep");
            Message <BlockAddress, List <RemoteContact> > msg
                = new Message <BlockAddress, List <RemoteContact> >(
                      new BlockAddress(this.GridID, this.BlockID),
                      contacts);

            MyAPIGateway.Multiplayer.SendMessageToOthers(
                Constants.MIDAcquisitionSweep,
                msg.ToXML());
        }
예제 #5
0
        /// <summary>
        /// Tests whether the BoundingBox contains a BoundingSphere.
        /// </summary>
        /// <param name="sphere">The BoundingSphere to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param>
        public void Contains(ref BoundingSphereD sphere, out ContainmentType result)
        {
            Vector3D result1;

            Vector3D.Clamp(ref sphere.Center, ref this.Min, ref this.Max, out result1);
            double result2;

            Vector3D.DistanceSquared(ref sphere.Center, ref result1, out result2);
            double num = sphere.Radius;

            if ((double)result2 > (double)num * (double)num)
            {
                result = ContainmentType.Disjoint;
            }
            else
            {
                result = (double)this.Min.X + (double)num > (double)sphere.Center.X || (double)sphere.Center.X > (double)this.Max.X - (double)num || ((double)this.Max.X - (double)this.Min.X <= (double)num || (double)this.Min.Y + (double)num > (double)sphere.Center.Y) || ((double)sphere.Center.Y > (double)this.Max.Y - (double)num || (double)this.Max.Y - (double)this.Min.Y <= (double)num || ((double)this.Min.Z + (double)num > (double)sphere.Center.Z || (double)sphere.Center.Z > (double)this.Max.Z - (double)num)) || (double)this.Max.X - (double)this.Min.X <= (double)num ? ContainmentType.Intersects : ContainmentType.Contains;
            }
        }
예제 #6
0
        public ContainmentType Contains(BoundingSphereD sphere)
        {
            Vector3D vectord;
            double   num;

            Vector3D.Clamp(ref sphere.Center, ref this.Min, ref this.Max, out vectord);
            Vector3D.DistanceSquared(ref sphere.Center, ref vectord, out num);
            double radius = sphere.Radius;

            if (num > (radius * radius))
            {
                return(ContainmentType.Disjoint);
            }
            if ((((((this.Min.X + radius) <= sphere.Center.X) && (sphere.Center.X <= (this.Max.X - radius))) && (((this.Max.X - this.Min.X) > radius) && ((this.Min.Y + radius) <= sphere.Center.Y))) && (((sphere.Center.Y <= (this.Max.Y - radius)) && ((this.Max.Y - this.Min.Y) > radius)) && (((this.Min.Z + radius) <= sphere.Center.Z) && (sphere.Center.Z <= (this.Max.Z - radius))))) && ((this.Max.X - this.Min.X) > radius))
            {
                return(ContainmentType.Contains);
            }
            return(ContainmentType.Intersects);
        }
예제 #7
0
        // Test whether this box intersects the given sphere
        public bool Intersects(ref BoundingSphereD sphere)
        {
            // Transform the sphere into local box space
            Quaternion iq          = Quaternion.Conjugate(Orientation);
            Vector3    localCenter = Vector3.Transform(sphere.Center - Center, iq);

            // (dx,dy,dz) = signed distance of center of sphere from edge of box
            double dx = Math.Abs(localCenter.X) - HalfExtent.X;
            double dy = Math.Abs(localCenter.Y) - HalfExtent.Y;
            double dz = Math.Abs(localCenter.Z) - HalfExtent.Z;

            // Compute how far away the sphere is in each dimension
            dx = Math.Max(dx, 0.0f);
            dy = Math.Max(dy, 0.0f);
            dz = Math.Max(dz, 0.0f);
            double r = sphere.Radius;

            return(dx * dx + dy * dy + dz * dz < r * r);
        }
예제 #8
0
        /// <summary>
        /// Checks whether the current BoundingFrustumD contains the specified BoundingSphere.
        /// </summary>
        /// <param name="sphere">The BoundingSphere to check against the current BoundingFrustumD.</param>
        public ContainmentType Contains(BoundingSphereD sphere)
        {
            Vector3D Vector3D = sphere.Center;
            double   num1     = sphere.Radius;
            int      num2     = 0;

            foreach (PlaneD plane in this.planes)
            {
                double num3 = (double)((double)plane.Normal.X * (double)Vector3D.X + (double)plane.Normal.Y * (double)Vector3D.Y + (double)plane.Normal.Z * (double)Vector3D.Z) + plane.D;
                if ((double)num3 > (double)num1)
                {
                    return(ContainmentType.Disjoint);
                }
                if ((double)num3 < -(double)num1)
                {
                    ++num2;
                }
            }
            return(num2 != 6 ? ContainmentType.Intersects : ContainmentType.Contains);
        }
예제 #9
0
        /// <summary>
        /// Checks whether the current BoundingFrustumD contains the specified BoundingSphere.
        /// </summary>
        /// <param name="sphere">The BoundingSphere to test for overlap.</param><param name="result">[OutAttribute] Enumeration indicating the extent of overlap.</param>
        public void Contains(ref BoundingSphereD sphere, out ContainmentType result)
        {
            Vector3D Vector3D = sphere.Center;
            double   num1     = sphere.Radius;
            int      num2     = 0;

            foreach (PlaneD plane in this.planes)
            {
                double num3 = (double)((double)plane.Normal.X * (double)Vector3D.X + (double)plane.Normal.Y * (double)Vector3D.Y + (double)plane.Normal.Z * (double)Vector3D.Z) + plane.D;
                if ((double)num3 > (double)num1)
                {
                    result = ContainmentType.Disjoint;
                    return;
                }
                else if ((double)num3 < -(double)num1)
                {
                    ++num2;
                }
            }
            result = num2 == 6 ? ContainmentType.Contains : ContainmentType.Intersects;
        }
예제 #10
0
        public void Contains(ref BoundingSphereD sphere, out ContainmentType result)
        {
            Vector3D center = sphere.Center;
            double   radius = sphere.Radius;
            int      num2   = 0;

            foreach (PlaneD ed in this.planes)
            {
                double num3 = (((ed.Normal.X * center.X) + (ed.Normal.Y * center.Y)) + (ed.Normal.Z * center.Z)) + ed.D;
                if (num3 > radius)
                {
                    result = ContainmentType.Disjoint;
                    return;
                }
                if (num3 < -radius)
                {
                    num2++;
                }
            }
            result = (num2 == 6) ? ContainmentType.Contains : ContainmentType.Intersects;
        }
        public ContainmentType Contains(ref BoundingSphereD sphere)
        {
            Quaternion rotation = Quaternion.Conjugate(this.Orientation);
            Vector3    vector   = Vector3.Transform((Vector3)(sphere.Center - this.Center), rotation);
            double     num      = Math.Abs(vector.X) - this.HalfExtent.X;
            double     num2     = Math.Abs(vector.Y) - this.HalfExtent.Y;
            double     num3     = Math.Abs(vector.Z) - this.HalfExtent.Z;
            double     radius   = sphere.Radius;

            if (((num <= -radius) && (num2 <= -radius)) && (num3 <= -radius))
            {
                return(ContainmentType.Contains);
            }
            num  = Math.Max(num, 0.0);
            num2 = Math.Max(num2, 0.0);
            num3 = Math.Max(num3, 0.0);
            if ((((num * num) + (num2 * num2)) + (num3 * num3)) >= (radius * radius))
            {
                return(ContainmentType.Disjoint);
            }
            return(ContainmentType.Intersects);
        }
예제 #12
0
        public ContainmentType Contains(BoundingSphereD sphere)
        {
            Vector3D center = sphere.Center;
            double   radius = sphere.Radius;
            int      num2   = 0;

            foreach (PlaneD ed in this.planes)
            {
                double num3 = (((ed.Normal.X * center.X) + (ed.Normal.Y * center.Y)) + (ed.Normal.Z * center.Z)) + ed.D;
                if (num3 > radius)
                {
                    return(ContainmentType.Disjoint);
                }
                if (num3 < -radius)
                {
                    num2++;
                }
            }
            if (num2 == 6)
            {
                return(ContainmentType.Contains);
            }
            return(ContainmentType.Intersects);
        }
예제 #13
0
 bool IMyCamera.IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     return(IsInFrustum(ref boundingSphere));
 }
예제 #14
0
 bool IMyCamera.IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     return IsInFrustum(ref boundingSphere);
 }
예제 #15
0
 //  Checks if specified bounding sphere is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding sphere.
 //  Don't use BoundingSphere.Transform. Instead transform sphere center manualy and then create new sphere.
 public bool IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     VRageMath.ContainmentType result;
     BoundingFrustum.Contains(ref boundingSphere, out result);
     return result != VRageMath.ContainmentType.Disjoint;
 }
예제 #16
0
        void UpdateBoundingFrustum()
        {
            //  Update frustum
            BoundingFrustum.Matrix = ViewProjectionMatrix;
            BoundingFrustumFar.Matrix = ViewProjectionMatrixFar;

            //  Update bounding box
            BoundingBox = BoundingBoxD.CreateInvalid();
            BoundingBox.Include(ref BoundingFrustum);

            //  Update bounding sphere
            BoundingSphere = MyUtils.GetBoundingSphereFromBoundingBox(ref BoundingBox);
        }
예제 #17
0
 public BoundingBoxD Include(BoundingSphereD sphere)
 {
     return(Include(ref sphere));
 }
예제 #18
0
 public BoundingBoxD Include(BoundingSphereD sphere) =>
 this.Include(ref sphere);
예제 #19
0
 /// <summary>
 /// Checks whether the current BoundingBox intersects a BoundingSphere.
 /// </summary>
 /// <param name="sphere">The BoundingSphere to check for intersection with.</param>
 public bool Intersects(BoundingSphereD sphere)
 {
     return(Intersects(ref sphere));
 }
예제 #20
0
 public bool Intersects(BoundingSphereD sphere) =>
 this.Intersects(ref sphere);
예제 #21
0
 //  Checks if specified bounding sphere is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding sphere.
 //  Don't use BoundingSphere.Transform. Instead transform sphere center manualy and then create new sphere.
 public bool IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     VRageMath.ContainmentType result;
     BoundingFrustum.Contains(ref boundingSphere, out result);
     return(result != VRageMath.ContainmentType.Disjoint);
 }
예제 #22
0
 void IMyEntity.GetTrianglesIntersectingSphere(ref VRageMath.BoundingSphereD sphere, VRageMath.Vector3?referenceNormalVector, float?maxAngle, List <MyTriangle_Vertex_Normals> retTriangles, int maxNeighbourTriangles)
 {
     GetTrianglesIntersectingSphere(ref sphere, referenceNormalVector, maxAngle, retTriangles, maxNeighbourTriangles);
 }
예제 #23
0
        /// <summary>
        /// Returns a list of grids in the vicinity of the CP
        /// </summary>
        /// <param name="cp">Control point to check</param>
        /// <returns></returns>
        private List<IMyCubeGrid> getGridsInCPRadius(ControlPoint cp)
        {
            // Get all ents within the radius
            VRageMath.BoundingSphereD bounds =
                new VRageMath.BoundingSphereD(cp.Position, (double)cp.Radius);
            List<IMyEntity> ents =
                MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds);

            // Get only the ships/stations
            List<IMyCubeGrid> grids = new List<IMyCubeGrid>();
            foreach (IMyEntity e in ents) {
                if (e is IMyCubeGrid)
                    grids.Add(e as IMyCubeGrid);
            }

            return grids;
        }
예제 #24
0
 bool IMyEntity.GetIntersectionWithSphere(ref VRageMath.BoundingSphereD sphere)
 {
     return(GetIntersectionWithSphere(ref sphere));
 }