Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--[BE Week] Update projection matrix near/far plane calcs #2276

Merged
merged 4 commits into from
Dec 6, 2023

Conversation

jturner65
Copy link
Contributor

Motivation and Context

This PR fixes or updates a few things related to the near/far plane calculation for projection matrices :

  • The manual calculations in sim have been replaced with recently implemented Magnum calls
  • The projection matrix far plane calculation for the RenderCamera::unproject function now not only calls the Magnum function, but also picks the correct calculation based on the nature of the Projection matrix, using the element at mat[3][3] to determine whether the matrix is perspective or orthographic.
  • Some minor cleanup in Viewer.cpp

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Dec 6, 2023
@jturner65 jturner65 requested a review from 0mdc December 6, 2023 15:18
Copy link
Collaborator

@mosra mosra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the unnecessary autos (I'm old and they make reading the code harder for me, not easier), this looks fine to me! :)

auto farDistance =
projectionMatrix()[3][2] / (1.0f + projectionMatrix()[2][2]);
// If projMat[3][3] == 0 then perpsective, otherwise ortho
auto farDistance = (projMat[3][3] == 0 ? projMat.perspectiveProjectionFar()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Annoying mode enabled)

Suggested change
auto farDistance = (projMat[3][3] == 0 ? projMat.perspectiveProjectionFar()
const float farDistance = (projMat[3][3] == 0 ? projMat.perspectiveProjectionFar()

@@ -207,10 +207,12 @@ esp::geo::Ray RenderCamera::unproject(const Mn::Vector2i& viewportPosition,
2 * Magnum::Vector2{viewPos} / Magnum::Vector2{viewport()} -
Magnum::Vector2{1.0f},
1.0};
const auto projMat = projectionMatrix();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const auto projMat = projectionMatrix();
const Mn::Matrix4 projMat = projectionMatrix();

Copy link
Contributor

@0mdc 0mdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!


// compute the far plane distance
auto farDistance =
projectionMatrix()[3][2] / (1.0f + projectionMatrix()[2][2]);
// If projMat[3][3] == 0 then perpsective, otherwise ortho
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: perpsective

@jturner65 jturner65 merged commit bb6ea83 into main Dec 6, 2023
10 checks passed
@jturner65 jturner65 deleted the Bugfix_ProjMatrix branch December 6, 2023 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants