public static ColumnResult GetColumn(VoxWorld vw, int x, int z, int w, int h, IVoxGridResolver vgr) { VoxLocation vl = new VoxLocation(new Vector3I(x, Region.HEIGHT - 1, z)); ColumnResult cr = new ColumnResult(); ushort id; // Get Height Information cr.Height = new RTSEngine.Data.HeightTile(); Region r = vw.regions[vl.RegionIndex]; int ramp; for (; vl.VoxelLoc.Y > 0; vl.VoxelLoc.Y--) { id = r.voxels[vl.VoxelIndex].ID; if (vgr.TryGetFlat(id)) { cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; } else if (vgr.TryGetRamp(id, out ramp)) { switch (ramp) { case 0: cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 0; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 0; break; case 1: cr.Height.XNZN = vl.VoxelLoc.Y + 0; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 0; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; case 2: cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 0; cr.Height.XPZP = vl.VoxelLoc.Y + 0; break; case 3: cr.Height.XNZN = vl.VoxelLoc.Y + 0; cr.Height.XPZN = vl.VoxelLoc.Y + 0; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; } if (vl.VoxelLoc.Y > 0) { vl.VoxelLoc.Y--; } break; } } // Get Wall Information cr.Walls = 0x00; if (x == 0) { cr.Walls |= CollisionGrid.Direction.XN; } else { Point hi = vgr.HeightIndex(vw, x, z, 0); Point hin = vgr.HeightIndex(vw, x - 1, z, 1); if (hin != hi) { cr.Walls |= CollisionGrid.Direction.XN; } } if (x == w - 1) { cr.Walls |= CollisionGrid.Direction.XP; } else { Point hi = vgr.HeightIndex(vw, x, z, 1); Point hin = vgr.HeightIndex(vw, x + 1, z, 0); if (hin != hi) { cr.Walls |= CollisionGrid.Direction.XP; } } if (z == 0) { cr.Walls |= CollisionGrid.Direction.ZN; } else { Point hi = vgr.HeightIndex(vw, x, z, 2); Point hin = vgr.HeightIndex(vw, x, z - 1, 3); if (hin != hi) { cr.Walls |= CollisionGrid.Direction.ZN; } } if (z == h - 1) { cr.Walls |= CollisionGrid.Direction.ZP; } else { Point hi = vgr.HeightIndex(vw, x, z, 3); Point hin = vgr.HeightIndex(vw, x, z + 1, 2); if (hin != hi) { cr.Walls |= CollisionGrid.Direction.ZP; } } if ((cr.Walls & CollisionGrid.Direction.XN) != 0 && (cr.Walls & CollisionGrid.Direction.ZN) != 0) { cr.Walls |= CollisionGrid.Direction.XNZN; } if ((cr.Walls & CollisionGrid.Direction.XP) != 0 && (cr.Walls & CollisionGrid.Direction.ZN) != 0) { cr.Walls |= CollisionGrid.Direction.XPZN; } if ((cr.Walls & CollisionGrid.Direction.XN) != 0 && (cr.Walls & CollisionGrid.Direction.ZP) != 0) { cr.Walls |= CollisionGrid.Direction.XNZP; } if ((cr.Walls & CollisionGrid.Direction.XP) != 0 && (cr.Walls & CollisionGrid.Direction.ZP) != 0) { cr.Walls |= CollisionGrid.Direction.XPZP; } return(cr); }
public static ColumnResult GetColumn(VoxWorld vw, int x, int z, int w, int h, IVoxGridResolver vgr) { VoxLocation vl = new VoxLocation(new Vector3I(x, Region.HEIGHT - 1, z)); ColumnResult cr = new ColumnResult(); ushort id; // Get Height Information cr.Height = new RTSEngine.Data.HeightTile(); Region r = vw.regions[vl.RegionIndex]; int ramp; for(; vl.VoxelLoc.Y > 0; vl.VoxelLoc.Y--) { id = r.voxels[vl.VoxelIndex].ID; if(vgr.TryGetFlat(id)) { cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; } else if(vgr.TryGetRamp(id, out ramp)) { switch(ramp) { case 0: cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 0; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 0; break; case 1: cr.Height.XNZN = vl.VoxelLoc.Y + 0; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 0; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; case 2: cr.Height.XNZN = vl.VoxelLoc.Y + 1; cr.Height.XPZN = vl.VoxelLoc.Y + 1; cr.Height.XNZP = vl.VoxelLoc.Y + 0; cr.Height.XPZP = vl.VoxelLoc.Y + 0; break; case 3: cr.Height.XNZN = vl.VoxelLoc.Y + 0; cr.Height.XPZN = vl.VoxelLoc.Y + 0; cr.Height.XNZP = vl.VoxelLoc.Y + 1; cr.Height.XPZP = vl.VoxelLoc.Y + 1; break; } if(vl.VoxelLoc.Y > 0) vl.VoxelLoc.Y--; break; } } // Get Wall Information cr.Walls = 0x00; if(x == 0) { cr.Walls |= CollisionGrid.Direction.XN; } else { Point hi = vgr.HeightIndex(vw, x, z, 0); Point hin = vgr.HeightIndex(vw, x - 1, z, 1); if(hin != hi) cr.Walls |= CollisionGrid.Direction.XN; } if(x == w - 1) { cr.Walls |= CollisionGrid.Direction.XP; } else { Point hi = vgr.HeightIndex(vw, x, z, 1); Point hin = vgr.HeightIndex(vw, x + 1, z, 0); if(hin != hi) cr.Walls |= CollisionGrid.Direction.XP; } if(z == 0) { cr.Walls |= CollisionGrid.Direction.ZN; } else { Point hi = vgr.HeightIndex(vw, x, z, 2); Point hin = vgr.HeightIndex(vw, x, z - 1, 3); if(hin != hi) cr.Walls |= CollisionGrid.Direction.ZN; } if(z == h - 1) { cr.Walls |= CollisionGrid.Direction.ZP; } else { Point hi = vgr.HeightIndex(vw, x, z, 3); Point hin = vgr.HeightIndex(vw, x, z + 1, 2); if(hin != hi) cr.Walls |= CollisionGrid.Direction.ZP; } if((cr.Walls & CollisionGrid.Direction.XN) != 0 && (cr.Walls & CollisionGrid.Direction.ZN) != 0) cr.Walls |= CollisionGrid.Direction.XNZN; if((cr.Walls & CollisionGrid.Direction.XP) != 0 && (cr.Walls & CollisionGrid.Direction.ZN) != 0) cr.Walls |= CollisionGrid.Direction.XPZN; if((cr.Walls & CollisionGrid.Direction.XN) != 0 && (cr.Walls & CollisionGrid.Direction.ZP) != 0) cr.Walls |= CollisionGrid.Direction.XNZP; if((cr.Walls & CollisionGrid.Direction.XP) != 0 && (cr.Walls & CollisionGrid.Direction.ZP) != 0) cr.Walls |= CollisionGrid.Direction.XPZP; return cr; }