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


C# BoundingBoxD.Contains方法代码示例

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


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

示例1: PointInsideGizmo

        public bool PointInsideGizmo(Vector3D point, MyGizmoSpaceEnum gizmo, ref MatrixD invGridWorldMatrix, float gridSize, float inflate = 0.0f, bool onVoxel = false)
        {
            MatrixD m = new MatrixD();
            BoundingBoxD gizmoBox = new BoundingBoxD();
            GetGizmoPointTestVariables(ref invGridWorldMatrix, gridSize, out gizmoBox, out m, gizmo, inflate: inflate, onVoxel: onVoxel);

            Vector3D localPoint = Vector3D.Transform(point, m);

            return gizmoBox.Contains(localPoint) == ContainmentType.Contains;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:10,代码来源:MyCubeBuilderGizmo.cs

示例2: IsInCell

 private static bool IsInCell(ref BoundingBoxD cellbox, ref BoundingSphereD asteroid)
 {
     return cellbox.Contains(asteroid) != ContainmentType.Disjoint;
 }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:4,代码来源:MyAsteroidCellGenerator.cs

示例3: PointsInsideGizmo

        public bool PointsInsideGizmo(List<Vector3> points, MyGizmoSpaceEnum gizmo, ref MatrixD invGridWorldMatrix, float gridSize, float inflate = 0.0f, bool onVoxel = false)
        {
            MatrixD m = new MatrixD();
            BoundingBoxD gizmoBox = new BoundingBoxD();
            GetGizmoPointTestVariables(ref invGridWorldMatrix, gridSize, out gizmoBox, out m, gizmo, inflate: inflate, onVoxel: onVoxel);

            foreach (var point in points)
            {
                Vector3 localPoint = Vector3.Transform(point, m);

                if (gizmoBox.Contains(localPoint) == ContainmentType.Contains)
                    return true;
            }
            return false;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:15,代码来源:MyCubeBuilderGizmo.cs

示例4: FindForestInitialCandidate

        private void FindForestInitialCandidate()
        {
            BoundingBoxD groundBox = m_ground.PositionComp.WorldAABB;
            Vector3D boxSize = groundBox.Size;
            boxSize *= 0.1f;
            groundBox.Inflate(-boxSize);
            MyBBSetSampler sampler = new MyBBSetSampler(groundBox.Min, groundBox.Max);

            bool posIsValid = true;
            Vector3D worldPos = default(Vector3D);
            int counter = 0;
            do
            {
                // find random position for starting 
                worldPos = sampler.Sample();
                var worldPosProjected = worldPos;
                worldPosProjected.Y = 0.5f;
                posIsValid = true;
                counter++;
                Vector3D areaCheck = new Vector3D(20, 20, 20);
                foreach (var enqueued in m_initialForestLocations)
                {
                    // only interested in XZ plane
                    BoundingBoxD tmp = new BoundingBoxD(enqueued - areaCheck, enqueued + areaCheck);
                    tmp.Min.Y = 0;
                    tmp.Max.Y = 1;

                    if (tmp.Contains(worldPosProjected) == ContainmentType.Contains)
                    {
                        posIsValid = false;
                        break;
                    }
                }
            } while (!posIsValid && counter != 10);

            if (!posIsValid)
            {
                // could not find any position
                return;
            }

            var lineStart = new Vector3D(worldPos.X, groundBox.Max.Y, worldPos.Z);
            var lineEnd = new Vector3D(worldPos.X, groundBox.Min.Y, worldPos.Z);
            LineD line = new LineD(lineStart, lineEnd);
            VRage.Game.Models.MyIntersectionResultLineTriangleEx? result = null;
            var correctGroundDefinition = MyDefinitionManager.Static.GetVoxelMaterialDefinition("Grass");
            var materialId = correctGroundDefinition.Index;

            if (m_ground.GetIntersectionWithLine(ref line, out result, VRage.Game.Components.IntersectionFlags.DIRECT_TRIANGLES))
            {
                Vector3D intersectionPoint = result.Value.IntersectionPointInWorldSpace;
                Vector3I voxelCoord, minRead, maxRead;
                MyVoxelCoordSystems.WorldPositionToVoxelCoord(m_ground.PositionLeftBottomCorner, ref intersectionPoint, out voxelCoord);
                minRead = voxelCoord - Vector3I.One;
                maxRead = voxelCoord + Vector3I.One;
                m_ground.Storage.ReadRange(m_voxelCache, MyStorageDataTypeFlags.Material, 0, ref minRead, ref maxRead);

                var minLocal = Vector3I.Zero;
                var maxLocal = Vector3I.One * 2;
                var it = new Vector3I_RangeIterator(ref minLocal, ref maxLocal);
                while (it.IsValid())
                {
                    var vec = it.Current;
                    var material = m_voxelCache.Material(ref vec);
                    if (material == materialId)
                    {
                        // found a location
                        var desired = voxelCoord - Vector3I.One + vec;
                        Vector3D desiredWorldPosition = default(Vector3D);
                        MyVoxelCoordSystems.VoxelCoordToWorldPosition(m_ground.PositionLeftBottomCorner, ref desired, out desiredWorldPosition);
                        m_initialForestLocations.Enqueue(desiredWorldPosition);
                        break;
                    }

                    it.MoveNext();
                }
            }
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:78,代码来源:MyFloraAreas.cs

示例5: CastPhysicsRay

        /// <summary>
        /// Performes a physics raycast
        /// It can be recursive (it calls CastDDA when it hits a grid).
        /// </summary>
        /// <param name="fromWorldPos"></param>
        /// <returns>Returns starting damage for current stack</returns>
        private MyRaycastDamageInfo CastPhysicsRay(Vector3D fromWorldPos)
        {
            Vector3D pos = Vector3D.Zero;
            IMyEntity hitEntity = null;

            var hitInfo = MyPhysics.CastRay(fromWorldPos, m_explosion.Center, MyPhysics.ExplosionRaycastLayer);
            if (hitInfo.HasValue)
            {
                hitEntity = (hitInfo.Value.HkHitInfo.Body.UserObject != null) ? ((MyPhysicsBody)hitInfo.Value.HkHitInfo.Body.UserObject).Entity : null;
                pos = hitInfo.Value.Position;
            }
            Vector3D direction = (m_explosion.Center - fromWorldPos);
            float lengthToCenter = (float)direction.Length();
            direction.Normalize();

            var grid = (hitEntity as MyCubeGrid);
            if (grid == null)
            {
                MyCubeBlock hitBlock = hitEntity as MyCubeBlock;
                if (hitBlock != null)
                {
                    grid = hitBlock.CubeGrid;
                }
            }
            if (grid != null)
            {
                //Try advancing the point to find the intersected block
                //If the block is a cube, this is necessary because the raycast will return a point somewhere outside the cube
                //If the block is not a full cube (slope, special block), the raycast can return inside the cube
                //It advances 4 times, each time one 8th the grid size
                for (int i = 0; i < 5; i++)
                {
                    Vector3D localPos = Vector3D.Transform(pos, grid.PositionComp.WorldMatrixNormalizedInv) / grid.GridSize;
                    Vector3I gridPos = Vector3I.Round(localPos);
                    var cubeBlock = grid.GetCubeBlock(gridPos);
                    if (cubeBlock != null)
                    {
                        if (m_castBlocks.Contains(cubeBlock))
                        {
                            //This shouldn't happen
                            //There is a corner case where the explosion position is inside the empty cell, but this should be handleded somewhere higher
                            System.Diagnostics.Debug.Fail("Raycast failed!");
                            DrawRay(fromWorldPos, pos, Color.Red);
                            return new MyRaycastDamageInfo(0f, lengthToCenter);
                        }
                        else
                        {
                            if (MyDebugDrawSettings.DEBUG_DRAW_EXPLOSION_HAVOK_RAYCASTS)
                                DrawRay(fromWorldPos, pos, Color.Blue);
                            return CastDDA(cubeBlock);
                        }
                    }
                    pos += direction * grid.GridSize / 8f;
                }
                //We hit a grid but were unable to find the hit cube. Send another raycast
                //Ideally, we would want to get the cube in all cases, but it also has to be fast
                //We need to check if the explosion center is between the initial start position (fromWorldPos) and the new one (pos)

                Vector3D min = new Vector3D(Math.Min(fromWorldPos.X, pos.X), Math.Min(fromWorldPos.Y, pos.Y), Math.Min(fromWorldPos.Z, pos.Z));
                Vector3D max = new Vector3D(Math.Max(fromWorldPos.X, pos.X), Math.Max(fromWorldPos.Y, pos.Y), Math.Max(fromWorldPos.Z, pos.Z));

                BoundingBoxD boundingBox = new BoundingBoxD(min, max);
                if (boundingBox.Contains(m_explosion.Center) == ContainmentType.Contains)
                {
                    return new MyRaycastDamageInfo(m_explosionDamage, lengthToCenter);
                }

                stackOverflowGuard++;
                if (stackOverflowGuard > MAX_PHYSICS_RECURSION_COUNT)
                {
                    System.Diagnostics.Debug.Fail("Potential stack overflow!");
                    if (MyDebugDrawSettings.DEBUG_DRAW_EXPLOSION_HAVOK_RAYCASTS)
                        DrawRay(fromWorldPos, pos, Color.Red);
                    return new MyRaycastDamageInfo(0f, lengthToCenter);
                }
                else
                {
                    if (MyDebugDrawSettings.DEBUG_DRAW_EXPLOSION_HAVOK_RAYCASTS)
                        DrawRay(fromWorldPos, pos, Color.White);
                    return CastPhysicsRay(pos);
                }
            }
            else if (hitInfo.HasValue)
            {
                //Something was hit, but it wasn't a grid. This needs to be handled somehow
                if (MyDebugDrawSettings.DEBUG_DRAW_EXPLOSION_HAVOK_RAYCASTS)
                    DrawRay(fromWorldPos, pos, Color.Violet);
                return new MyRaycastDamageInfo(0, lengthToCenter);
            }

            //Nothing was hit, so we can assume the there was nothing blocking the explosion
            if (MyDebugDrawSettings.DEBUG_DRAW_EXPLOSION_HAVOK_RAYCASTS)
                DrawRay(fromWorldPos, pos, Color.Salmon);
            return new MyRaycastDamageInfo(m_explosionDamage, lengthToCenter);
//.........这里部分代码省略.........
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:101,代码来源:MyExplosionDamage.cs

示例6: PointsAABBIntersectsGizmo

        public bool PointsAABBIntersectsGizmo(List<Vector3D> points, MyGizmoSpaceEnum gizmo, ref MatrixD invGridWorldMatrix, float gridSize, float inflate = 0.0f, bool onVoxel = false, bool dynamicMode = false)
        {
            MatrixD m = new MatrixD();
            BoundingBoxD gizmoBox = new BoundingBoxD();
            GetGizmoPointTestVariables(ref invGridWorldMatrix, gridSize, out gizmoBox, out m, gizmo, inflate: inflate, onVoxel: onVoxel, dynamicMode: dynamicMode);

            BoundingBoxD pointsBox = BoundingBoxD.CreateInvalid();
            foreach (var point in points)
            {
                Vector3D localPoint = Vector3D.Transform(point, m);

                if (gizmoBox.Contains(localPoint) == ContainmentType.Contains)
                    return true;

                pointsBox.Include(localPoint);
            }

            return pointsBox.Intersects(ref gizmoBox);
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:19,代码来源:MyCubeBuilderGizmo.cs


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