From 8b09f6f4eccf72e0604ef912a3f18cdf08dd2d5d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 Feb 2015 14:02:04 +0100 Subject: Handle lighting and depth --- src/World/Block.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/World/Block.cpp (limited to 'src/World/Block.cpp') diff --git a/src/World/Block.cpp b/src/World/Block.cpp new file mode 100644 index 0000000..3aa4af3 --- /dev/null +++ b/src/World/Block.cpp @@ -0,0 +1,57 @@ +/* + Copyright (c) 2015, Matthias Schiffer + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "Block.hpp" +#include "BlockType.hpp" + + +namespace MinedMap { +namespace World { + +uint32_t Block::getColor() const { + const World::BlockType &t = World::BLOCK_TYPES[id]; + + if (!t.opaque) + return 0; + + uint8_t r = t.color >> 16; + uint8_t g = t.color >> 8; + uint8_t b = t.color; + + uint8_t light = (blockLight > skyLight) ? blockLight : skyLight; + + float lightCoef = light/30.0f + 0.5f; + float heightCoef = height/255.0f + 0.5f; + + r *= lightCoef * heightCoef; + g *= lightCoef * heightCoef; + b *= lightCoef * heightCoef; + + return (r << 24) | (g << 16) | (b << 8) | 0xff; +} + +} +} -- cgit v1.2.3