Skip to content

Commit

Permalink
Fix wrong Z check in OgreWideAngleCamera::Project3d (#746)
Browse files Browse the repository at this point in the history
The matrix returned by Ogre::Camera::getProjectionMatrix has Z in range
[-1; 1], not range [0; 1]

This means we can't do pos.z > 0. We must do pos.z / pos.w > -1
Additionally, we must check against against z < 1; otherwise the point
may get picked by the wrong face (and fail tests).

Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
  • Loading branch information
darksylinc committed Oct 30, 2022
1 parent b197260 commit fcd52be
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ogre/src/OgreWideAngleCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,11 @@ math::Vector3d OgreWideAngleCamera::Project3d(
auto pos = viewProj * Ogre::Vector4(OgreConversions::Convert(_pt));
pos.x /= pos.w;
pos.y /= pos.w;
// check if point is visible
if (std::fabs(pos.x) <= 1 && std::fabs(pos.y) <= 1 && pos.z > 0)
// check if point is visible.
// pos.z is in range [-w; w] so we check if it's > -w then
// it means it's in front of us.
if (std::fabs(pos.x) <= 1 && std::fabs(pos.y) <= 1 &&
pos.z > -std::fabs(pos.w))
{
// determine dir vector to projected point from env camera
// work in y up, z forward, x right clip space
Expand Down

0 comments on commit fcd52be

Please sign in to comment.