1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Use Sky class to obtain directional light source position for shadows (#12662)

* Also remove unused Sky::getSkyBodyOrbitTilt method

Fixes misalignment of sun position and shadow direction at high tilt values.
This commit is contained in:
x2048 2022-08-17 16:30:05 +02:00 committed by GitHub
parent 3f67215df9
commit 8c29c4f620
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 11 deletions

View file

@ -554,6 +554,25 @@ void Sky::update(float time_of_day, float time_brightness,
}
}
static v3f getSkyBodyPosition(float horizon_position, float day_position, float orbit_tilt)
{
v3f result = v3f(0, 0, -1);
result.rotateXZBy(horizon_position);
result.rotateXYBy(day_position);
result.rotateYZBy(orbit_tilt);
return result;
}
v3f Sky::getSunDirection()
{
return getSkyBodyPosition(90, getWickedTimeOfDay(m_time_of_day) * 360 - 90, m_sky_body_orbit_tilt);
}
v3f Sky::getMoonDirection()
{
return getSkyBodyPosition(270, getWickedTimeOfDay(m_time_of_day) * 360 - 90, m_sky_body_orbit_tilt);
}
void Sky::draw_sun(video::IVideoDriver *driver, float sunsize, const video::SColor &suncolor,
const video::SColor &suncolor2, float wicked_time_of_day)
/* Draw sun in the sky.
@ -703,15 +722,13 @@ 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);
v3f centrum = getSkyBodyPosition(horizon_position, day_position, m_sky_body_orbit_tilt);
v3f untilted_centrum = getSkyBodyPosition(horizon_position, day_position, 0.f);
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;
vertex.Pos += centrum - untilted_centrum;
}
}