summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorBen Deutsch <ben@bendeutsch.de>2017-05-07 18:41:47 +0200
committerSmallJoker <mk939@ymail.com>2017-07-05 15:39:49 +0200
commit6bedb6de408d531c1843888edc6576040c368695 (patch)
tree1415a26e8f4f97121687f9ef8b7f21590ea88f8e /src/game.cpp
parent61a3de42fd9c7c24c06ba8522e4240d4f5e3a04f (diff)
downloadminetest-6bedb6de408d531c1843888edc6576040c368695.tar.gz
minetest-6bedb6de408d531c1843888edc6576040c368695.tar.bz2
minetest-6bedb6de408d531c1843888edc6576040c368695.zip
Fog effect when camera is inside cloud
Fixes issue #3576 * Clouds now take camera position as 3D, not 2D * Cloud grid filling extracted to gridFilled method * Clouds detect whether camera is inside cloud * Camera in cloud changes fog by overriding sky colors with cloud color * Sun, moon and stars can be temporarily disabled with setBodiesVisible * Disabling fog also disables all "inside cloud" behaviors
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 9f7b0ca52..b6304f19e 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -4104,12 +4104,29 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
Update clouds
*/
if (clouds) {
- v3f player_position = player->getPosition();
if (sky->getCloudsVisible()) {
clouds->setVisible(true);
clouds->step(dtime);
- clouds->update(v2f(player_position.X, player_position.Z),
- sky->getCloudColor());
+ // camera->getPosition is not enough for 3rd person views
+ v3f camera_node_position = camera->getCameraNode()->getPosition();
+ v3s16 camera_offset = camera->getOffset();
+ camera_node_position.X = camera_node_position.X + camera_offset.X * BS;
+ camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS;
+ camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS;
+ clouds->update(camera_node_position,
+ sky->getCloudColor());
+ if (clouds->isCameraInsideCloud() && m_cache_enable_fog &&
+ !flags.force_fog_off) {
+ // if inside clouds, and fog enabled, use that as sky
+ // color(s)
+ video::SColor clouds_dark = clouds->getColor()
+ .getInterpolated(video::SColor(255, 0, 0, 0), 0.9);
+ sky->overrideColors(clouds_dark, clouds->getColor());
+ sky->setBodiesVisible(false);
+ runData.fog_range = 20.0f * BS;
+ // do not draw clouds after all
+ clouds->setVisible(false);
+ }
} else {
clouds->setVisible(false);
}
@@ -4221,7 +4238,6 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
/*
Drawing begins
*/
-
const video::SColor &skycolor = sky->getSkyColor();
TimeTaker tt_draw("mainloop: draw");