//private static Vector2[] uv = new Vector2[]{new Vector2(1,0), new Vector2(0,0), new Vector2(0,1), new Vector2(1,1)}; public List<Vertex> GetVertices(OctreeNode node, Block block, Chunk chunk, World world) { List<Vertex> vertices = new List<Vertex>(); int x = (int)(chunk.GetWorldLocation().X + node.origin.X), y = (int)(chunk.GetWorldLocation().Y + node.origin.Y), z = (int)(chunk.GetWorldLocation().Z + node.origin.Z); for(int face = 0; face < 6; face++){ Vector2[] uv = block.GetUV(face); Block block2 = world.GetBlock(x + (addsX[face] * node.blockSize), y + (addsX[face + 6] * node.blockSize), z + (addsX[face + 12] * node.blockSize)); if(!block2.material.solid) { int baseCorner = face * 4; for(int corner = 0; corner < 4; corner++){ Vertex vertex = new Vertex(corners[quadsOrder[baseCorner + corner]] * node.blockSize); vertex.position += node.origin - new Vector3(node.blockSize / 2f, node.blockSize / 2f, node.blockSize / 2f); vertex.color = block.material.color * brightness[face]; vertex.normal.X = node.blockSize; vertex.normal.Y = block.GetSheetX(face); vertex.normal.Z = block.GetSheetY(face); vertex.texCoord = uv[corner]; vertices.Add(vertex); triangles += 2; } } } return vertices; }
public void CreateTreeAt(int x, int y, int z, Chunk chunk) { for(int i = 1; i < 6; i++){ chunk.SetBlock(x, y + i, z, Block.log); } for(int X = -2; X <= 2; X++) for(int Y = 0; Y < 3; Y++) for(int Z = -2; Z <= 2; Z++) chunk.world.SetBlockSilent(chunk.GetWorldLocation() + new OpenTK.Vector3(x+X,y+Y+4,z+Z), Block.leaf); }
public void Generate(Chunk chunk) { WorldQuad[,] quads = new WorldQuad[Chunk.scale, Chunk.scale]; for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { //Generate quads to quad array quads[x,z] = GenerateQuad((int)chunk.GetWorldLocation().X + x, (int)chunk.GetWorldLocation().Z + z); } } for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { float dist = GetNearestWaterDistance(x, z, quads); quads[x,z].moisture = dist; quads[x,z].heat *= dist; //Do stuff based on surrounding quads } } for (int x = 0; x < Chunk.scale; x++) { for (int z = 0; z < Chunk.scale; z++) { //Finally set blocks int chunkYOffset = (int)chunk.GetWorldLocation().Y; WorldQuad quad = quads[x,z]; Biome biome = Biome.simple; foreach(Biome b in biomes) { if((quad.moisture <= b.moistureHigh) && (quad.moisture >= b.moistureLow) && (quad.heat <= b.heightHigh) && (quad.heat >= b.heightLow)) { biome = b; break; } } chunk.SetBlock(x, quad.height - chunkYOffset, z, biome.topBlock); if(quads[x,z].isOcean) chunk.SetBlock(x, 30 - chunkYOffset, z, Block.water); } } }