]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/sky.cpp
Remove unused ITextSceneNode header (#11476)
[dragonfireclient.git] / src / client / sky.cpp
index 44c8f157499ad40474b84061c67d29877d152133..1cf9a4afca3b43cc442582d435e62f9bd4604905 100644 (file)
@@ -53,10 +53,12 @@ static video::SMaterial baseMaterial()
        return mat;
 };
 
-Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
-               scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
-                       RenderingEngine::get_scene_manager(), id)
+Sky::Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShaderSource *ssrc) :
+               scene::ISceneNode(rendering_engine->get_scene_manager()->getRootSceneNode(),
+                       rendering_engine->get_scene_manager(), id)
 {
+       m_seed = (u64)myrand() << 32 | myrand();
+
        setAutomaticCulling(scene::EAC_OFF);
        m_box.MaxEdge.set(0, 0, 0);
        m_box.MinEdge.set(0, 0, 0);
@@ -120,7 +122,14 @@ Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
                m_materials[i].Lighting = true;
                m_materials[i].MaterialType = video::EMT_SOLID;
        }
+
        m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
+
+       if (g_settings->getBool("enable_dynamic_shadows")) {
+               float val = g_settings->getFloat("shadow_sky_body_orbit_tilt");
+               m_sky_body_orbit_tilt = rangelim(val, 0.0f, 60.0f);
+       }
+
        setStarCount(1000, true);
 }
 
@@ -173,17 +182,7 @@ void Sky::render()
                video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
                video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
 
-               float nightlength = 0.415;
-               float wn = nightlength / 2;
-               float wicked_time_of_day = 0;
-               if (m_time_of_day > wn && m_time_of_day < 1.0 - wn)
-                       wicked_time_of_day = (m_time_of_day - wn) / (1.0 - wn * 2) * 0.5 + 0.25;
-               else if (m_time_of_day < 0.5)
-                       wicked_time_of_day = m_time_of_day / wn * 0.25;
-               else
-                       wicked_time_of_day = 1.0 - ((1.0 - m_time_of_day) / wn * 0.25);
-               /*std::cerr<<"time_of_day="<<m_time_of_day<<" -> "
-                               <<"wicked_time_of_day="<<wicked_time_of_day<<std::endl;*/
+               float wicked_time_of_day = getWickedTimeOfDay(m_time_of_day);
 
                video::SColor suncolor = suncolor_f.toSColor();
                video::SColor suncolor2 = suncolor2_f.toSColor();
@@ -737,10 +736,15 @@ void Sky::place_sky_body(
        * day_position: turn the body around the Z axis, to place it depending of the time of the day
        */
 {
+       v3f centrum(0, 0, -1);
+       centrum.rotateXZBy(horizon_position);
+       centrum.rotateXYBy(day_position);
+       centrum.rotateYZBy(m_sky_body_orbit_tilt);
        for (video::S3DVertex &vertex : vertices) {
                // Body is directed to -Z (south) by default
                vertex.Pos.rotateXZBy(horizon_position);
                vertex.Pos.rotateXYBy(day_position);
+               vertex.Pos.Z += centrum.Z;
        }
 }
 
@@ -833,7 +837,6 @@ void Sky::setStarCount(u16 star_count, bool force_update)
        // Allow force updating star count at game init.
        if (m_star_params.count != star_count || force_update) {
                m_star_params.count = star_count;
-               m_seed = (u64)myrand() << 32 | myrand();
                updateStars();
        }
 }
@@ -930,3 +933,17 @@ void Sky::setSkyDefaults()
        m_moon_params = sky_defaults.getMoonDefaults();
        m_star_params = sky_defaults.getStarDefaults();
 }
+
+float getWickedTimeOfDay(float time_of_day)
+{
+       float nightlength = 0.415f;
+       float wn = nightlength / 2;
+       float wicked_time_of_day = 0;
+       if (time_of_day > wn && time_of_day < 1.0f - wn)
+               wicked_time_of_day = (time_of_day - wn) / (1.0f - wn * 2) * 0.5f + 0.25f;
+       else if (time_of_day < 0.5f)
+               wicked_time_of_day = time_of_day / wn * 0.25f;
+       else
+               wicked_time_of_day = 1.0f - ((1.0f - time_of_day) / wn * 0.25f);
+       return wicked_time_of_day;
+}