Esempio n. 1
0
        private List <AxisAlignedBoundingBox> GetCollidingObjects(Vector3 newPosition)
        {
            List <AxisAlignedBoundingBox> collidingObjects = new List <AxisAlignedBoundingBox>();

            World theWorld = World.Instance;
            AxisAlignedBoundingBox thisAABB = entity.AABB;

            thisAABB.Translate(newPosition);

            AxisAlignedBoundingBox sweepAABB = thisAABB;

            //sweepAABB.Min.Y--;
            sweepAABB.AlignToWorldGrid();
            for (int x = (int)sweepAABB.Min.X; x <= (int)sweepAABB.Max.X; x++)
            {
                for (int y = (int)sweepAABB.Min.Y; y <= (int)sweepAABB.Max.Y; y++)
                {
                    for (int z = (int)sweepAABB.Min.Z; z <= (int)sweepAABB.Max.Z; z++)
                    {
                        int   blockId = theWorld.GetBlock(x, y, z);
                        Block alien   = BlockRepository.Blocks[blockId];
                        if (!alien.IsOpaque)
                        {
                            continue;
                        }
                        AxisAlignedBoundingBox collidingObject = alien.BoundingBox;
                        collidingObject.Translate(new Vector3(x, y, z));
                        if (thisAABB.OverLaps(collidingObject))
                        {
                            collidingObjects.Add(collidingObject);
                        }
                    }
                }
            }
            return(collidingObjects);
        }