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


C# AABB.Offset方法代码示例

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


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

示例1: 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


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