Merge pull request #1593 from immibis/fix-squashed-planets

Fix squashed planets when window isn't 4:3
dev
Tomasz Kapuściński 2023-07-03 20:45:13 +02:00 committed by GitHub
commit 172e1fbff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -101,6 +101,9 @@ void CPlanet::Draw()
Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
float dp = 0.5f/256.0f;
Math::IntPoint windowSize = m_engine->GetWindowSize();
float inverseAspectRatio = static_cast<float>(windowSize.y) / static_cast<float>(windowSize.x);
for (const auto& planet : m_planets)
{
if (planet.type != m_visibleType)
@ -129,9 +132,14 @@ void CPlanet::Draw()
a = eyeDirV + planet.angle.y;
p1.y = 0.4f+(Math::Mod(a+Math::PI, Math::PI*2.0f)-Math::PI)*(2.0f/Math::PI);
p1.x -= planet.dim/2.0f*0.75f;
// planet.dim is what percentage of the screen height the planet takes up (e.g. 0.333 = 1/3 of screen height)
// and then the width is calculated to make it square. (0.333 = 1/4 of screen width assuming 4:3)
// This matches the behaviour of the 3D scene - the vertical FOV is fixed, and the horizontal FOV changes
// to match the aspect ratio.
p1.x -= planet.dim/2.0f*inverseAspectRatio;
p1.y -= planet.dim/2.0f;
p2.x = p1.x+planet.dim*0.75f;
p2.x = p1.x+planet.dim*inverseAspectRatio;
p2.y = p1.y+planet.dim;
float u1 = planet.uv1.x + dp;