private void TryMove(Vector3 moveVector) { // build a test move-vector slightly longer than moveVector. Vector3 testVector = moveVector; testVector.Normalize(); testVector *= moveVector.Length() + 0.3f; var footPosition = Position + new Vector3(0f, -0.5f, 0f); Vector3 testPosition = footPosition + testVector; if (BlockStorage.BlockAt(testPosition).Exists) { return; } // There should be some bounding box so his head does not enter a block above ;) /fasbat testPosition -= 2 * new Vector3(0f, -0.5f, 0f); if (BlockStorage.BlockAt(testPosition).Exists) { return; } this.Position += moveVector; }
public void Jump() { var footPosition = Position + new Vector3(0f, -1.5f, 0f); Block standingBlock = BlockStorage.BlockAt(footPosition); if (!standingBlock.Exists && this.Velocity.Y != 0) { return; } float amountBelowSurface = ((ushort)footPosition.Y) + 1 - footPosition.Y; Position += new Vector3(0, amountBelowSurface + 0.01f, 0); this.Velocity.Y = JumpVelocity; }
private void ProcessPosition(GameTime gameTime) { if (FlyingEnabled) { return; } this.Velocity.Y += Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; var footPosition = Position + new Vector3(0f, -1.5f, 0f); Block standingBlock = BlockStorage.BlockAt(footPosition); if (standingBlock.Exists) { this.Velocity.Y = 0; } this.Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; }
private void FindAimedBlock() { for (float x = 0.5f; x < 8f; x += 0.1f) { Vector3 target = this._camera.Position + (LookVector * x); var block = BlockStorage.BlockAt(target); if (!block.Exists) { this.AimedEmptyBlock = new PositionedBlock(new Vector3Int(target), block); } else { this.AimedSolidBlock = new PositionedBlock(new Vector3Int(target), block); return; } } this.AimedSolidBlock = null; }
private void PlantTree(Chunk chunk, int grassLevel, int grassOffset, int worldPositionX, int worldPositionZ) { // based on: http://techcraft.codeplex.com/SourceControl/changeset/view/5c1888588e5d#TechCraft%2fNewTake%2fNewTake%2fmodel%2fterrain%2fSimpleTerrain.cs var trunkHeight = (byte)(5 + (byte)_treePlanter.Next(10)); Console.WriteLine("tree location: {0},{1},{2}", worldPositionX, grassLevel, worldPositionZ); // trunk for (byte y = 1; y <= trunkHeight; y++) { BlockStorage.Blocks[grassOffset + y].Type = BlockType.Tree; // set the foliage. int radius = 2; Console.WriteLine("foliage: {0}-{1}, {2}, {3}", worldPositionX - radius, worldPositionX + radius, grassLevel + y, worldPositionZ); for (int x = worldPositionX - radius; x <= worldPositionX + radius; x++) { //for (int z = worldPositionZ - radius; z <= worldPositionZ + radius; z++) //{ if (!BlockStorage.BlockAt(x, grassLevel + y, worldPositionZ).Exists) { Console.Write("leave "); BlockStorage.SetBlockAt(x, grassLevel + y, worldPositionZ, new Block(BlockType.Leaves)); } else { Console.Write("solid "); } //} } Console.WriteLine(); } if (grassLevel + trunkHeight > chunk.HighestSolidBlockOffset) { chunk.HighestSolidBlockOffset = (byte)(grassLevel + trunkHeight + 1); } }
public void TestAllBlocksInCacheRange() { // read them back for (var x = this._cacheXStartIndex; x < this._cacheXEndIndex; x++) { for (var z = this._cacheZStartIndex; z < this._cacheZEndIndex; z++) { var offset = BlockStorage.BlockIndexByWorldPosition(x, z); for (var y = 0; y < _config.Chunk.HeightInBlocks; y++) { var index = offset + y; var expectedType = this._directlyIndexedValidationDictionary[index]; var blockIndexed = BlockStorage.Blocks[index]; Assert.AreEqual(expectedType, blockIndexed.Type); var blockAt = BlockStorage.BlockAt(x, y, z); Assert.AreEqual(expectedType, blockAt.Type); } } } }
/// <summary> /// Builds vertices for block. /// </summary> /// <param name="chunk"></param> /// <param name="blockIndex"> </param> /// <param name="worldPosition"></param> private void BuildBlockVertices(Chunk chunk, int blockIndex, Vector3Int worldPosition) { Block block = BlockStorage.Blocks[blockIndex]; // get the block to process. Block blockTopNW, blockTopN, blockTopNE, blockTopW, blockTopM, blockTopE, blockTopSW, blockTopS, blockTopSE; Block blockMidNW, blockMidN, blockMidNE, blockMidW, blockMidM, blockMidE, blockMidSW, blockMidS, blockMidSE; Block blockBotNW, blockBotN, blockBotNE, blockBotW, blockBotM, blockBotE, blockBotSW, blockBotS, blockBotSE; blockTopNW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y + 1, worldPosition.Z + 1); blockTopN = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y + 1, worldPosition.Z + 1); blockTopNE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y + 1, worldPosition.Z + 1); blockTopW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y + 1, worldPosition.Z); blockTopM = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y + 1, worldPosition.Z); blockTopE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y + 1, worldPosition.Z); blockTopSW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y + 1, worldPosition.Z - 1); blockTopS = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y + 1, worldPosition.Z - 1); blockTopSE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y + 1, worldPosition.Z - 1); blockMidNW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y, worldPosition.Z + 1); blockMidN = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y, worldPosition.Z + 1); blockMidNE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y, worldPosition.Z + 1); blockMidW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y, worldPosition.Z); // here comes the self block in order but we don't need to calculate it ;) blockMidE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y, worldPosition.Z); blockMidSW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y, worldPosition.Z - 1); blockMidS = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y, worldPosition.Z - 1); blockMidSE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y, worldPosition.Z - 1); blockBotNW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y - 1, worldPosition.Z + 1); blockBotN = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y - 1, worldPosition.Z + 1); blockBotNE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y - 1, worldPosition.Z + 1); blockBotW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y - 1, worldPosition.Z); blockBotM = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y - 1, worldPosition.Z); blockBotE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y - 1, worldPosition.Z); blockBotSW = BlockStorage.BlockAt(worldPosition.X - 1, worldPosition.Y - 1, worldPosition.Z - 1); blockBotS = BlockStorage.BlockAt(worldPosition.X, worldPosition.Y - 1, worldPosition.Z - 1); blockBotSE = BlockStorage.BlockAt(worldPosition.X + 1, worldPosition.Y - 1, worldPosition.Z - 1); float sunTR, sunTL, sunBR, sunBL; float redTR, redTL, redBR, redBL; float grnTR, grnTL, grnBR, grnBL; float bluTR, bluTL, bluBR, bluBL; Color localTR, localTL, localBR, localBL; localTR = Color.Black; localTL = Color.Yellow; localBR = Color.Green; localBL = Color.Blue; // -X face. if (!blockMidW.Exists && !(block.Type == BlockType.Water && blockMidW.Type == BlockType.Water)) { sunTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.Sun + blockTopW.Sun + blockMidNW.Sun + blockMidW.Sun) / 4); sunTR = (1f / Chunk.MaxSunValue) * ((blockTopSW.Sun + blockTopW.Sun + blockMidSW.Sun + blockMidW.Sun) / 4); sunBL = (1f / Chunk.MaxSunValue) * ((blockBotNW.Sun + blockBotW.Sun + blockMidNW.Sun + blockMidW.Sun) / 4); sunBR = (1f / Chunk.MaxSunValue) * ((blockBotSW.Sun + blockBotW.Sun + blockMidSW.Sun + blockMidW.Sun) / 4); redTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.R + blockTopW.R + blockMidNW.R + blockMidW.R) / 4); redTR = (1f / Chunk.MaxSunValue) * ((blockTopSW.R + blockTopW.R + blockMidSW.R + blockMidW.R) / 4); redBL = (1f / Chunk.MaxSunValue) * ((blockBotNW.R + blockBotW.R + blockMidNW.R + blockMidW.R) / 4); redBR = (1f / Chunk.MaxSunValue) * ((blockBotSW.R + blockBotW.R + blockMidSW.R + blockMidW.R) / 4); grnTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.G + blockTopW.G + blockMidNW.G + blockMidW.G) / 4); grnTR = (1f / Chunk.MaxSunValue) * ((blockTopSW.G + blockTopW.G + blockMidSW.G + blockMidW.G) / 4); grnBL = (1f / Chunk.MaxSunValue) * ((blockBotNW.G + blockBotW.G + blockMidNW.G + blockMidW.G) / 4); grnBR = (1f / Chunk.MaxSunValue) * ((blockBotSW.G + blockBotW.G + blockMidSW.G + blockMidW.G) / 4); bluTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.B + blockTopW.B + blockMidNW.B + blockMidW.B) / 4); bluTR = (1f / Chunk.MaxSunValue) * ((blockTopSW.B + blockTopW.B + blockMidSW.B + blockMidW.B) / 4); bluBL = (1f / Chunk.MaxSunValue) * ((blockBotNW.B + blockBotW.B + blockMidNW.B + blockMidW.B) / 4); bluBR = (1f / Chunk.MaxSunValue) * ((blockBotSW.B + blockBotW.B + blockMidSW.B + blockMidW.B) / 4); localTL = new Color(redTL, grnTL, bluTL); localTR = new Color(redTR, grnTR, bluTR); localBL = new Color(redBL, grnBL, bluBL); localBR = new Color(redBR, grnBR, bluBR); BuildFaceVertices(chunk, worldPosition, block.Type, BlockFaceDirection.XDecreasing, sunTL, sunTR, sunBL, sunBR, localTL, localTR, localBL, localBR); } // +X face. if (!blockMidE.Exists && !(block.Type == BlockType.Water && blockMidE.Type == BlockType.Water)) { sunTL = (1f / Chunk.MaxSunValue) * ((blockTopSE.Sun + blockTopE.Sun + blockMidSE.Sun + blockMidE.Sun) / 4); sunTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.Sun + blockTopE.Sun + blockMidNE.Sun + blockMidE.Sun) / 4); sunBL = (1f / Chunk.MaxSunValue) * ((blockBotSE.Sun + blockBotE.Sun + blockMidSE.Sun + blockMidE.Sun) / 4); sunBR = (1f / Chunk.MaxSunValue) * ((blockBotNE.Sun + blockBotE.Sun + blockMidNE.Sun + blockMidE.Sun) / 4); redTL = (1f / Chunk.MaxSunValue) * ((blockTopSE.R + blockTopE.R + blockMidSE.R + blockMidE.R) / 4); redTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.R + blockTopE.R + blockMidNE.R + blockMidE.R) / 4); redBL = (1f / Chunk.MaxSunValue) * ((blockBotSE.R + blockBotE.R + blockMidSE.R + blockMidE.R) / 4); redBR = (1f / Chunk.MaxSunValue) * ((blockBotNE.R + blockBotE.R + blockMidNE.R + blockMidE.R) / 4); grnTL = (1f / Chunk.MaxSunValue) * ((blockTopSE.G + blockTopE.G + blockMidSE.G + blockMidE.G) / 4); grnTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.G + blockTopE.G + blockMidNE.G + blockMidE.G) / 4); grnBL = (1f / Chunk.MaxSunValue) * ((blockBotSE.G + blockBotE.G + blockMidSE.G + blockMidE.G) / 4); grnBR = (1f / Chunk.MaxSunValue) * ((blockBotNE.G + blockBotE.G + blockMidNE.G + blockMidE.G) / 4); bluTL = (1f / Chunk.MaxSunValue) * ((blockTopSE.B + blockTopE.B + blockMidSE.B + blockMidE.B) / 4); bluTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.B + blockTopE.B + blockMidNE.B + blockMidE.B) / 4); bluBL = (1f / Chunk.MaxSunValue) * ((blockBotSE.B + blockBotE.B + blockMidSE.B + blockMidE.B) / 4); bluBR = (1f / Chunk.MaxSunValue) * ((blockBotNE.B + blockBotE.B + blockMidNE.B + blockMidE.B) / 4); localTL = new Color(redTL, grnTL, bluTL); localTR = new Color(redTR, grnTR, bluTR); localBL = new Color(redBL, grnBL, bluBL); localBR = new Color(redBR, grnBR, bluBR); BuildFaceVertices(chunk, worldPosition, block.Type, BlockFaceDirection.XIncreasing, sunTL, sunTR, sunBL, sunBR, localTL, localTR, localBL, localBR); } // -Y face. if (!blockBotM.Exists && !(block.Type == BlockType.Water && blockBotM.Type == BlockType.Water)) { sunBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.Sun + blockBotS.Sun + blockBotM.Sun + blockTopW.Sun) / 4); sunBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.Sun + blockBotS.Sun + blockBotM.Sun + blockTopE.Sun) / 4); sunTL = (1f / Chunk.MaxSunValue) * ((blockBotNW.Sun + blockBotN.Sun + blockBotM.Sun + blockTopW.Sun) / 4); sunTR = (1f / Chunk.MaxSunValue) * ((blockBotNE.Sun + blockBotN.Sun + blockBotM.Sun + blockTopE.Sun) / 4); redBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.R + blockBotS.R + blockBotM.R + blockTopW.R) / 4); redBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.R + blockBotS.R + blockBotM.R + blockTopE.R) / 4); redTL = (1f / Chunk.MaxSunValue) * ((blockBotNW.R + blockBotN.R + blockBotM.R + blockTopW.R) / 4); redTR = (1f / Chunk.MaxSunValue) * ((blockBotNE.R + blockBotN.R + blockBotM.R + blockTopE.R) / 4); grnBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.G + blockBotS.G + blockBotM.G + blockTopW.G) / 4); grnBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.G + blockBotS.G + blockBotM.G + blockTopE.G) / 4); grnTL = (1f / Chunk.MaxSunValue) * ((blockBotNW.G + blockBotN.G + blockBotM.G + blockTopW.G) / 4); grnTR = (1f / Chunk.MaxSunValue) * ((blockBotNE.G + blockBotN.G + blockBotM.G + blockTopE.G) / 4); bluBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.B + blockBotS.B + blockBotM.B + blockTopW.B) / 4); bluBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.B + blockBotS.B + blockBotM.B + blockTopE.B) / 4); bluTL = (1f / Chunk.MaxSunValue) * ((blockBotNW.B + blockBotN.B + blockBotM.B + blockTopW.B) / 4); bluTR = (1f / Chunk.MaxSunValue) * ((blockBotNE.B + blockBotN.B + blockBotM.B + blockTopE.B) / 4); localTL = new Color(redTL, grnTL, bluTL); localTR = new Color(redTR, grnTR, bluTR); localBL = new Color(redBL, grnBL, bluBL); localBR = new Color(redBR, grnBR, bluBR); BuildFaceVertices(chunk, worldPosition, block.Type, BlockFaceDirection.YDecreasing, sunTL, sunTR, sunBL, sunBR, localTL, localTR, localBL, localBR); } // +Y face. if (!blockTopM.Exists && !(block.Type == BlockType.Water && blockTopM.Type == BlockType.Water)) { sunTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.Sun + blockTopN.Sun + blockTopW.Sun + blockTopM.Sun) / 4); sunTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.Sun + blockTopN.Sun + blockTopE.Sun + blockTopM.Sun) / 4); sunBL = (1f / Chunk.MaxSunValue) * ((blockTopSW.Sun + blockTopS.Sun + blockTopW.Sun + blockTopM.Sun) / 4); sunBR = (1f / Chunk.MaxSunValue) * ((blockTopSE.Sun + blockTopS.Sun + blockTopE.Sun + blockTopM.Sun) / 4); redTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.R + blockTopN.R + blockTopW.R + blockTopM.R) / 4); redTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.R + blockTopN.R + blockTopE.R + blockTopM.R) / 4); redBL = (1f / Chunk.MaxSunValue) * ((blockTopSW.R + blockTopS.R + blockTopW.R + blockTopM.R) / 4); redBR = (1f / Chunk.MaxSunValue) * ((blockTopSE.R + blockTopS.R + blockTopE.R + blockTopM.R) / 4); grnTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.G + blockTopN.G + blockTopW.G + blockTopM.G) / 4); grnTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.G + blockTopN.G + blockTopE.G + blockTopM.G) / 4); grnBL = (1f / Chunk.MaxSunValue) * ((blockTopSW.G + blockTopS.G + blockTopW.G + blockTopM.G) / 4); grnBR = (1f / Chunk.MaxSunValue) * ((blockTopSE.G + blockTopS.G + blockTopE.G + blockTopM.G) / 4); bluTL = (1f / Chunk.MaxSunValue) * ((blockTopNW.B + blockTopN.B + blockTopW.B + blockTopM.B) / 4); bluTR = (1f / Chunk.MaxSunValue) * ((blockTopNE.B + blockTopN.B + blockTopE.B + blockTopM.B) / 4); bluBL = (1f / Chunk.MaxSunValue) * ((blockTopSW.B + blockTopS.B + blockTopW.B + blockTopM.B) / 4); bluBR = (1f / Chunk.MaxSunValue) * ((blockTopSE.B + blockTopS.B + blockTopE.B + blockTopM.B) / 4); localTL = new Color(redTL, grnTL, bluTL); localTR = new Color(redTR, grnTR, bluTR); localBL = new Color(redBL, grnBL, bluBL); localBR = new Color(redBR, grnBR, bluBR); BuildFaceVertices(chunk, worldPosition, block.Type, BlockFaceDirection.YIncreasing, sunTL, sunTR, sunBL, sunBR, localTL, localTR, localBL, localBR); } // -Z face. if (!blockMidS.Exists && !(block.Type == BlockType.Water && blockMidS.Type == BlockType.Water)) { sunTL = (1f / Chunk.MaxSunValue) * ((blockTopSW.Sun + blockTopS.Sun + blockMidSW.Sun + blockMidS.Sun) / 4); sunTR = (1f / Chunk.MaxSunValue) * ((blockTopSE.Sun + blockTopS.Sun + blockMidSE.Sun + blockMidS.Sun) / 4); sunBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.Sun + blockBotS.Sun + blockMidSW.Sun + blockMidS.Sun) / 4); sunBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.Sun + blockBotS.Sun + blockMidSE.Sun + blockMidS.Sun) / 4); redTL = (1f / Chunk.MaxSunValue) * ((blockTopSW.R + blockTopS.R + blockMidSW.R + blockMidS.R) / 4); redTR = (1f / Chunk.MaxSunValue) * ((blockTopSE.R + blockTopS.R + blockMidSE.R + blockMidS.R) / 4); redBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.R + blockBotS.R + blockMidSW.R + blockMidS.R) / 4); redBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.R + blockBotS.R + blockMidSE.R + blockMidS.R) / 4); grnTL = (1f / Chunk.MaxSunValue) * ((blockTopSW.G + blockTopS.G + blockMidSW.G + blockMidS.G) / 4); grnTR = (1f / Chunk.MaxSunValue) * ((blockTopSE.G + blockTopS.G + blockMidSE.G + blockMidS.G) / 4); grnBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.G + blockBotS.G + blockMidSW.G + blockMidS.G) / 4); grnBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.G + blockBotS.G + blockMidSE.G + blockMidS.G) / 4); bluTL = (1f / Chunk.MaxSunValue) * ((blockTopSW.B + blockTopS.B + blockMidSW.B + blockMidS.B) / 4); bluTR = (1f / Chunk.MaxSunValue) * ((blockTopSE.B + blockTopS.B + blockMidSE.B + blockMidS.B) / 4); bluBL = (1f / Chunk.MaxSunValue) * ((blockBotSW.B + blockBotS.B + blockMidSW.B + blockMidS.B) / 4); bluBR = (1f / Chunk.MaxSunValue) * ((blockBotSE.B + blockBotS.B + blockMidSE.B + blockMidS.B) / 4); localTL = new Color(redTL, grnTL, bluTL); localTR = new Color(redTR, grnTR, bluTR); localBL = new Color(redBL, grnBL, bluBL); localBR = new Color(redBR, grnBR, bluBR); BuildFaceVertices(chunk, worldPosition, block.Type, BlockFaceDirection.ZDecreasing, sunTL, sunTR, sunBL, sunBR, localTL, localTR, localBL, localBR); } // +Z face. if (!blockMidN.Exists && !(block.Type == BlockType.Water && blockMidN.Type == BlockType.Water)) { sunTL = (1f / Chunk.MaxSunValue) * ((blockTopNE.Sun + blockTopN.Sun + blockMidNE.Sun + blockMidN.Sun) / 4); sunTR = (1f / Chunk.MaxSunValue) * ((blockTopNW.Sun + blockTopN.Sun + blockMidNW.Sun + blockMidN.Sun) / 4); sunBL = (1f / Chunk.MaxSunValue) * ((blockBotNE.Sun + blockBotN.Sun + blockMidNE.Sun + blockMidN.Sun) / 4); sunBR = (1f / Chunk.MaxSunValue) * ((blockBotNW.Sun + blockBotN.Sun + blockMidNW.Sun + blockMidN.Sun) / 4); redTL = (1f / Chunk.MaxSunValue) * ((blockTopNE.R + blockTopN.R + blockMidNE.R + blockMidN.R) / 4); redTR = (1f / Chunk.MaxSunValue) * ((blockTopNW.R + blockTopN.R + blockMidNW.R + blockMidN.R) / 4); redBL = (1f / Chunk.MaxSunValue) * ((blockBotNE.R + blockBotN.R + blockMidNE.R + blockMidN.R) / 4); redBR = (1f / Chunk.MaxSunValue) * ((blockBotNW.R + blockBotN.R + blockMidNW.R + blockMidN.R) / 4); grnTL = (1f / Chunk.MaxSunValue) * ((blockTopNE.G + blockTopN.G + blockMidNE.G + blockMidN.G) / 4); grnTR = (1f / Chunk.MaxSunValue) * ((blockTopNW.G + blockTopN.G + blockMidNW.G + blockMidN.G) / 4); grnBL = (1f / Chunk.MaxSunValue) * ((blockBotNE.G + blockBotN.G + blockMidNE.G + blockMidN.G) / 4); grnBR = (1f / Chunk.MaxSunValue) * ((blockBotNW.G + blockBotN.G + blockMidNW.G + blockMidN.G) / 4); bluTL = (1f / Chunk.MaxSunValue) * ((blockTopNE.B + blockTopN.B + blockMidNE.B + blockMidN.B) / 4); bluTR = (1f / Chunk.MaxSunValue) * ((blockTopNW.B + blockTopN.B + blockMidNW.B + blockMidN.B) / 4); bluBL = (1f / Chunk.MaxSunValue) * ((blockBotNE.B + blockBotN.B + blockMidNE.B + blockMidN.B) / 4); bluBR = (1f / Chunk.MaxSunValue) * ((blockBotNW.B + blockBotN.B + blockMidNW.B + blockMidN.B) / 4); localTL = new Color(redTL, grnTL, bluTL); localTR = new Color(redTR, grnTR, bluTR); localBL = new Color(redBL, grnBL, bluBL); localBR = new Color(redBR, grnBR, bluBR); BuildFaceVertices(chunk, worldPosition, block.Type, BlockFaceDirection.ZIncreasing, sunTL, sunTR, sunBL, sunBR, localTL, localTR, localBL, localBR); } }
/// <summary> /// Returns the block at given wolrd coordinate. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public Block BlockAt(int x, int y, int z) { return(BlockStorage.BlockAt(this.WorldPosition.X + x, y, this.WorldPosition.Z + z)); }