コード例 #1
0
        private void FindGridBounds()
        {
            BoxAAB = new BoundingBoxD();
            BoxAAB.Include(_BiggestGrid.CalculateBoundingBox());

            MatrixD BiggestGridMatrix        = _BiggestGrid.PositionAndOrientation.Value.GetMatrix();
            MatrixD BiggestGridMatrixToLocal = MatrixD.Invert(BiggestGridMatrix);


            Vector3D[] corners = new Vector3D[8];
            foreach (var grid in _grids)
            {
                if (grid == _BiggestGrid)
                {
                    continue;
                }


                BoundingBoxD box = grid.CalculateBoundingBox();

                MyOrientedBoundingBoxD worldBox = new MyOrientedBoundingBoxD(box, grid.PositionAndOrientation.Value.GetMatrix());
                worldBox.Transform(BiggestGridMatrixToLocal);
                worldBox.GetCorners(corners, 0);

                foreach (var corner in corners)
                {
                    BoxAAB.Include(corner);
                }
            }

            BoundingSphereD Sphere = BoundingSphereD.CreateFromBoundingBox(BoxAAB);

            BoxD    = new MyOrientedBoundingBoxD(BoxAAB, BiggestGridMatrix);
            SphereD = new BoundingSphereD(BoxD.Center, Sphere.Radius);



            //Test bounds to make sure they are in the right spot

            /*
             *
             * long ID = MySession.Static.Players.TryGetIdentityId(76561198045096439);
             * Vector3D[] array = new Vector3D[8];
             * BoxD.GetCorners(array, 0);
             *
             * for (int i = 0; i <= 7; i++)
             * {
             *  CharacterUtilities.SendGps(array[i], i.ToString(), ID, 10);
             * }
             */

            //Log.Info($"HangarDebug: {BoxD.ToString()}");
        }
コード例 #2
0
        public void InitLazy(MyObjectBuilder_DefinitionBase baseBuilder)
        {
            MyObjectBuilder_PrefabDefinition definition = baseBuilder as MyObjectBuilder_PrefabDefinition;

            if ((definition.CubeGrid != null) || (definition.CubeGrids != null))
            {
                if (definition.CubeGrid == null)
                {
                    this.m_cubeGrids = definition.CubeGrids;
                }
                else
                {
                    this.m_cubeGrids = new MyObjectBuilder_CubeGrid[] { definition.CubeGrid };
                }
                this.m_boundingSphere = new VRageMath.BoundingSphere(Vector3.Zero, float.MinValue);
                this.m_boundingBox    = VRageMath.BoundingBox.CreateInvalid();
                MyObjectBuilder_CubeGrid[] cubeGrids = this.m_cubeGrids;
                int index = 0;
                while (index < cubeGrids.Length)
                {
                    Matrix identity;
                    MyObjectBuilder_CubeGrid grid = cubeGrids[index];
                    VRageMath.BoundingBox    box  = grid.CalculateBoundingBox();
                    if (grid.PositionAndOrientation == null)
                    {
                        identity = Matrix.Identity;
                    }
                    else
                    {
                        identity = (Matrix)grid.PositionAndOrientation.Value.GetMatrix();
                    }
                    this.m_boundingBox.Include(box.Transform(identity));
                    index++;
                }
                this.m_boundingSphere = VRageMath.BoundingSphere.CreateFromBoundingBox(this.m_boundingBox);
                cubeGrids             = this.m_cubeGrids;
                for (index = 0; index < cubeGrids.Length; index++)
                {
                    MyObjectBuilder_CubeGrid grid1 = cubeGrids[index];
                    grid1.CreatePhysics = true;
                    grid1.XMirroxPlane  = null;
                    grid1.YMirroxPlane  = null;
                    grid1.ZMirroxPlane  = null;
                }
                this.Initialized = true;
            }
        }
コード例 #3
0
 public static BoundingSphere CalculateBoundingSphere(this MyObjectBuilder_CubeGrid grid)
 {
     return(BoundingSphere.CreateFromBoundingBox(grid.CalculateBoundingBox()));
 }