当前位置: 首页>>代码示例>>C#>>正文


C# BoundingBoxD.TransformFast方法代码示例

本文整理汇总了C#中BoundingBoxD.TransformFast方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBoxD.TransformFast方法的具体用法?C# BoundingBoxD.TransformFast怎么用?C# BoundingBoxD.TransformFast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoundingBoxD的用法示例。


在下文中一共展示了BoundingBoxD.TransformFast方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

        public void Init(IMy2DClipmapManager parent, int x, int y, int lod, ref BoundingBox2D bounds)
        {
            m_manager = (MyPlanetEnvironmentComponent)parent;

            var bounds3D = new BoundingBoxD(new Vector3D(bounds.Min, 0), new Vector3D(bounds.Max, 0));
            Lod = lod;

            Face = m_manager.ActiveFace;

            var matrix = m_manager.ActiveClipmap.WorldMatrix;

            bounds3D = bounds3D.TransformFast(matrix);

            Coords = new Vector2I(x, y);

            Id = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod);

            m_manager.RegisterProxy(this);

            MyEnvironmentSectorParameters sectorParams;

            matrix.Translation = Vector3D.Zero;

            sectorParams.SurfaceBasisX = Vector3.Transform(new Vector3(bounds.Width / 2, 0, 0), matrix);
            sectorParams.SurfaceBasisY = Vector3.Transform(new Vector3(0, bounds.Height / 2, 0), matrix);
            sectorParams.Center = bounds3D.Center;

            if (lod > m_manager.MaxLod) return;

            if (!m_manager.TryGetSector(Id, out EnvironmentSector))
            {
                sectorParams.SectorId = Id;
                sectorParams.EntityId = MyPlanetSectorId.MakeSectorId(x, y, m_manager.ActiveFace, lod);

                sectorParams.Bounds = m_manager.GetBoundingShape(ref sectorParams.Center, ref sectorParams.SurfaceBasisX, ref sectorParams.SurfaceBasisY); ;

                sectorParams.Environment = m_manager.EnvironmentDefinition;

                sectorParams.DataRange = new BoundingBox2I(Coords << lod, ((Coords + 1) << lod) - 1);

                sectorParams.Provider = m_manager.Providers[m_manager.ActiveFace];

                EnvironmentSector = m_manager.EnvironmentDefinition.CreateSector();
                EnvironmentSector.Init(m_manager, ref sectorParams);

                m_manager.Planet.AddChildEntity((MyEntity)EnvironmentSector);
            }

            m_manager.EnqueueOperation(this, lod);
            LodSet = lod;

            EnvironmentSector.OnLodCommit += sector_OnMyLodCommit;
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:53,代码来源:MyPlanetEnvironmentClipmapProxy.cs

