Skip to content

Commit

Permalink
Camera::HFOV override for Ogre and Ogre2 (#636)
Browse files Browse the repository at this point in the history
* camera HFOV override and add camera HFOV tests

Signed-off-by: youhy <[email protected]>

Co-authored-by: Ian Chen <[email protected]>
  • Loading branch information
AzulRadio and iche033 authored Jun 1, 2022
1 parent 830c051 commit a3dc1ae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ogre/include/ignition/rendering/ogre/OgreCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace ignition

public: virtual ~OgreCamera();

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

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

Expand Down
8 changes: 8 additions & 0 deletions ogre/src/OgreCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ void OgreCamera::Destroy()
}
}

//////////////////////////////////////////////////
math::Angle OgreCamera::HFOV() const
{
double vfov = this->ogreCamera->getFOVy().valueRadians();
double hFOV = 2.0 * atan(tan(vfov / 2.0) * this->AspectRatio());
return math::Angle(hFOV);
}

//////////////////////////////////////////////////
void OgreCamera::SetHFOV(const math::Angle &_angle)
{
Expand Down
3 changes: 3 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ namespace ignition
/// \brief Destructor
public: virtual ~Ogre2Camera();

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

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

Expand Down
8 changes: 8 additions & 0 deletions ogre2/src/Ogre2Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ void Ogre2Camera::Destroy()
}
}

//////////////////////////////////////////////////
math::Angle Ogre2Camera::HFOV() const
{
double vfov = this->ogreCamera->getFOVy().valueRadians();
double hFOV = 2.0 * atan(tan(vfov / 2.0) * this->AspectRatio());
return math::Angle(hFOV);
}

//////////////////////////////////////////////////
void Ogre2Camera::SetHFOV(const math::Angle &_angle)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Camera_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void CameraTest::ViewProjectionMatrix(const std::string &_renderEngine)
EXPECT_GT(camera->HFOV(), 0);
math::Angle hfov(1.57);
camera->SetHFOV(hfov);
EXPECT_DOUBLE_EQ(hfov.Radian(), camera->HFOV().Radian());
EXPECT_NEAR(hfov.Radian(), camera->HFOV().Radian(), 1e-6);

EXPECT_GT(camera->AspectRatio(), 0);
camera->SetAspectRatio(1.7777);
Expand Down

0 comments on commit a3dc1ae

Please sign in to comment.