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


C# BoundingBox.Translate方法代码示例

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


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

示例1: IntersectStorage

 public ContainmentType IntersectStorage(ref BoundingBox bb, bool lazy)
 {
     if (Entity != null)
     {
         var voxel = (MyVoxelBase) Entity;
         bb.Translate(voxel.StorageMin);
         if (voxel.Storage != null)
             return voxel.Storage.Intersect(ref bb, lazy);
     }
     return ContainmentType.Disjoint;
 }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:11,代码来源:MyRenderComponentPlanet.cs

示例2: Add

            public void Add(MatrixD worldMatrix, BoundingBox box, Vector4I id, MyVoxelBase voxel)
            {
                if (m_list.Count > 1900)
                    m_list.ClearList();

                voxel = voxel.RootVoxel;
                box.Translate(-voxel.SizeInMetresHalf);
                //box.Translate(voxel.StorageMin);


                m_list.Add(new PredictionInfo
                {
                    Id = id,
                    Bounds = MyOrientedBoundingBoxD.Create((BoundingBoxD)box, voxel.WorldMatrix),
                    Body = voxel
                });
            }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:17,代码来源:MyVoxelDebugInputComponent.Physics.cs

示例3: UpdateAfterSimulation10

        internal void UpdateAfterSimulation10()
        {
            ProfilerShort.Begin("Voxel Physics Prediction");
            UpdateRigidBodyShape();

            // Apply prediction based on movement of nearby entities.
            foreach (var entity in m_nearbyEntities)
            {
                Debug.Assert(m_bodiesInitialized, "Voxel map does not have physics!");

                bool lod0 = entity is MyCharacter;

                if (!lod0)
                {
                    var body = entity.Physics as MyPhysicsBody;

                    if (body != null && body.RigidBody != null &&
                        (body.RigidBody.Layer == MyPhysics.CollisionLayers.FloatingObjectCollisionLayer || body.RigidBody.Layer == MyPhysics.CollisionLayers.LightFloatingObjectCollisionLayer))
                        lod0 = true;
                }

                if (!(entity is MyCubeGrid) && !lod0)
                    continue;

                if (entity.MarkedForClose)
                    continue;

                if (entity.Physics.LinearVelocity.Length() < 2f)
                    continue;

                BoundingBoxD aabb;
                GetPrediction(entity, out aabb);
                if (!aabb.Intersects(m_voxelMap.PositionComp.WorldAABB))
                    continue;

                int lod = lod0 ? 0 : 1;
                float lodSize = 1 << lod;

                Vector3I min, max;
                Vector3D localPositionMin, localPositionMax;

                aabb = aabb.Transform(m_voxelMap.PositionComp.WorldMatrixInvScaled);

                aabb.Translate(m_voxelMap.SizeInMetresHalf);

                localPositionMax = aabb.Max;
                localPositionMin = aabb.Min;



                MyVoxelCoordSystems.LocalPositionToVoxelCoord(ref localPositionMin, out min);
                MyVoxelCoordSystems.LocalPositionToVoxelCoord(ref localPositionMax, out max);
                m_voxelMap.Storage.ClampVoxelCoord(ref min);
                m_voxelMap.Storage.ClampVoxelCoord(ref max);
                MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref min, out min);
                MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref max, out max);
                min >>= lod;
                max >>= lod;

                {
                    var size = (max - min + 1).Size;
                    if (size >= m_cellsToGenerateBuffer.Length)
                    {
                        m_cellsToGenerateBuffer = new Vector3I[MathHelper.GetNearestBiggerPowerOfTwo(size)];
                    }
                }
                var shape = GetShape(lod);

                Debug.Assert(shape.Base.IsValid);
                int requiredCellsCount = shape.GetMissingCellsInRange(ref min, ref max, m_cellsToGenerateBuffer);

                if (requiredCellsCount == 0)
                {
                    continue;
                }

                var bb = new BoundingBox(min * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_METRES * lodSize, (max + 1) * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_METRES * lodSize);
                bb.Translate(m_voxelMap.StorageMin);
                ProfilerShort.Begin("Storage Intersect");
                if (requiredCellsCount > 0 && m_voxelMap.Storage.Intersect(ref bb, false) != ContainmentType.Intersects)
                {
                    ProfilerShort.BeginNextBlock("Set Empty Shapes");
                    for (int i = 0; i < requiredCellsCount; ++i)
                    {
                        var cell = m_cellsToGenerateBuffer[i];
                        m_workTracker.Cancel(new MyCellCoord(lod, cell));
                        shape.SetChild(cell.X, cell.Y, cell.Z, (HkBvCompressedMeshShape)HkShape.Empty, HkReferencePolicy.TakeOwnership);
                    }
                    ProfilerShort.End();
                    continue;
                }

                ProfilerShort.BeginNextBlock("Start Jobs");
                for (int i = 0; i < requiredCellsCount; ++i)
                {
                    if (m_workTracker.Exists(new MyCellCoord(lod, m_cellsToGenerateBuffer[i])))
                        continue;

                    MyPrecalcJobPhysicsPrefetch.Start(new MyPrecalcJobPhysicsPrefetch.Args
                    {
//.........这里部分代码省略.........
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:101,代码来源:MyVoxelPhysicsBody.cs

示例4: FixSnapTransformationBase6

        protected void FixSnapTransformationBase6()
        {
            Debug.Assert(m_copiedGrids.Count != 0);
            if (m_copiedGrids.Count == 0)
                return;

            var pasteMatrix = GetPasteMatrix();
            var hitGrid = m_hitEntity as MyCubeGrid;

            if (hitGrid == null)
                return;
            
            // Fix rotation of the first pasted grid
            Matrix hitGridRotation = hitGrid.WorldMatrix.GetOrientation();
            Matrix firstRotation = m_previewGrids[0].WorldMatrix.GetOrientation();
            // PARODY
            hitGridRotation = Matrix.Normalize(hitGridRotation);
            // PARODY
            firstRotation = Matrix.Normalize(firstRotation);
            Matrix newFirstRotation = Matrix.AlignRotationToAxes(ref firstRotation, ref hitGridRotation);
            Matrix rotationDelta = Matrix.Invert(firstRotation) * newFirstRotation;

            // Fix transformations of all the pasted grids
            int gridIndex = 0;
            foreach (var grid in m_previewGrids)
            {
                Matrix rotation = grid.WorldMatrix.GetOrientation();
                rotation = rotation * rotationDelta;
                Matrix rotationInv = Matrix.Invert(rotation);

                Vector3D position = m_pastePosition;

                MatrixD newWorld = MatrixD.CreateWorld(position, rotation.Forward, rotation.Up);
                Debug.Assert(newWorld.GetOrientation().IsRotation());
                grid.PositionComp.SetWorldMatrix(newWorld);
            }


            bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && m_previewGrids[0].GridSizeEnum == MyCubeSize.Small;

            if (smallOnLargeGrid)
            {
                Vector3 pasteOffset = MyCubeBuilder.TransformLargeGridHitCoordToSmallGrid(m_pastePosition, hitGrid.PositionComp.WorldMatrixNormalizedInv, hitGrid.GridSize);
                m_pastePosition = hitGrid.GridIntegerToWorld(pasteOffset);
                if (MyFakes.ENABLE_VR_BUILDING) // Move pasted grid to aabb edge
                {
                    Vector3 normal = Vector3I.Round(Vector3.TransformNormal(m_hitNormal, hitGrid.PositionComp.WorldMatrixNormalizedInv));
                    Vector3 normalStepLocalInHitGrid = normal * (m_previewGrids[0].GridSize / hitGrid.GridSize);
                    Vector3 normalStepLocalInPreviewGrid = Vector3I.Round(Vector3D.TransformNormal(Vector3D.TransformNormal(normal, hitGrid.WorldMatrix),
                        m_previewGrids[0].PositionComp.WorldMatrixNormalizedInv)); 
                    var localAABB = m_previewGrids[0].PositionComp.LocalAABB;
                    localAABB.Min /= m_previewGrids[0].GridSize;
                    localAABB.Max /= m_previewGrids[0].GridSize;
                    Vector3 offsetOrigin = m_dragPointToPositionLocal / m_previewGrids[0].GridSize;
                    Vector3 offsetLocalInPreviewGrid = Vector3.Zero;
                    Vector3 offsetLocalInHitGrid = Vector3.Zero;
                    BoundingBox cubeBox = new BoundingBox(-Vector3.Half, Vector3.Half);
                    cubeBox.Inflate(-0.05f);
                    cubeBox.Translate(-offsetOrigin + offsetLocalInPreviewGrid - normalStepLocalInPreviewGrid);
                    while (localAABB.Contains(cubeBox) != ContainmentType.Disjoint)
                    {
                        offsetLocalInPreviewGrid -= normalStepLocalInPreviewGrid;
                        offsetLocalInHitGrid -= normalStepLocalInHitGrid;
                        cubeBox.Translate(-normalStepLocalInPreviewGrid);
                    }

                    m_pastePosition = hitGrid.GridIntegerToWorld(pasteOffset - offsetLocalInHitGrid);
                }
            }
            else
            {
                // Find a collision-free position for the first paste grid along the raycast normal
                Vector3I collisionTestStep = Vector3I.Round(Vector3.TransformNormal(m_hitNormal, hitGrid.PositionComp.WorldMatrixNormalizedInv));
                Vector3I pasteOffset = hitGrid.WorldToGridInteger(m_pastePosition);

                int i;
                for (i = 0; i < 100; ++i) // CH:TODO: Fix the step limit
                {
                    if (hitGrid.CanMergeCubes(m_previewGrids[0], pasteOffset))
                        break;
                    pasteOffset += collisionTestStep;
                }

                if (i == 0)
                {
                    for (i = 0; i < 100; ++i) // CH:TODO: Fix the step limit
                    {
                        pasteOffset -= collisionTestStep;
                        if (!hitGrid.CanMergeCubes(m_previewGrids[0], pasteOffset))
                            break;
                    }
                    pasteOffset += collisionTestStep;
                }

                if (i == 100)
                {
                    pasteOffset = hitGrid.WorldToGridInteger(m_pastePosition);
                }

                m_pastePosition = hitGrid.GridIntegerToWorld(pasteOffset);
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridClipboard.cs

示例5: UpdateAfterSimulation10

        public override void UpdateAfterSimulation10()
        {
            base.UpdateAfterSimulation10();

			if (!Sync.IsServer || !IsWorking || !ResourceSink.IsPowered)
                return;

            var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up);
            var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax.Value + m_fieldMin.Value) * 0.5f, rotation1);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field");
            if (m_recreateField)
            {
                m_recreateField = false;
                m_fieldShape.RemoveReference();
                m_fieldShape = GetHkShape();
				ResourceSink.Update();
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            var boundingBox = new BoundingBoxD(m_fieldMin.Value, m_fieldMax.Value).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition());
             
            m_potentialPenetrations.Clear();
            MyGamePruningStructure.GetTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations);

            m_potentialVoxelPenetrations.Clear();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);//disabled until heightmap queries are finished

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics");
            LastDetectedEntity = null;
            bool empty = true;
            foreach (var entity in m_potentialPenetrations)
            {
                if (entity is MyVoxelBase)
                {
                    //voxels are handled in different loop (becaose of planets)
                    continue;
                }
                if (ShouldDetect(entity))
                {
                    Quaternion rotation2;
                    Vector3 posDiff;
                    HkShape? shape2;
                    if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                    {
                        if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                        {
                            LastDetectedEntity = entity;
                            empty = false;
                            break;
                        }
                    }
                }
            }

            if (DetectAsteroids)
            {
                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    var voxel = entity as MyVoxelPhysics;
                    if (voxel != null)
                    {
                        Vector3D localPositionMin, localPositionMax;

                        VRage.Voxels.MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Min, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMin);
                        VRage.Voxels.MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Max, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMax);
                        var aabb = new BoundingBox(localPositionMin, localPositionMax);
                        aabb.Translate(voxel.StorageMin);
                        if (voxel.Storage.Intersect(ref aabb) != ContainmentType.Disjoint)
                        {
                            LastDetectedEntity = voxel;
                            empty = false;
                            break;
                        }
                    }
                    else
                    {
                        Quaternion rotation2;
                        Vector3 posDiff;
                        HkShape? shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }
            }
            IsActive = !empty;
            m_potentialPenetrations.Clear();
            m_potentialVoxelPenetrations.Clear();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:97,代码来源:MySensorBlock.cs