示例2: AddVoxelMesh

        private void AddVoxelMesh(MyVoxelBase voxelBase, IMyStorage storage, Dictionary<Vector3I, MyIsoMesh> cache, float border, Vector3D originPosition, MyOrientedBoundingBoxD obb, List<BoundingBoxD> bbList)
        {
            bool useCache = cache != null;
            if (useCache)
                CheckCacheValidity();

            obb.HalfExtent += new Vector3D(border, 0, border);
            BoundingBoxD bb = obb.GetAABB();            
            int aabbSideSide = (int)Math.Round(bb.HalfExtents.Max() * 2);
            bb = new BoundingBoxD(bb.Min, bb.Min + aabbSideSide);
            bb.Translate(obb.Center - bb.Center);

            // For debug
            bbList.Add(new BoundingBoxD(bb.Min, bb.Max));

            bb = (BoundingBoxD)bb.TransformFast(voxelBase.PositionComp.WorldMatrixInvScaled);
            bb.Translate(voxelBase.SizeInMetresHalf);

            Vector3I min = Vector3I.Round(bb.Min);
            Vector3I max = min + aabbSideSide;
            Vector3I geomMin, geomMax;
            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref min, out geomMin);
            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref max, out geomMax);

            var cullBox = obb;
            cullBox.Transform(voxelBase.PositionComp.WorldMatrixInvScaled);
            cullBox.Center += voxelBase.SizeInMetresHalf;
            ProfilerShort.Begin("WOOOORK");

            Vector3I_RangeIterator it = new Vector3I_RangeIterator(ref geomMin, ref geomMax);
            MyCellCoord coord = new MyCellCoord();
            BoundingBox localAabb;
            coord.Lod = NAVMESH_LOD;
            int hits = 0;
            MyIsoMesh gMesh;
            Vector3 offset = originPosition - voxelBase.PositionLeftBottomCorner;

            // Calculate rotation
            Vector3 gravityVector = -Vector3.Normalize(GameSystems.MyGravityProviderSystem.CalculateTotalGravityInPoint(originPosition));
            Vector3 forwardVector = Vector3.CalculatePerpendicularVector(gravityVector);
            Quaternion quaternion = Quaternion.CreateFromForwardUp(forwardVector, gravityVector);
            Matrix rotation = Matrix.CreateFromQuaternion(Quaternion.Inverse(quaternion));

            Matrix ownRotation = voxelBase.PositionComp.WorldMatrix.GetOrientation();

            while (it.IsValid())
            {
                ProfilerShort.Begin("ITERATOR");

                if (useCache && cache.TryGetValue(it.Current, out gMesh))
                {
                    if (gMesh != null)
                    {
                        AddMeshTriangles(gMesh, offset, rotation, ownRotation);
                    }
                    it.MoveNext();
                    ProfilerShort.End();
                    continue;
                }
                    
                coord.CoordInLod = it.Current;
                MyVoxelCoordSystems.GeometryCellCoordToLocalAABB(ref coord.CoordInLod, out localAabb);
                
                if (!cullBox.Intersects(ref localAabb))
                {
                    hits++;
                    it.MoveNext();
                    ProfilerShort.End();
                    continue;
                }
                ProfilerShort.End();

                var debugBB = new BoundingBoxD(localAabb.Min, localAabb.Max).Translate(-voxelBase.SizeInMetresHalf);
                bbList.Add(debugBB);

                ProfilerShort.Begin("Mesh Calc");
                var voxelStart = coord.CoordInLod * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS - 1;
                var voxelEnd = voxelStart + MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS //- 1
                    + 1 // overlap to neighbor so geometry is stitched together within same LOD
                    + 1; // for eg. 9 vertices in row we need 9 + 1 samples (voxels)

                var generatedMesh = MyPrecalcComponent.IsoMesher.Precalc(storage, NAVMESH_LOD, voxelStart, voxelEnd, false, false, true);
                ProfilerShort.End();

                if (useCache)
                    cache[it.Current] = generatedMesh;

                if (generatedMesh != null)
                {
                    ProfilerShort.Begin("Mesh NOT NULL");
                    AddMeshTriangles(generatedMesh, offset, rotation, ownRotation);
                    ProfilerShort.End();
                }
                it.MoveNext();
            }
            ProfilerShort.End();
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:97,代码来源:MyNavigationInputMesh.cs

