private static VoxelBlock getChunkVoxelWrapper(VoxelTerrainChunk chunk, Point3 point) { var voxelInternal = chunk.GetVoxelInternal(ref point); if (voxelInternal == null) { return(null); } return(new VoxelBlock(point, chunk, voxelInternal)); }
public RenderData(VoxelTerrainChunk terrainChunk) { TerrainChunk = terrainChunk; _ent = new WorldRendering.Entity(); }
public VoxelAdapter(VoxelTerrainChunk terrainChunk) { this.terrainChunk = terrainChunk; }
public VoxelBlock(Point3 position, VoxelTerrainChunk terrainChunk, VoxelTerrainChunk.Voxel block) { this.RelativePosition = position; this.TerrainChunk = terrainChunk; this.block = block; }
protected bool Equals(VoxelTerrainChunk other) { return(Size.Equals(other.Size) && WorldPosition.Equals(other.WorldPosition) && NodeSize.Equals(other.NodeSize)); }
public VoxelBlock Raycast(Ray ray, out VoxelBlock emptyTargetedBlock) { VoxelBlock last = null; VoxelBlock ret = null; var traverser = new GridTraverser(); float?closest = null; foreach (VoxelTerrainChunk terr in TW.Data.Objects.Where(o => o is VoxelTerrainChunk)) { var trace = new RayTrace(); trace.Ray = ray; float?dist = trace.Ray.xna().Intersects(terr.GetBoundingBox().xna()); if (!dist.HasValue) { continue; } if (closest.HasValue && closest.Value < dist.Value) { continue; } trace.Start = dist.Value + 0.001f; traverser.NodeSize = terr.NodeSize; traverser.GridOffset = terr.WorldPosition; //TODO: fix multiple terrains var hit = false; VoxelTerrainChunk terr1 = terr; traverser.Traverse(trace, delegate(Point3 arg) { if (!terr1.InGrid(arg)) { return(true); } var voxelBlock = terr1.GetVoxelInternal(ref arg); if (voxelBlock == null) { return(false); } if (voxelBlock.Filled) { hit = true; ret = getChunkVoxelWrapper(terr1, arg); return(true); } last = getChunkVoxelWrapper(terr1, arg); return(false); }); if (hit) { closest = dist; } } emptyTargetedBlock = last; return(ret); }