Beispiel #1
0
 public VoxelMaterial GetVoxel(Point3 pos)
 {
     if (IsOutside(pos))
     {
         return(null);
     }
     return(terrainChunk.GetVoxelInternal(pos).Filled ? mat : null);
 }
Beispiel #2
0
            private void clearVisible()
            {
                for (int index = 0; index < visibleBlocks.Count; index++)
                {
                    var b = visibleBlocks[index];
                    TerrainChunk.GetVoxelInternal(ref b).Visible = false;
                }

                visibleBlocks.Clear();
            }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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);
        }