Example #1
0
        public static int FindIntersectingSolids(AABB bb, Level lvl, ref AABB[] aabbs)
        {
            Vec3S32 min = bb.BlockMin, max = bb.BlockMax;
            int     volume = (max.X - min.X + 1) * (max.Y - min.Y + 1) * (max.Z - min.Z + 1);

            if (volume > aabbs.Length)
            {
                aabbs = new AABB[volume];
            }
            int count = 0;

            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++)
                    {
                        BlockID block   = lvl.GetBlock((ushort)x, (ushort)y, (ushort)z);
                        AABB    blockBB = lvl.blockAABBs[block];

                        blockBB.Min.X += x * 32; blockBB.Min.Y += y * 32; blockBB.Min.Z += z * 32;
                        blockBB.Max.X += x * 32; blockBB.Max.Y += y * 32; blockBB.Max.Z += z * 32;
                        if (!AABB.Intersects(ref bb, ref blockBB))
                        {
                            continue;
                        }

                        BlockDefinition def   = lvl.GetBlockDef(block);
                        bool            solid = false;

                        if (def != null)
                        {
                            solid = CollideType.IsSolid(def.CollideType);
                        }
                        else
                        {
                            solid = block == Block.Invalid || !Block.Walkthrough(Block.Convert(block));
                        }
                        if (!solid)
                        {
                            continue;
                        }

                        aabbs[count] = blockBB;
                        count++;
                    }
                }
            }
            return(count);
        }
Example #2
0
        public static bool IntersectsSolidBlocks(AABB bb, Level lvl)
        {
            Vec3S32 min = bb.BlockMin, max = bb.BlockMax;

            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++)
                    {
                        ushort   xP = (ushort)x, yP = (ushort)y, zP = (ushort)z;
                        ExtBlock block = lvl.GetBlock(xP, yP, zP);

                        AABB blockBB = lvl.blockAABBs[block.Index].Offset(x * 32, y * 32, z * 32);
                        if (!AABB.Intersects(ref bb, ref blockBB))
                        {
                            continue;
                        }

                        BlockDefinition def = lvl.GetBlockDef(block);
                        if (def != null)
                        {
                            if (CollideType.IsSolid(def.CollideType))
                            {
                                return(true);
                            }
                        }
                        else if (block.BlockID == Block.Invalid)
                        {
                            if (y < lvl.Height)
                            {
                                return(true);
                            }
                        }
                        else if (!Block.Walkthrough(Block.Convert(block.BlockID)))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Example #3
0
 public static AABB Make(Vec3S32 pos, Vec3S32 size)
 {
     return(new AABB(pos.X - size.X / 2, pos.Y, pos.Z - size.Z / 2,
                     pos.X + size.X / 2, pos.Y + size.Y, pos.Z + size.Z / 2));
 }
Example #4
0
 public AABB(Vec3S32 min, Vec3S32 max)
 {
     Min = min;
     Max = max;
 }