public static VoxLocation?GetLevel(Ray camRay, VoxState state, int h) { camRay.Position -= new Vector3(state.World.worldMin.X * Region.WIDTH, 0, state.World.worldMin.Y * Region.DEPTH); VRay vr = new VRay(camRay.Position, camRay.Direction); Vector3I loc = vr.GetNextLocation(); // Check For World Intersect BoundingBox bb = new BoundingBox(new Vector3(0, h - 1, 0), new Vector3(VoxWorld.WIDTH * Region.WIDTH, h, VoxWorld.DEPTH * Region.DEPTH)); if (!camRay.Intersects(bb).HasValue) { return(null); } // Move In World while (!IsInBounds(loc)) { loc = vr.GetNextLocation(); } // Move Through World while (IsInBounds(loc)) { VoxLocation vl = new VoxLocation(loc); Region region = state.World.regions[vl.RegionIndex]; ushort id = region.voxels[vl.VoxelIndex].ID; if (loc.Y == h) { return(vl); } loc = vr.GetNextLocation(); } return(null); }
public static VoxLocation?GetOuter(Ray camRay, VoxState state) { camRay.Position -= new Vector3(state.World.worldMin.X * Region.WIDTH, 0, state.World.worldMin.Y * Region.DEPTH); VRay vr = new VRay(camRay.Position, camRay.Direction); Vector3I loc = vr.GetNextLocation(); // Check For World Intersect BoundingBox bb = new BoundingBox(Vector3.Zero, new Vector3(VoxWorld.WIDTH * Region.WIDTH, Region.HEIGHT, VoxWorld.DEPTH * Region.DEPTH)); if (!camRay.Intersects(bb).HasValue) { return(null); } // Move In World while (!IsInBounds(loc)) { loc = vr.GetNextLocation(); } // Move Through World VoxLocation pvl = new VoxLocation(loc); while (IsInBounds(loc)) { VoxLocation vl = new VoxLocation(loc); Region region = state.World.regions[vl.RegionIndex]; if (region != null) { ushort id = region.voxels[vl.VoxelIndex].ID; if (id != 0) { return(pvl); } } loc = vr.GetNextLocation(); pvl = vl; } return(null); }