示例3: GetWorldBoundingBox

 /// <summary>
 /// Returns world AABB of the block (geometry AABB). If useAABBFromBlockCubes = true then AABB from block cubes is returned.
 /// </summary>
 public void GetWorldBoundingBox(out BoundingBoxD aabb, bool useAABBFromBlockCubes = false)
 {
     if (FatBlock != null && !useAABBFromBlockCubes)
     {
         aabb = FatBlock.PositionComp.WorldAABB;
     }
     else
     {
         float gridSize = CubeGrid.GridSize;
         aabb = new BoundingBoxD(Min * gridSize - gridSize / 2, Max * gridSize + gridSize / 2);
         aabb = aabb.TransformFast(CubeGrid.WorldMatrix);
     }
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:16,代码来源:MySlimBlock.cs

示例4: PeekWorldBoundaries

 public override BoundingBoxD PeekWorldBoundaries(ref Vector3D targetPosition)
 {
     MatrixD newTransformation = Transformation;
     newTransformation.Translation = targetPosition;
     var bbox = new BoundingBoxD(A - Radius, B + Radius);
     return bbox.TransformFast(newTransformation);
 }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:7,代码来源:MyVoxelGenerator.cs

示例5: GetWorldBoundaries

 public override BoundingBoxD GetWorldBoundaries()
 {
     var bbox = new BoundingBoxD(A - Radius, B + Radius);
     return bbox.TransformFast(Transformation);
 }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:5,代码来源:MyVoxelGenerator.cs

示例6: TestGridPlacement

        private static void TestGridPlacement(ref MyGridPlacementSettings settings, ref MatrixD worldMatrix, ref MyCubeGrid touchingGrid, float gridSize, bool isStatic, ref BoundingBoxD localAABB, MyCubeBlockDefinition blockDefinition,
           MyBlockOrientation? blockOrientation, ref bool entityOverlap, ref bool touchingStaticGrid, MyCubeGrid grid)
        {
            var worldAabb = localAABB.TransformFast(ref worldMatrix);
            var invWorldMatrix = grid.PositionComp.WorldMatrixNormalizedInv;
            var otherLocalAabb = worldAabb.TransformFast(ref invWorldMatrix);

            Vector3D minToWorld = Vector3D.Transform(localAABB.Min, worldMatrix);
            Vector3D maxToWorld = Vector3D.Transform(localAABB.Max, worldMatrix);
            Vector3D tempMinLocal = Vector3D.Transform(minToWorld, invWorldMatrix);
            Vector3D tempMaxLocal = Vector3D.Transform(maxToWorld, invWorldMatrix);

            Vector3D otherMinLocal = Vector3D.Min(tempMinLocal, tempMaxLocal);
            Vector3D otherMaxLocal = Vector3D.Max(tempMinLocal, tempMaxLocal);

            var scaledMin = (otherMinLocal + gridSize / 2) / grid.GridSize;
            var scaledMax = (otherMaxLocal - gridSize / 2) / grid.GridSize;
            var tempMin = Vector3I.Round(scaledMin);
            var tempMax = Vector3I.Round(scaledMax);
            var min = Vector3I.Min(tempMin, tempMax);
            var max = Vector3I.Max(tempMin, tempMax);

            MyBlockOrientation? gridBlockOrientation = null;
            if (MyFakes.ENABLE_COMPOUND_BLOCKS && isStatic && grid.IsStatic && blockOrientation != null)
            {
                Matrix blockRotation;
                blockOrientation.Value.GetMatrix(out blockRotation);
                Matrix rotationInGrid = blockRotation * worldMatrix;
                rotationInGrid = rotationInGrid * invWorldMatrix;
                rotationInGrid.Translation = Vector3.Zero;

                Base6Directions.Direction forwardDir = Base6Directions.GetForward(ref rotationInGrid);
                Base6Directions.Direction upDir = Base6Directions.GetUp(ref rotationInGrid);
                if (Base6Directions.IsValidBlockOrientation(forwardDir, upDir))
                    gridBlockOrientation = new MyBlockOrientation(forwardDir, upDir);
            }

            if (!grid.CanAddCubes(min, max, gridBlockOrientation, blockDefinition))
            {
                entityOverlap = true;
                return;
            }

            if (settings.CanAnchorToStaticGrid && grid.IsTouchingAnyNeighbor(min, max))
            {
                touchingStaticGrid = true;
                if (touchingGrid == null)
                    touchingGrid = grid;
            }
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:50,代码来源:MyCubeGrid.Static.cs

示例7: TestPlacementVoxelMapOverlap

        public static bool TestPlacementVoxelMapOverlap(
            MyVoxelBase voxelMap,
            ref MyGridPlacementSettings settings,
            ref BoundingBoxD localAabb,
            ref MatrixD worldMatrix,
            bool touchingStaticGrid = false)
        {
            ProfilerShort.Begin("TestPlacementVoxelMapOverlap");

            var worldAabb = localAabb.TransformFast(ref worldMatrix);

            const int IntersectsOrInside = 1;
            const int Outside = 2;

            int overlapState = Outside;

            if (voxelMap == null)
                voxelMap = MySession.Static.VoxelMaps.GetVoxelMapWhoseBoundingBoxIntersectsBox(ref worldAabb, null);

            if (voxelMap != null && voxelMap.IsAnyAabbCornerInside(ref worldMatrix, localAabb))
            {
                overlapState = IntersectsOrInside;
            }

            bool testPassed = true;

            switch (overlapState)
            {
                case IntersectsOrInside:
                    testPassed = settings.VoxelPlacement.Value.PlacementMode == VoxelPlacementMode.Both;
                    break;
                case Outside:
                    testPassed = settings.VoxelPlacement.Value.PlacementMode == VoxelPlacementMode.OutsideVoxel || (settings.CanAnchorToStaticGrid && touchingStaticGrid);
                    break;
                default:
                    Debug.Fail("Invalid branch.");
                    break;
            }

            ProfilerShort.End();

            return testPassed;
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:43,代码来源:MyCubeGrid.Static.cs

示例8: TestBlockPlacementArea

        public static bool TestBlockPlacementArea(MyCubeBlockDefinition blockDefinition, MyBlockOrientation? blockOrientation, MatrixD worldMatrix, ref MyGridPlacementSettings settings, BoundingBoxD localAabb, bool dynamicBuildMode,
            MyEntity ignoredEntity = null, bool testVoxel = true)
        {
            ProfilerShort.Begin("TestStart");
            Vector3 halfExtents = localAabb.HalfExtents;
            halfExtents += settings.SearchHalfExtentsDeltaAbsolute; //this works for SE
            if (MyFakes.ENABLE_BLOCK_PLACING_IN_OCCUPIED_AREA)
                halfExtents -= new Vector3D(GRID_PLACING_AREA_FIX_VALUE);
            Vector3D translation = localAabb.TransformFast(ref worldMatrix).Center;
            Quaternion quaternion = Quaternion.CreateFromRotationMatrix(worldMatrix);
            quaternion.Normalize();
            ProfilerShort.End();

            ProfilerShort.Begin("VoxelOverlap");
            // copy settings so we wont override original one.
            MyGridPlacementSettings settingsCopy = settings;

            if (testVoxel && !TestVoxelPlacement(blockDefinition, settingsCopy, dynamicBuildMode, worldMatrix, localAabb))
                return false;

            ProfilerShort.End();

            ProfilerShort.Begin("Havok.GetPenetrationsBox");
            Debug.Assert(m_physicsBoxQueryList.Count == 0, "List not cleared");
            MyPhysics.GetPenetrationsBox(ref halfExtents, ref translation, ref quaternion, m_physicsBoxQueryList, MyPhysics.CollisionLayers.NoVoxelCollisionLayer);
            m_lastQueryBox.HalfExtents = halfExtents;
            m_lastQueryTransform = MatrixD.CreateFromQuaternion(quaternion);
            m_lastQueryTransform.Translation = translation;
            ProfilerShort.End();

            MyCubeGrid touchingGrid;
            return TestPlacementAreaInternal(null, ref settingsCopy, blockDefinition, blockOrientation, ref localAabb, ignoredEntity, ref worldMatrix, out touchingGrid, dynamicBuildMode: dynamicBuildMode);
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:33,代码来源:MyCubeGrid.Static.cs

示例9: TestPlacementAreaInternalWithEntities

        private static bool TestPlacementAreaInternalWithEntities(MyCubeGrid targetGrid,
         bool targetGridIsStatic,
         ref MyGridPlacementSettings settings,
         ref BoundingBoxD localAabb,
         MyEntity ignoredEntity,
         ref MatrixD worldMatrix,
         bool dynamicBuildMode = false)
        {
            ProfilerShort.Begin("TestPlacementAreaInternalWithEntities");

            MyCubeGrid touchingGrid = null;

            float gridSize = targetGrid.GridSize;
            bool isStatic = targetGridIsStatic;

            var worldAabb = localAabb.TransformFast(ref worldMatrix);

            bool entityOverlap = false;
            MyVoxelBase overlappedVoxelMap = null;
            bool touchingStaticGrid = false;
            foreach (var entity in m_tmpResultList)
            {
                if (ignoredEntity != null && (entity == ignoredEntity || entity.GetTopMostParent() == ignoredEntity))
                    continue;

                var body = entity.Physics;
                if (body == null)
                    continue;

                var grid = entity as MyCubeGrid;
                if (grid != null)
                {
                    // Small on large (or large on small) always possible
                    if (isStatic == grid.IsStatic && gridSize != grid.GridSize)
                        continue;

                    TestGridPlacement(ref settings, ref worldMatrix, ref touchingGrid, gridSize, isStatic, ref localAabb, null, null, ref entityOverlap, ref touchingStaticGrid, grid);

                    if (entityOverlap)
                    {
                        break;
                    }
                }
                else
                {
                    var character = entity as MyCharacter;
                    if (character != null && character.PositionComp.WorldAABB.Intersects(targetGrid.PositionComp.WorldAABB))
                    {
                        entityOverlap = true;
                        break;
                    }
                }
            }

            m_tmpResultList.Clear();
            ProfilerShort.End();

            if (entityOverlap)
                return false;

            if (targetGrid.IsStatic)
            {
                return true;
            }

            return true;
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:67,代码来源:MyCubeGrid.Static.cs

示例10: IsAabbInsideVoxel

        /// <summary>
        /// Checks if aabb is in voxel. If settings provided it will return false if penetration settings allow for it.
        /// </summary>
        /// <param name="worldMatrix">World matrix of the aabb.</param>
        /// <param name="localAabb">Local aabb</param>
        /// <param name="settings">Game settings</param>
        /// <returns></returns>
        public static bool IsAabbInsideVoxel(MatrixD worldMatrix, BoundingBoxD localAabb, MyGridPlacementSettings settings)
        {

            var worldAabb = localAabb.TransformFast(ref worldMatrix);

            List<MyVoxelBase> voxels = new List<MyVoxelBase>();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref worldAabb, voxels);

            foreach (MyVoxelBase voxel in voxels)
            {
                if (settings.VoxelPlacement.Value.PlacementMode != VoxelPlacementMode.Volumetric && voxel.IsAnyAabbCornerInside(ref worldMatrix, localAabb))
                    return true;

                if (settings.VoxelPlacement.Value.PlacementMode == VoxelPlacementMode.Volumetric && !TestPlacementVoxelMapPenetration(voxel, settings, ref localAabb, ref worldMatrix))
                    return true;
            }

            return false;
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:26,代码来源:MyCubeGrid.Static.cs

示例11: TestPlacementArea

        //public static bool TestPlacementAreaWithEntities(MyCubeGrid targetGrid, bool targetGridIsStatic, ref MyGridPlacementSettings settings, BoundingBoxD localAabb, bool dynamicBuildMode, MyEntity ignoredEntity = null)
        //{
        //    ProfilerShort.Begin("Test start with entities");
        //    var worldMatrix = targetGrid.WorldMatrix;

        //    Vector3 halfExtents = localAabb.HalfExtents;
        //    halfExtents += settings.SearchHalfExtentsDeltaAbsolute; //this works for SE
        //    if (MyFakes.ENABLE_BLOCK_PLACING_IN_OCCUPIED_AREA)
        //        halfExtents -= new Vector3D(GRID_PLACING_AREA_FIX_VALUE);
        //    Vector3D translation = localAabb.Transform(ref worldMatrix).Center;
        //    Quaternion quaternion = Quaternion.CreateFromRotationMatrix(worldMatrix);
        //    quaternion.Normalize();
        //    ProfilerShort.End();

        //    ProfilerShort.Begin("get top most entities");

        //    m_tmpResultList.Clear();
        //    BoundingBoxD box = targetGrid.PositionComp.WorldAABB;
        //    MyGamePruningStructure.GetTopMostEntitiesInBox(ref box, m_tmpResultList);
        //    ProfilerShort.End();

        //    return TestPlacementAreaInternalWithEntities(targetGrid, targetGridIsStatic, ref settings, ref localAabb, ignoredEntity, ref worldMatrix, dynamicBuildMode: dynamicBuildMode);
        //}

        public static bool TestPlacementArea(MyCubeGrid targetGrid, bool targetGridIsStatic, ref MyGridPlacementSettings settings, BoundingBoxD localAabb, bool dynamicBuildMode, MyEntity ignoredEntity = null, bool testVoxel = true)
        {
            ProfilerShort.Begin("TestStart");
            var worldMatrix = targetGrid.WorldMatrix;

            Vector3 halfExtents = localAabb.HalfExtents;
            halfExtents += settings.SearchHalfExtentsDeltaAbsolute; //this works for SE
            if (MyFakes.ENABLE_BLOCK_PLACING_IN_OCCUPIED_AREA)
                halfExtents -= new Vector3D(GRID_PLACING_AREA_FIX_VALUE);
            Vector3D translation = localAabb.TransformFast(ref worldMatrix).Center;
            Quaternion quaternion = Quaternion.CreateFromRotationMatrix(worldMatrix);
            quaternion.Normalize();
            ProfilerShort.End();

            ProfilerShort.Begin("VoxelOverlap");

            if (testVoxel && settings.VoxelPlacement.Value.PlacementMode != VoxelPlacementMode.Both)
            {
                bool result = IsAabbInsideVoxel(worldMatrix, localAabb, settings);

                if (settings.VoxelPlacement.Value.PlacementMode == VoxelPlacementMode.InVoxel)
                    result = !result;

                if (result)
                {
                    ProfilerShort.End();
                    return false;
                }
            }

            ProfilerShort.End();

            ProfilerShort.Begin("Havok.GetPenetrationsBox");

            Debug.Assert(m_physicsBoxQueryList.Count == 0, "List not cleared");
            MyPhysics.GetPenetrationsBox(ref halfExtents, ref translation, ref quaternion, m_physicsBoxQueryList, MyPhysics.CollisionLayers.NoVoxelCollisionLayer);
            m_lastQueryBox.HalfExtents = halfExtents;
            m_lastQueryTransform = MatrixD.CreateFromQuaternion(quaternion);
            m_lastQueryTransform.Translation = translation;
            ProfilerShort.End();

            MyCubeGrid touchingGrid;
            return TestPlacementAreaInternal(targetGrid, targetGridIsStatic, ref settings, null, null, ref localAabb, ignoredEntity, ref worldMatrix, out touchingGrid, dynamicBuildMode);
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:68,代码来源:MyCubeGrid.Static.cs

示例12: GetVoxelContentInBoundingBox_Fast

        /// <summary>
        /// Calculates amount of volume of a bounding box in voxels.
        /// </summary>
        /// <param name="localAabb">Local bounding box to query for.</param>
        /// <param name="worldMatrix">World matrix of the bounding box.</param>
        /// <returns>Pair of floats where 1st value is Volume amount and 2nd value is ratio of Volume amount to Whole volume.</returns>
        public MyTuple<float,float> GetVoxelContentInBoundingBox_Fast(BoundingBoxD localAabb, MatrixD worldMatrix)
        {
            MatrixD toVoxel = worldMatrix * PositionComp.WorldMatrixNormalizedInv;
            MatrixD toGrid; MatrixD.Invert(ref toVoxel, out toGrid);

            BoundingBoxD transAABB = localAabb.TransformFast(toVoxel);
            transAABB.Translate(SizeInMetresHalf + StorageMin);
            Vector3I minI = Vector3I.Floor(transAABB.Min);
            Vector3I maxI = Vector3I.Ceiling(transAABB.Max);

            double vol = localAabb.Volume / MyVoxelConstants.VOXEL_VOLUME_IN_METERS;
            int K = Math.Max((MathHelper.Log2Ceiling((int)vol) - MathHelper.Log2Ceiling(100)) / 3, 0);
            float voxelSizeAtLod = MyVoxelConstants.VOXEL_SIZE_IN_METRES * (1 << K);
            float voxelVolumeAtLod = voxelSizeAtLod * voxelSizeAtLod * voxelSizeAtLod;
            minI >>= K;
            maxI >>= K;

           // localAabb.Inflate(1 * voxelSizeAtLod);

            var offset = ((Size >> 1) + StorageMin) >> K;

            m_tempStorage.Resize(maxI - minI + 1);
            Storage.ReadRange(m_tempStorage, MyStorageDataTypeFlags.Content, K, minI, maxI);

            float resultVolume = 0;
            float resultPercent = 0;
            int hitVolumeBoxes = 0;

            MyOrientedBoundingBoxD worldbbox = new MyOrientedBoundingBoxD(localAabb, worldMatrix);

            Vector3I coord, cache;
            for (coord.Z = minI.Z, cache.Z = 0; coord.Z <= maxI.Z; coord.Z++, cache.Z++)
            {
                for (coord.Y = minI.Y, cache.Y = 0; coord.Y <= maxI.Y; coord.Y++, cache.Y++)
                {
                    for (coord.X = minI.X, cache.X = 0; coord.X <= maxI.X; coord.X++, cache.X++)
                    {
                        Vector3D voxelPos = (coord - offset) * voxelSizeAtLod;

                        Vector3D gridPoint;
                        Vector3D.Transform(ref voxelPos, ref toGrid, out gridPoint);

                        ContainmentType cont;
                        //localAabb.Contains(ref gridPoint, out cont);

                        var voxelToWorld = WorldMatrix;
                        voxelToWorld.Translation -= (Vector3D)StorageMin + SizeInMetresHalf;

                        BoundingBoxD voxelBox = new BoundingBoxD();
                        voxelBox.Min = ((Vector3D)(coord) - .5) * voxelSizeAtLod;
                        voxelBox.Max = ((Vector3D)(coord) + .5) * voxelSizeAtLod;

                        MyOrientedBoundingBoxD voxelBbox = new MyOrientedBoundingBoxD(voxelBox, voxelToWorld);

                        cont = worldbbox.Contains(ref voxelBbox);

                        if (cont == ContainmentType.Disjoint)
                        {
                            //VRageRender.MyRenderProxy.DebugDrawOBB(
                            //new MyOrientedBoundingBoxD(voxelBox, voxelToWorld), Color.Red, 0.1f,
                            //true, false);
                            continue;
                        }

                        float content = m_tempStorage.Content(ref cache) / MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT;



                        //VRageRender.MyRenderProxy.DebugDrawOBB(voxelBbox, Color.Aqua, content,
                        //   true, false);

                        resultVolume += content * voxelVolumeAtLod;
                        resultPercent += content;
                        hitVolumeBoxes++;
                    }
                }
            }

            resultPercent /= hitVolumeBoxes; 
            //float localAABBVol = (float)localAabb.Volume;
            //if (localAABBVol < resultVolume)
            //    resultPercent *= (float)localAabb.Volume / resultVolume;


            //VRageRender.MyRenderProxy.DebugDrawOBB(worldbbox, Color.Yellow, 0,
            //                true, false);
            //VRageRender.MyRenderProxy.DebugWaitForFrameFinish();


            return new MyTuple<float, float>(resultVolume, resultPercent);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:97,代码来源:MyVoxelBase.cs

示例13: UpdateGizmo_VoxelMap


//.........这里部分代码省略.........
                            gizmoSpace.m_cubeMatricesTemp, 
                            gizmoSpace.m_cubeNormals, 
                            gizmoSpace.m_patternOffsets
                            );

                        if (gizmoSpace.m_showGizmoCube)
                        {
                            for (int i = 0; i < gizmoSpace.m_cubeMatricesTemp.Count; i++)
                            {
                                MatrixD modelMatrix = gizmoSpace.m_cubeMatricesTemp[i] * gizmoSpace.m_worldMatrixAdd;
                                modelMatrix.Translation = tempWorldPos;
                                gizmoSpace.m_cubeMatricesTemp[i] = modelMatrix;
                            }
                            drawMatrix.Translation = tempWorldPos;
                            MatrixD invDrawMatrix = MatrixD.Invert(localOrientation * drawMatrix);
                            
                            m_gizmo.AddFastBuildParts(gizmoSpace, CurrentBlockDefinition, null);
                            m_gizmo.UpdateGizmoCubeParts(gizmoSpace, m_renderData, ref invDrawMatrix, CurrentBlockDefinition);
                        }
                    }

            //calculate world center for block model
            worldCenter /= CurrentBlockDefinition.Size.Size;
            if (!m_animationLock)
            {
                gizmoSpace.m_animationProgress = 0;
                gizmoSpace.m_animationLastPosition = worldCenter;
            }
            else if (MySandboxGame.Config.AnimatedRotation && gizmoSpace.m_animationProgress < 1)
            {
                worldCenter = Vector3D.Lerp(gizmoSpace.m_animationLastPosition, worldCenter, gizmoSpace.m_animationProgress);
            }
            worldCenter = Vector3D.Transform(worldCenter, gizmoSpace.m_worldMatrixAdd);
            drawMatrix.Translation = worldCenter;
            drawMatrix = localOrientation * drawMatrix;

            BoundingBoxD localAABB = new BoundingBoxD(-CurrentBlockDefinition.Size * gridSize * 0.5f, CurrentBlockDefinition.Size * gridSize * 0.5f);

            var settings = CurrentBlockDefinition.CubeSize == MyCubeSize.Large ? CubeBuilderDefinition.BuildingSettings.LargeStaticGrid : CubeBuilderDefinition.BuildingSettings.SmallStaticGrid;
            MyBlockOrientation blockOrientation = new MyBlockOrientation(ref Quaternion.Identity);
            bool placementTest = CheckValidBlockRotation(gizmoSpace.m_localMatrixAdd, CurrentBlockDefinition.Direction, CurrentBlockDefinition.Rotation)
                && MyCubeGrid.TestBlockPlacementArea(CurrentBlockDefinition, blockOrientation, drawMatrix, ref settings, localAABB, false);
            gizmoSpace.m_buildAllowed &= placementTest;
            gizmoSpace.m_buildAllowed &= gizmoSpace.m_showGizmoCube;
            gizmoSpace.m_worldMatrixAdd = drawMatrix;

            BuildComponent.GetGridSpawnMaterials(CurrentBlockDefinition, drawMatrix, true);
            if (MySession.Static.IsAdminModeEnabled(Sync.MyId) == false)
            {
                gizmoSpace.m_buildAllowed &= BuildComponent.HasBuildingMaterials(MySession.Static.LocalCharacter);
            }

            if (MySession.Static.SurvivalMode && !SpectatorIsBuilding && MySession.Static.IsAdminModeEnabled(Sync.MyId) == false)
            {
                BoundingBoxD gizmoBox = localAABB.TransformFast(ref drawMatrix);

                if (!MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref MatrixD.Identity, gizmoBox, gridSize, IntersectionDistance) || CameraControllerSpectator)
                {
                    gizmoSpace.m_buildAllowed = false;
                    gizmoSpace.m_showGizmoCube = false;
                    gizmoSpace.m_removeBlock = null;
                    return;
                }
            }


            color = Color.White;
            string lineMaterial = gizmoSpace.m_buildAllowed ? "GizmoDrawLine" : "GizmoDrawLineRed";

            if (gizmoSpace.SymmetryPlane == MySymmetrySettingModeEnum.Disabled)
            {
                MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix,
                    ref localAABB, ref color, MySimpleObjectRasterizer.Wireframe, 1, 0.04f, lineMaterial: lineMaterial);

                m_rotationHints.CalculateRotationHints(drawMatrix, localAABB, !MyHud.MinimalHud && MySandboxGame.Config.RotationHints && draw && MyFakes.ENABLE_ROTATION_HINTS);
            }

            gizmoSpace.m_cubeMatricesTemp.Clear();
            gizmoSpace.m_cubeModelsTemp.Clear();

            if (gizmoSpace.m_showGizmoCube)
            {
                // Draw mount points of added cube block as yellow squares in neighboring cells.
                if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_MOUNT_POINTS)
                {
                    DrawMountPoints(gridSize, CurrentBlockDefinition, ref drawMatrix);
                }

                AddFastBuildModels(gizmoSpace, MatrixD.Identity, gizmoSpace.m_cubeMatricesTemp, gizmoSpace.m_cubeModelsTemp, gizmoSpace.m_blockDefinition);

                Debug.Assert(gizmoSpace.m_cubeMatricesTemp.Count == gizmoSpace.m_cubeModelsTemp.Count);
                for (int i = 0; i < gizmoSpace.m_cubeMatricesTemp.Count; ++i)
                {
                    string model = gizmoSpace.m_cubeModelsTemp[i];
                    if (!string.IsNullOrEmpty(model))
                        m_renderData.AddInstance(MyModel.GetId(model), gizmoSpace.m_cubeMatricesTemp[i], ref MatrixD.Identity);
                }
            }
            gizmoSpace.m_animationProgress += m_animationSpeed;
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:101,代码来源:MyCubeBuilder.cs

示例14: QueryEmptyOrFull

        private bool QueryEmptyOrFull(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
        {
            ////return false;
            var bb = new BoundingBox(new Vector3(minX, minY, minZ), new Vector3(maxX, maxY, maxZ));
            if (bb.Volume() < 100)
                return false;

            //bb.Translate(m_voxelMap.StorageMin);
            var result = m_voxelMap.Storage.Intersect(ref bb, false) != ContainmentType.Intersects;
            {
                var bbd = new BoundingBoxD(new Vector3(minX, minY, minZ) * 8, new Vector3(maxX, maxY, maxZ) * 8);
                bbd.TransformFast(Entity.WorldMatrix);
                var obb = new MyOrientedBoundingBoxD(bbd, Entity.WorldMatrix);
                MyRenderProxy.DebugDrawAABB(bbd, result ? Color.Green : Color.Red, 1, 1, false);
            }
            return result;
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:17,代码来源:MyVoxelPhysicsBody.cs


注:本文中的BoundingBoxD.TransformFast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。