Skip to content

Commit

Permalink
Ogre2: add overrides for hfov and aspect ratio updates
Browse files Browse the repository at this point in the history
- Ensure that the cameras update correctly when changing hfov or aspect ratio.
- Behaviour now consistent with the Ogre2Camera.

Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring committed Jan 15, 2025
1 parent a63edc9 commit 7ad1b5c
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2BoundingBoxCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ namespace gz
/// the ogre id which appears in the map.
public: void MarkVisibleBoxes();

// Documentation inherited.
public: virtual math::Angle HFOV() const override;

// Documentation inherited.
public: virtual void SetHFOV(const math::Angle &_hfov) override;

// Documentation inherited.
public: virtual double AspectRatio() const override;

// Documentation inherited.
public: virtual void SetAspectRatio(const double _ratio) override;

/// \brief Synchronizes every setting that depends on AspectRatio
/// with Ogre's camera
protected: void SyncOgreCameraAspectRatio();

/// \brief Get a pointer to the render target.
/// \return Pointer to the render target
protected: virtual RenderTargetPtr RenderTarget() const override;
Expand Down
16 changes: 16 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2DepthCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ namespace gz
/// \brief Implementation of the render call
public: virtual void Render() override;

// Documentation inherited.
public: virtual math::Angle HFOV() const override;

// Documentation inherited.
public: virtual void SetHFOV(const math::Angle &_hfov) override;

// Documentation inherited.
public: virtual double AspectRatio() const override;

// Documentation inherited.
public: virtual void SetAspectRatio(const double _ratio) override;

/// \brief Set the far clip distance
/// \param[in] _far far clip distance
public: virtual void SetFarClipPlane(const double _far) override;
Expand Down Expand Up @@ -143,6 +155,10 @@ namespace gz
/// \return valid field of view
protected: static double LimitFOV(const double _fov);

/// \brief Synchronizes every setting that depends on AspectRatio
/// with Ogre's camera
protected: void SyncOgreCameraAspectRatio();

/// \brief Create the camera.
protected: void CreateCamera();

Expand Down
16 changes: 16 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2SegmentationCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ namespace gz
// Documentation inherited.
public: virtual Ogre::Camera *OgreCamera() const override;

// Documentation inherited.
public: virtual math::Angle HFOV() const override;

// Documentation inherited.
public: virtual void SetHFOV(const math::Angle &_hfov) override;

// Documentation inherited.
public: virtual double AspectRatio() const override;

// Documentation inherited.
public: virtual void SetAspectRatio(const double _ratio) override;

/// \brief Synchronizes every setting that depends on AspectRatio
/// with Ogre's camera
protected: void SyncOgreCameraAspectRatio();

/// \brief Create the camera.
protected: void CreateCamera();

Expand Down
16 changes: 16 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2ThermalCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ namespace gz
// Documentation inherited.
public: virtual Ogre::Camera *OgreCamera() const override;

// Documentation inherited.
public: virtual math::Angle HFOV() const override;

// Documentation inherited.
public: virtual void SetHFOV(const math::Angle &_hfov) override;

// Documentation inherited.
public: virtual double AspectRatio() const override;

// Documentation inherited.
public: virtual void SetAspectRatio(const double _ratio) override;

/// \brief Synchronizes every setting that depends on AspectRatio
/// with Ogre's camera
protected: void SyncOgreCameraAspectRatio();

/// \brief Get a pointer to the render target.
/// \return Pointer to the render target
protected: virtual RenderTargetPtr RenderTarget() const override;
Expand Down
36 changes: 36 additions & 0 deletions ogre2/src/Ogre2BoundingBoxCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1533,3 +1533,39 @@ BoundingBoxType Ogre2BoundingBoxCamera::Type() const
{
return this->dataPtr->type;
}

//////////////////////////////////////////////////
math::Angle Ogre2BoundingBoxCamera::HFOV() const
{
return BaseCamera::HFOV();
}

