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


C# AABB.Intersects方法代码示例

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


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

示例1: TouchesAny

        /// <summary> Determines whether any of the blocks that intersect the
        /// given bounding box satisfy the given condition. </summary>
        public bool TouchesAny( AABB bounds, Predicate<byte> condition )
        {
            Vector3I bbMin = Vector3I.Floor( bounds.Min );
            Vector3I bbMax = Vector3I.Floor( bounds.Max );

            // Order loops so that we minimise cache misses
            for( int y = bbMin.Y; y <= bbMax.Y; y++ )
                for( int z = bbMin.Z; z <= bbMax.Z; z++ )
                    for( int x = bbMin.X; x <= bbMax.X; x++ )
            {
                if( !game.World.IsValidPos( x, y, z ) ) continue;
                byte block = game.World.GetBlock( x, y, z );
                Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
                Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];

                AABB blockBB = new AABB( min, max );
                if( !blockBB.Intersects( bounds ) ) continue;
                if( condition( block ) ) return true;
            }
            return false;
        }
开发者ID:Retatta,项目名称:ClassicalSharp,代码行数:23,代码来源:Entity.Bounds.cs

示例2: LowestModifier

        float LowestModifier( AABB bounds, bool checkSolid )
        {
            Vector3I bbMin = Vector3I.Floor( bounds.Min );
            Vector3I bbMax = Vector3I.Floor( bounds.Max );
            float modifier = inf;

            for( int y = bbMin.Y; y <= bbMax.Y; y++ )
                for( int z = bbMin.Z; z <= bbMax.Z; z++ )
                    for( int x = bbMin.X; x <= bbMax.X; x++ )
            {
                byte block = game.World.SafeGetBlock( x, y, z );
                if( block == 0 ) continue;
                CollideType type = info.Collide[block];
                if( type == CollideType.Solid && !checkSolid )
                    continue;

                Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
                Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];
                AABB blockBB = new AABB( min, max );
                if( !blockBB.Intersects( bounds ) ) continue;

                modifier = Math.Min( modifier, info.SpeedMultiplier[block] );
                if( block >= BlockInfo.CpeCount && type == CollideType.SwimThrough )
                    useLiquidGravity = true;
            }
            return modifier;
        }
开发者ID:Retatta,项目名称:ClassicalSharp,代码行数:27,代码来源:PhysicsComponent.cs

示例3: FindReachableBlocks

        void FindReachableBlocks( ref int count, out AABB entityBB, 
            out AABB entityExtentBB)
        {
            Vector3 vel = entity.Velocity;
            entityBB = entity.CollisionBounds;

            // Exact maximum extent the entity can reach, and the equivalent map coordinates.
            entityExtentBB = new AABB(
                vel.X < 0 ? entityBB.Min.X + vel.X : entityBB.Min.X,
                vel.Y < 0 ? entityBB.Min.Y + vel.Y : entityBB.Min.Y,
                vel.Z < 0 ? entityBB.Min.Z + vel.Z : entityBB.Min.Z,
                vel.X > 0 ? entityBB.Max.X + vel.X : entityBB.Max.X,
                vel.Y > 0 ? entityBB.Max.Y + vel.Y : entityBB.Max.Y,
                vel.Z > 0 ? entityBB.Max.Z + vel.Z : entityBB.Max.Z
            );
            Vector3I min = Vector3I.Floor( entityExtentBB.Min );
            Vector3I max = Vector3I.Floor( entityExtentBB.Max );

            int elements = (max.X + 1 - min.X) * (max.Y + 1 - min.Y) * (max.Z + 1 - min.Z);
            if( elements > stateCache.Length ) {
                stateCache = new State[elements];
            }

            AABB blockBB = default( AABB );
            // Order loops so that we minimise cache misses
            for( int y = min.Y; y <= max.Y; y++ )
                for( int z = min.Z; z <= max.Z; z++ )
                    for( int x = min.X; x <= max.X; x++ )
            {
                byte blockId = GetPhysicsBlockId( x, y, z );
                if( !GetBoundingBox( blockId, x, y, z, ref blockBB ) ) continue;
                if( !entityExtentBB.Intersects( blockBB ) ) continue; // necessary for non whole blocks. (slabs)

                float tx = 0, ty = 0, tz = 0;
                CalcTime( ref vel, ref entityBB, ref blockBB, out tx, out ty, out tz );
                if( tx > 1 || ty > 1 || tz > 1 ) continue;
                float tSquared = tx * tx + ty * ty + tz * tz;
                stateCache[count++] = new State( x, y, z, blockId, tSquared );
            }
        }
开发者ID:Retatta,项目名称:ClassicalSharp,代码行数:40,代码来源:CollisionsComponent.cs

