@@ -589,9 +589,9 @@ void Renderer::resize(int width, int height)
589589
590590float Renderer::calcPixelSize (float fovY, float windowHeight)
591591{
592- if (getProjectionMode () == ProjectionMode::FisheyeMode)
593- return 2 .0f / windowHeight;
594- return 2 * ( float ) tan (degToRad (fovY / 2.0 )) / ( float ) windowHeight;
592+ return (getProjectionMode () == ProjectionMode::FisheyeMode)
593+ ? 2 .0f / windowHeight
594+ : 2 . 0f * tan (degToRad (fovY * 0 . 5f )) / static_cast < float >( windowHeight) ;
595595}
596596
597597void Renderer::setFieldOfView (float _fov)
@@ -1544,11 +1544,7 @@ void Renderer::draw(const Observer& observer,
15441544
15451545 // Set up the projection and modelview matrices.
15461546 // We'll usethem for positioning star and planet labels.
1547- float aspectRatio = getAspectRatio ();
1548- if (getProjectionMode () == Renderer::ProjectionMode::FisheyeMode)
1549- m_projMatrix = Ortho (-aspectRatio, aspectRatio, -1 .0f , 1 .0f , NEAR_DIST, FAR_DIST);
1550- else
1551- m_projMatrix = Perspective (fov, aspectRatio, NEAR_DIST, FAR_DIST);
1547+ buildProjectionMatrix (m_projMatrix, NEAR_DIST, FAR_DIST);
15521548 m_modelMatrix = Affine3f (getCameraOrientation ()).matrix ();
15531549 m_MVPMatrix = m_projMatrix * m_modelMatrix;
15541550
@@ -4049,7 +4045,7 @@ void Renderer::renderSkyGrids(const Observer& observer)
40494045 }
40504046
40514047 if ((renderFlags & ShowEcliptic) != 0 )
4052- renderEclipticLine ();
4048+ m_eclipticLineRenderer-> render ();
40534049}
40544050
40554051void Renderer::labelConstellations (const AsterismList& asterisms,
@@ -5309,18 +5305,14 @@ Renderer::renderSolarSystemObjects(const Observer &observer,
53095305
53105306 // Set up a perspective projection using the current interval's near and
53115307 // far clip planes.
5312- float aspectRatio = getAspectRatio ();
53135308 Matrix4f proj;
5314- if (getProjectionMode () == Renderer::ProjectionMode::FisheyeMode)
5315- proj = Ortho (-aspectRatio, aspectRatio, -1 .0f , 1 .0f , nearPlaneDistance, farPlaneDistance);
5316- else
5317- proj = Perspective (fov, aspectRatio, nearPlaneDistance, farPlaneDistance);
5309+ buildProjectionMatrix (proj, nearPlaneDistance, farPlaneDistance);
53185310 Matrices m = { &proj, &m_modelMatrix };
53195311
53205312 setCurrentProjectionMatrix (proj);
53215313
53225314 Frustum intervalFrustum (degToRad (fov),
5323- aspectRatio ,
5315+ getAspectRatio () ,
53245316 nearPlaneDistance,
53255317 farPlaneDistance);
53265318
@@ -5446,8 +5438,10 @@ Renderer::setPipelineState(const Renderer::PipelineState &ps) noexcept
54465438 }
54475439}
54485440
5449- void Renderer::renderEclipticLine ( )
5441+ void Renderer::buildProjectionMatrix (Eigen::Matrix4f &mat, float nearZ, float farZ )
54505442{
5451- if ((renderFlags & ShowEcliptic) != 0 )
5452- m_eclipticLineRenderer->render ();
5443+ float aspectRatio = getAspectRatio ();
5444+ mat = (getProjectionMode () == Renderer::ProjectionMode::FisheyeMode)
5445+ ? celmath::Ortho (-aspectRatio, aspectRatio, -1 .0f , 1 .0f , nearZ, farZ)
5446+ : celmath::Perspective (fov, aspectRatio, nearZ, farZ);
54535447}
0 commit comments