示例#1
0
        //  Create vertex buffers and index buffers and fill them with voxel render cells
        //  IMPORTANT: Don't call from background thread or from LoadContent. Only from Draw call
        public static void PrepareRenderCellCache()
        {
            MyMwcLog.WriteLine("MyVoxelMaps.PrepareRenderCellCache - START");
            MyMwcLog.IncreaseIndent();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("BoundingSphere");

            BoundingSphere sphere = new BoundingSphere(MyCamera.BoundingSphere.Center, MyCamera.BoundingSphere.Radius * 1.2f);

            MyPerformanceTimer.PrepareRenderCellCache.Start();

            for (int voxelMapIterator = 0; voxelMapIterator < m_voxelMaps.Count; voxelMapIterator++)
            {
                //  Because this LoadInDraw will stop normal update calls, we might not be able to send keep alive
                //  messages to server for some time. This will help it - it will make networking be up-to-date.
                //MyClientServer.Update();

                MyVoxelMap voxelMap = m_voxelMaps[voxelMapIterator];

                //  Only voxel maps near bounding sphere
                if (voxelMap.IsSphereIntersectingBoundingSphereOfThisVoxelMap(ref sphere))
                {
                    voxelMap.PrepareRenderCellCache();
                }
            }

            MyPerformanceTimer.PrepareRenderCellCache.End();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyVoxelMaps.PrepareRenderCellCache - END");
        }
示例#2
0
        public static bool GetListOfVoxelMapsWhoseBoundingSphereIntersectsSphere(ref BoundingSphere boundingSphere, IList <MyVoxelMap> listOfVoxelMaps, MyEntity ignorePhysObject)
        {
            listOfVoxelMaps.Clear();

            /*
             * //  Get collision elements near the line's bounding box (use sweep-and-prune, so we iterate only close objects)
             * BoundingBox boundingBox = BoundingBoxHelper.InitialBox;
             * BoundingBoxHelper.AddSphere(ref boundingSphere, ref boundingBox);
             *
             * var elements = MyEntities.GetElementsInBox(ref boundingBox);
             * foreach (MinerWars.AppCode.Physics.MyRBElement element in elements)
             * {
             *  MyEntity physicObject = ((MinerWars.AppCode.Game.Physics.MyPhysicsBody)element.GetRigidBody().m_UserData).Entity;
             *
             *  MyVoxelMap map = physicObject as MyVoxelMap;
             *  if (map != null)
             *      listOfVoxelMaps.Add(map);
             * }
             * elements.Clear();
             */
            //MyEntities.GetIntersectionWithSphere(ref boundingSphere, ignorePhysObject, null, false, false, ref list);


            for (int i = 0; i < m_voxelMaps.Count; i++)
            {
                MyVoxelMap voxelMapForCollisionTest = m_voxelMaps[i];
                if (voxelMapForCollisionTest != ignorePhysObject)
                {
                    if (voxelMapForCollisionTest.IsSphereIntersectingBoundingSphereOfThisVoxelMap(ref boundingSphere) == true)
                    {
                        listOfVoxelMaps.Add(voxelMapForCollisionTest);
                    }
                }
            }
            if (listOfVoxelMaps.Count > 0)
            {
                return(true);
            }
            //  If we get here, no intersection was found
            return(false);
        }