Skip to content

Commit

Permalink
Fix crash when wide angle camera FOV is > 180 (#1016)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Jul 22, 2024
1 parent a7cf4f0 commit 3335d59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ogre/src/OgreWideAngleCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,11 @@ void OgreWideAngleCamera::CreateWideAngleTexture()

double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / ratio);
this->dataPtr->ogreCamera->setAspectRatio(ratio);
this->dataPtr->ogreCamera->setFOVy(Ogre::Radian(vfov));
// Setting the fov is likely not necessary for the ogreCamera but
// clamp to max fov supported by ogre to avoid issues with building the
// frustum
this->dataPtr->ogreCamera->setFOVy(Ogre::Radian(
Ogre::Real(std::clamp(vfov, 0.0, GZ_PI))));

// create the env cameras and textures
this->CreateEnvCameras();
Expand Down
7 changes: 6 additions & 1 deletion ogre2/src/Ogre2WideAngleCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,12 @@ void Ogre2WideAngleCamera::PrepareForFinalPass(Ogre::Pass *_pass)
const double ratio = static_cast<double>(this->ImageWidth()) /
static_cast<double>(this->ImageHeight());
const double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / ratio);
this->dataPtr->ogreCamera->setFOVy(Ogre::Radian(Ogre::Real(vfov)));

// Setting the fov is likely not necessary in the final pass but
// clamp to max fov supported by ogre to avoid issues with building the
// frustum
this->dataPtr->ogreCamera->setFOVy(Ogre::Radian(
Ogre::Real(std::clamp(vfov, 0.0, GZ_PI))));

const float localHfov = static_cast<float>(this->HFOV().Radian());

Expand Down

0 comments on commit 3335d59

Please sign in to comment.