示例6: RenderShape

        public override void RenderShape(VisionViewBase view, ShapeRenderMode mode)
        {
            base.RenderShape(view, mode);

            // Don't draw carvers if "playing the game" or 'Visible' property is false
            if (EditorManager.InPlayingMode || FinalVisibleState == false)
                return;

            Vector3F size = new Vector3F(_vBoxSize.X * ScaleX, _vBoxSize.Y * ScaleY, _vBoxSize.Z * ScaleZ);
            BoundingBox bbox = new BoundingBox(-size * 0.5f, size * 0.5f);

            if (_bInverted)
            {
                bbox.Translate(Position);
                uint color = (mode == ShapeRenderMode.Selected) ? (uint)0x6000ff80 : (uint)0x3000ff80;
                view.RenderSolidBox(bbox, color);
            }
            else
            {
                uint color = (mode == ShapeRenderMode.Selected) ? (uint)0x600080ff : (uint)0x300080ff;
                view.RenderOrientedSolidBox(bbox, Position, RotationMatrix, color);
            }
        }
开发者ID:bgarrels,项目名称:projectanarchy,代码行数:23,代码来源:HavokNavMeshCarverShape.cs

示例7: FindConnectionsToWorld

        private void FindConnectionsToWorld(HashSet<MySlimBlock> blocks)
        {
            if (m_grid.Physics != null && m_grid.Physics.LinearVelocity.LengthSquared() > 0) //jn: TODO nicer
                return;
            int counter = 0;
            ProfilerShort.Begin("FindConnectionsToWorld");
            var q = Quaternion.Identity;
            foreach (var b in blocks)
            {
                var geometryBox = b.FatBlock.GetGeometryLocalBox();
                Vector3 halfExtents = geometryBox.Size / 2;

                Vector3D pos;
                b.ComputeScaledCenter(out pos);
                pos += geometryBox.Center;
                pos = Vector3D.Transform(pos, m_grid.WorldMatrix);

                Matrix blockMatrix;
                b.Orientation.GetMatrix(out blockMatrix);
                q = Quaternion.CreateFromRotationMatrix(blockMatrix * m_grid.WorldMatrix.GetOrientation());

                Sandbox.Engine.Physics.MyPhysics.GetPenetrationsBox(ref halfExtents, ref pos, ref q, m_penetrations, Sandbox.Engine.Physics.MyPhysics.CollideWithStaticLayer);
                counter++;
                bool isStatic = false;
                foreach (var p in m_penetrations)
                {
                    if (p == null)
                        continue;
                    var e = p.UserObject as Sandbox.Engine.Physics.MyPhysicsBody;
                    if (e != null && e.Entity != null && e.Entity is MyVoxelMap)
                    {
                        isStatic = true;
                        break;
                    }
                }

                m_penetrations.Clear();
                if (isStatic && !BlocksConnectedToWorld.Contains(b.Position))
                {
                    isStatic = false;
                    m_blocksShapes[b.Position].GetChildren(m_shapeInfosList2);
                    for (int i = 0; i < m_shapeInfosList2.Count; i++)
                    {
                        var child = m_shapeInfosList2[i];
                        if (child.Shape.GetChildrenCount() > 0)
                        {
                            child.Shape.GetChildren(m_shapeInfosList2);
                            continue;
                        }
                        Vector4 min;
                        Vector4 max;
                        child.Shape.GetShape().GetLocalAABB(0.01f, out min, out max);//.Transform(CubeGrid.PositionComp.WorldMatrix);
                        BoundingBox bb = new BoundingBox(new Vector3(min), new Vector3(max));
                        bb = bb.Translate(b.Position * m_grid.GridSize);
                        var bbd = bb.Transform(m_grid.WorldMatrix);
                        halfExtents = bbd.HalfExtents;
                        pos = bbd.Center;
                        Sandbox.Engine.Physics.MyPhysics.GetPenetrationsBox(ref halfExtents, ref pos, ref q, m_penetrations, Sandbox.Engine.Physics.MyPhysics.CollideWithStaticLayer);
                        counter++;
                        foreach (var p in m_penetrations)
                        {
                            if (p == null)
                                continue;
                            var e = p.UserObject as Sandbox.Engine.Physics.MyPhysicsBody;
                            if (e != null && e.Entity != null && e.Entity is MyVoxelMap)
                            {
                                isStatic = true;
                                child.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
                                break;
                            }
                        }
                        m_penetrations.Clear();
                    }
                    m_shapeInfosList2.Clear();
                    if (isStatic)
                        BlocksConnectedToWorld.Add(b.Position);
                }
            }
            ProfilerShort.End(counter);
        }
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:80,代码来源:MyGridShape.cs

