public static LocalVoxelPos_t WorldToLocalVoxel(WorldVoxelPos_t p) { return(new LocalVoxelPos_t { vx = WorldToLocalVoxel(p.vx, VOXEL_CHUNK_SIZE_XZ), vy = WorldToLocalVoxel(p.vy, VOXEL_CHUNK_SIZE_Y), vz = WorldToLocalVoxel(p.vz, VOXEL_CHUNK_SIZE_XZ) }); }
public static WorldChunkPos_t WorldToChunk(WorldVoxelPos_t p) { return(new WorldChunkPos_t { cx = WorldToChunk(p.vx, VOXEL_CHUNK_SIZE_XZ), cy = WorldToChunk(p.vy, VOXEL_CHUNK_SIZE_Y), cz = WorldToChunk(p.vz, VOXEL_CHUNK_SIZE_XZ) }); }
public static Vector3 WorldToVec3(WorldVoxelPos_t p) { var c = WorldToChunk(p); var v = WorldToLocalVoxel(p); return(new Vector3( (float)((c.cx * VOXEL_CHUNK_SIZE_XZ) + v.vx), (float)((c.cy * VOXEL_CHUNK_SIZE_Y) + v.vy), (float)((c.cz * VOXEL_CHUNK_SIZE_XZ) + v.vz) )); }
static PinnedChunkData_t GenerateVoxelsSinWave(WorldChunkPos_t cpos, PinnedChunkData_t chunk) { var Y_OFS = (VOXEL_CHUNK_SIZE_Y * MaxVoxelChunkLine(VOXEL_CHUNK_VIS_MAX_Y)) / 8; bool solid = false; bool air = false; chunk.flags = EChunkFlags.LAYER_DEFAULT; WorldVoxelPos_t pos = ChunkToWorld(cpos); Vector3 v3 = WorldToVec3(pos); for (int x = 0; x < VOXEL_CHUNK_SIZE_XZ; ++x) { for (int z = 0; z < VOXEL_CHUNK_SIZE_XZ; ++z) { var cs = Mathf.Cos((v3.x + x) / 64); var ss = Mathf.Sin((v3.z + z) / 64); for (int y = 0; y < VOXEL_CHUNK_SIZE_Y; ++y) { var ofs = x + (z * VOXEL_CHUNK_SIZE_XZ) + (y * VOXEL_CHUNK_SIZE_XZ * VOXEL_CHUNK_SIZE_XZ); var ypos = v3.y + y; if (ypos < ((cs + ss) * (Y_OFS / 2))) { chunk.voxeldata[ofs] = EVoxelBlockType.Dirt; solid = true; } else { air = true; chunk.voxeldata[ofs] = EVoxelBlockType.Air; } } } } if (solid) { chunk.flags |= EChunkFlags.SOLID; } if (air) { chunk.flags |= EChunkFlags.AIR; } chunk.flags |= EChunkFlags.LAYER_DEFAULT; return(chunk); }
void Reveal(Vector2 pos, int radius) { float pixelsPerVoxel = (float)_sizePixels / _worldSize; var mapBottomLeft = new WorldVoxelPos_t((int)((-_worldSize / 2) * pixelsPerVoxel), 0, (int)((-_worldSize / 2) * pixelsPerVoxel)); var blockColors = World.Streaming.blockColors; int minX = (int)(pos.x * pixelsPerVoxel) - _revealSizePixels / 2; int minZ = (int)(pos.y * pixelsPerVoxel) - _revealSizePixels / 2; for (int z = 0; z < _revealSizePixels; ++z) { var zofs = z * _revealSizePixels; int vz = (int)pos.y + (int)((z - _revealSizePixels / 2) / pixelsPerVoxel); for (int x = 0; x < _revealSizePixels; ++x) { var ofs = zofs + x; int vx = (int)pos.x + (int)((x - _revealSizePixels / 2) / pixelsPerVoxel); EVoxelBlockType voxel; int elevation; _streaming.GetElevationAndTopBlock(vx, vz, out elevation, out voxel); if (voxel == EVoxelBlockType.Air) { continue; } var color = blockColors[(int)(voxel) - 1]; const float minElevation = -10; const float maxElevation = 54; float elevationT = (float)(elevation - minElevation) / (maxElevation - minElevation); Color32 elevationColor = Color32.Lerp(new Color(elevationT, elevationT, elevationT, 1f), color, 0.35f); _pixels[ofs] = elevationColor; } } _blitTexture.SetPixels32(_pixels); _blitTexture.Apply(); BlitToMainTexture(_blitTexture, minX - mapBottomLeft.vx, minZ - mapBottomLeft.vz); GL.sRGBWrite = false; Graphics.SetRenderTarget(_maskTexture); GL.PushMatrix(); GL.LoadPixelMatrix(0, _sizePixels, 0, _sizePixels); Graphics.DrawTexture(new Rect(minX - mapBottomLeft.vx, minZ - mapBottomLeft.vz, _revealSizePixels, _revealSizePixels), _revealTexture, _maskBlitMaterial); GL.PopMatrix(); Graphics.SetRenderTarget(null); }