示例4: CollideWithReachableBlocks

        void CollideWithReachableBlocks( int count, ref Vector3 size,
            ref AABB entityBB, ref AABB entityExtentBB)
        {
            bool wasOn = entity.onGround;
            entity.onGround = false;
            if( count > 0 )
                QuickSort( stateCache, 0, count - 1 );
            hitXMin = false; hitYMin = false; hitZMin = false;
            hitXMax = false; hitYMax = false; hitZMax = false;
            AABB blockBB = default(AABB);

            for( int i = 0; i < count; i++ ) {
                State state = stateCache[i];
                Vector3 blockPos = new Vector3( state.X >> 3, state.Y >> 3, state.Z >> 3 );
                int block = (state.X & 0x7) | (state.Y & 0x7) << 3 | (state.Z & 0x7) << 6;
                blockBB.Min = blockPos + info.MinBB[block];
                blockBB.Max = blockPos + info.MaxBB[block];
                if( !entityExtentBB.Intersects( blockBB ) ) continue;

                float tx = 0, ty = 0, tz = 0;
                CalcTime( ref entity.Velocity, ref entityBB, ref blockBB, out tx, out ty, out tz );
                if( tx > 1 || ty > 1 || tz > 1 )
                    Utils.LogDebug( "t > 1 in physics calculation.. this shouldn't have happened." );
                AABB finalBB = entityBB.Offset( entity.Velocity * new Vector3( tx, ty, tz ) );

                // if we have hit the bottom of a block, we need to change the axis we test first.
                if( !hitYMin ) {
                    if( finalBB.Min.Y + Adjustment >= blockBB.Max.Y )
                        ClipYMax( ref blockBB, ref entityBB, ref entityExtentBB, ref size );
                    else if( finalBB.Max.Y - Adjustment <= blockBB.Min.Y )
                        ClipYMin( ref blockBB, ref entityBB, ref entityExtentBB, ref size );
                    else if( finalBB.Min.X + Adjustment >= blockBB.Max.X )
                        ClipXMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                    else if( finalBB.Max.X - Adjustment <= blockBB.Min.X )
                        ClipXMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                    else if( finalBB.Min.Z + Adjustment >= blockBB.Max.Z )
                        ClipZMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                    else if( finalBB.Max.Z - Adjustment <= blockBB.Min.Z )
                        ClipZMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                    continue;
                }

                // if flying or falling, test the horizontal axes first.
                if( finalBB.Min.X + Adjustment >= blockBB.Max.X )
                    ClipXMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                else if( finalBB.Max.X - Adjustment <= blockBB.Min.X )
                    ClipXMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                else if( finalBB.Min.Z + Adjustment >= blockBB.Max.Z )
                    ClipZMax( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                else if( finalBB.Max.Z - Adjustment <= blockBB.Min.Z )
                    ClipZMin( ref blockBB, ref entityBB, wasOn, finalBB, ref entityExtentBB, ref size );
                else if( finalBB.Min.Y + Adjustment >= blockBB.Max.Y )
                    ClipYMax( ref blockBB, ref entityBB, ref entityExtentBB, ref size );
                else if( finalBB.Max.Y - Adjustment <= blockBB.Min.Y )
                    ClipYMin( ref blockBB, ref entityBB, ref entityExtentBB, ref size );
            }
        }
开发者ID:Retatta,项目名称:ClassicalSharp,代码行数:57,代码来源:CollisionsComponent.cs

示例5: CanSlideThrough

        bool CanSlideThrough( ref AABB adjFinalBB )
        {
            Vector3I bbMin = Vector3I.Floor( adjFinalBB.Min );
            Vector3I bbMax = Vector3I.Floor( adjFinalBB.Max );

            for( int y = bbMin.Y; y <= bbMax.Y; y++ )
                for( int z = bbMin.Z; z <= bbMax.Z; z++ )
                    for( int x = bbMin.X; x <= bbMax.X; x++ )
            {
                byte block = GetPhysicsBlockId( x, y, z );
                Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
                Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];

                AABB blockBB = new AABB( min, max );
                if( !blockBB.Intersects( adjFinalBB ) )
                    continue;
                if( info.Collide[GetPhysicsBlockId( x, y, z )] == CollideType.Solid )
                    return false;
            }
            return true;
        }
开发者ID:Retatta,项目名称:ClassicalSharp,代码行数:21,代码来源:CollisionsComponent.cs

示例6: Update

 public static void Update(AABB player)
 {
     if (player.Intersects(levelEnding))
     {
         loadLevel(nextLevel);
     }
 }
开发者ID:Olian04,项目名称:Canvas_theGame,代码行数:7,代码来源:Level.cs

示例7: TouchesAnyLiquid

        // If liquid block above, leave height same
        // otherwise reduce water BB height by 0.5 blocks
        bool TouchesAnyLiquid( AABB bounds, byte block1, byte block2 )
        {
            Vector3I bbMin = Vector3I.Floor( bounds.Min );
            Vector3I bbMax = Vector3I.Floor( bounds.Max );
            int height = game.World.Height;

            // Order loops so that we minimise cache misses
            for( int y = bbMin.Y; y <= bbMax.Y; y++ )
                for( int z = bbMin.Z; z <= bbMax.Z; z++ )
                    for( int x = bbMin.X; x <= bbMax.X; x++ )
            {
                if( !game.World.IsValidPos( x, y, z ) ) continue;
                byte block = game.World.GetBlock( x, y, z );
                byte below = (y - 1) < 0 ? (byte)0 : game.World.GetBlock( x, y - 1, z );
                byte above = (y + 1) >= height ? (byte)0 : game.World.GetBlock( x, y + 1, z );

                // TODO: use recording to find right constants when I have more time
                Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
                Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];
                //if( game.BlockInfo.Collide[below] != CollideType.SwimThrough )
                //	min.Y += 4/16f;
                //if( game.BlockInfo.Collide[above] != CollideType.SwimThrough )
                //	max.Y -= 4/16f;

                AABB blockBB = new AABB( min, max );
                if( !blockBB.Intersects( bounds ) ) continue;
                if( block == block1 || block == block2 ) return true;
            }
            return false;
        }
开发者ID:Retatta,项目名称:ClassicalSharp,代码行数:32,代码来源:Entity.Bounds.cs


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