//////////////////////////////////////////////////
void Ogre2BoundingBoxCamera::SetHFOV(const math::Angle &_angle)
{
BaseCamera::SetHFOV(_angle);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
double Ogre2BoundingBoxCamera::AspectRatio() const
{
return BaseCamera::AspectRatio();
}

//////////////////////////////////////////////////
void Ogre2BoundingBoxCamera::SetAspectRatio(const double _ratio)
{
BaseCamera::SetAspectRatio(_ratio);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
void Ogre2BoundingBoxCamera::SyncOgreCameraAspectRatio()
{
const double aspectRatio = this->AspectRatio();
const double angle = this->HFOV().Radian();
const double vfov = 2.0 * atan(tan(angle / 2.0) / aspectRatio);
this->dataPtr->ogreCamera->setFOVy(Ogre::Radian((Ogre::Real)vfov));
this->dataPtr->ogreCamera->setAspectRatio((Ogre::Real)aspectRatio);
}
36 changes: 36 additions & 0 deletions ogre2/src/Ogre2DepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,42 @@ RenderTargetPtr Ogre2DepthCamera::RenderTarget() const
return this->dataPtr->depthTexture;
}

//////////////////////////////////////////////////
math::Angle Ogre2DepthCamera::HFOV() const
{
return BaseCamera::HFOV();
}

//////////////////////////////////////////////////
void Ogre2DepthCamera::SetHFOV(const math::Angle &_angle)
{
BaseCamera::SetHFOV(_angle);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
double Ogre2DepthCamera::AspectRatio() const
{
return BaseCamera::AspectRatio();
}

//////////////////////////////////////////////////
void Ogre2DepthCamera::SetAspectRatio(const double _ratio)
{
BaseCamera::SetAspectRatio(_ratio);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
void Ogre2DepthCamera::SyncOgreCameraAspectRatio()
{
const double aspectRatio = this->AspectRatio();
const double angle = this->HFOV().Radian();
const double vfov = 2.0 * atan(tan(angle / 2.0) / aspectRatio);
this->ogreCamera->setFOVy(Ogre::Radian((Ogre::Real)vfov));
this->ogreCamera->setAspectRatio((Ogre::Real)aspectRatio);
}

//////////////////////////////////////////////////
double Ogre2DepthCamera::LimitFOV(const double _fov)
{
Expand Down
36 changes: 36 additions & 0 deletions ogre2/src/Ogre2SegmentationCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,39 @@ Ogre::Camera *Ogre2SegmentationCamera::OgreCamera() const
{
return this->ogreCamera;
}

//////////////////////////////////////////////////
math::Angle Ogre2SegmentationCamera::HFOV() const
{
return BaseCamera::HFOV();
}

//////////////////////////////////////////////////
void Ogre2SegmentationCamera::SetHFOV(const math::Angle &_angle)
{
BaseCamera::SetHFOV(_angle);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
double Ogre2SegmentationCamera::AspectRatio() const
{
return BaseCamera::AspectRatio();
}

//////////////////////////////////////////////////
void Ogre2SegmentationCamera::SetAspectRatio(const double _ratio)
{
BaseCamera::SetAspectRatio(_ratio);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
void Ogre2SegmentationCamera::SyncOgreCameraAspectRatio()
{
const double aspectRatio = this->AspectRatio();
const double angle = this->HFOV().Radian();
const double vfov = 2.0 * atan(tan(angle / 2.0) / aspectRatio);
this->ogreCamera->setFOVy(Ogre::Radian((Ogre::Real)vfov));
this->ogreCamera->setAspectRatio((Ogre::Real)aspectRatio);
}
36 changes: 36 additions & 0 deletions ogre2/src/Ogre2ThermalCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1219,3 +1219,39 @@ Ogre::Camera *Ogre2ThermalCamera::OgreCamera() const
{
return this->ogreCamera;
}

//////////////////////////////////////////////////
math::Angle Ogre2ThermalCamera::HFOV() const
{
return BaseCamera::HFOV();
}

//////////////////////////////////////////////////
void Ogre2ThermalCamera::SetHFOV(const math::Angle &_angle)
{
BaseCamera::SetHFOV(_angle);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
double Ogre2ThermalCamera::AspectRatio() const
{
return BaseCamera::AspectRatio();
}

//////////////////////////////////////////////////
void Ogre2ThermalCamera::SetAspectRatio(const double _ratio)
{
BaseCamera::SetAspectRatio(_ratio);
this->SyncOgreCameraAspectRatio();
}

//////////////////////////////////////////////////
void Ogre2ThermalCamera::SyncOgreCameraAspectRatio()
{
const double aspectRatio = this->AspectRatio();
const double angle = this->HFOV().Radian();
const double vfov = 2.0 * atan(tan(angle / 2.0) / aspectRatio);
this->ogreCamera->setFOVy(Ogre::Radian((Ogre::Real)vfov));
this->ogreCamera->setAspectRatio((Ogre::Real)aspectRatio);
}

0 comments on commit 7ad1b5c

Please sign in to comment.