Fix distorted Sun, Moon and Star visuals based on Orbit Tilt (#15459)

This commit is contained in:
veprogames 2024-12-06 22:00:06 +01:00 committed by GitHub
parent 5a8412dd23
commit b857798848
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -661,7 +661,9 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day)
return;
m_materials[0].ColorParam = color.toSColor();
auto sky_rotation = core::matrix4().setRotationAxisRadians(2.0f * M_PI * (wicked_time_of_day - 0.25f), v3f(0.0f, 0.0f, 1.0f));
auto day_rotation = core::matrix4().setRotationAxisRadians(2.0f * M_PI * (wicked_time_of_day - 0.25f), v3f(0.0f, 0.0f, 1.0f));
auto orbit_rotation = core::matrix4().setRotationAxisRadians(m_sky_params.body_orbit_tilt * M_PI / 180.0, v3f(1.0f, 0.0f, 0.0f));
auto sky_rotation = orbit_rotation * day_rotation;
auto world_matrix = driver->getTransform(video::ETS_WORLD);
driver->setTransform(video::ETS_WORLD, world_matrix * sky_rotation);
driver->setMaterial(m_materials[0]);
@ -695,13 +697,11 @@ 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 = getSkyBodyPosition(horizon_position, day_position, m_sky_params.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 += centrum - untilted_centrum;
vertex.Pos.rotateYZBy(m_sky_params.body_orbit_tilt);
}
}