示例8: PrepareRulesForBoxInternal

        private void PrepareRulesForBoxInternal(ref BoundingBox request)
        {
            if (m_rangeBiomes == null) m_rangeBiomes = new List<PlanetMaterialRule>[256];

            BoundingBox box;
            request.Translate(-m_planetShape.Center());

            // Inflate so we don't miss any rules.
            request.Inflate(request.Extents.Length() * .1f);

            GetRuleBounds(ref request, out box);

            foreach (var bio in m_biomes.Values)
            {
                if (ReferenceEquals(m_rangeBiomes[bio.Value], bio.Rules) || m_rangeBiomes[bio.Value] == null || m_providerForRules != this)
                    m_rangeBiomes[bio.Value] = new List<PlanetMaterialRule>();

                bio.MateriaTree.OverlapAllBoundingBox(ref box, m_rangeBiomes[bio.Value], clear: true);
            }
            m_rangeClean = false;
            m_providerForRules = this;
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:22,代码来源:MyPlanetMaterialProvider.cs

示例9: IntersectStorage

        /**
         * Intersect the storage
         * 
         * @param box WorldSpace bounding box to intersect with the storage.
         */
        public ContainmentType IntersectStorage(ref BoundingBox box, bool lazy = true)
        {
            box.Transform(PositionComp.WorldMatrixInvScaled);

            box.Translate(SizeInMetresHalf + StorageMin);

            return Storage.Intersect(ref box, lazy);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:13,代码来源:MyVoxelBase.cs

示例10: Intersect

 public ContainmentType Intersect(BoundingBoxI box, bool lazy)
 {
     if (Closed)
     {
         Debug.Fail("Storage closed!");
         return ContainmentType.Disjoint;
     }
     BoundingBox bbox = new BoundingBox(box);
     bbox.Translate(-Shape.Center()); // Bring to center local
     return Shape.IntersectBoundingBox(ref bbox, 1.0f);
 }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:11,代码来源:MyPlanetStorageProvider.cs

示例11: PrepareRulesForBoxInternal

        private void PrepareRulesForBoxInternal(ref BoundingBox request)
        {
            if (m_rangeBiomes == null) m_rangeBiomes = new List<PlanetMaterialRule>[256];

            BoundingBox box;
            request.Translate(-m_planetShape.Center());

            // Inflate so we don't miss any rules.
            request.Inflate(request.Extents.Length() * .1f);

            GetRuleBounds(ref request, out box);

            foreach (var bio in m_biomes.Values)
            {
                if (Object.ReferenceEquals(m_rangeBiomes[bio.Value], bio.Rules) || m_rangeBiomes[bio.Value] == null || m_providerForRules != this)
                    m_rangeBiomes[bio.Value] = new List<PlanetMaterialRule>();

                m_rangeBiomes[bio.Value].Clear();

                bio.MateriaTree.Query(delegate(int x)
                {
                    m_rangeBiomes[bio.Value].Add(bio.MateriaTree.GetUserData<PlanetMaterialRule>(x)); return true;
                }, ref box);
            }
            m_rangeClean = false;
            m_providerForRules = this;
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:27,代码来源:MyPlanetMaterialProvider.cs


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