From df5d6d9b548dd9c2bbeeabf9c860f16bc92f33b3 Mon Sep 17 00:00:00 2001 From: youhy Date: Thu, 26 May 2022 11:26:11 -0700 Subject: [PATCH 01/11] change aspect to AspectRatio() Signed-off-by: youhy --- ogre/src/OgreCamera.cc | 2 +- ogre2/src/Ogre2Camera.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ogre/src/OgreCamera.cc b/ogre/src/OgreCamera.cc index 39a99c3f5..32eb8890c 100644 --- a/ogre/src/OgreCamera.cc +++ b/ogre/src/OgreCamera.cc @@ -71,7 +71,7 @@ void OgreCamera::SetHFOV(const math::Angle &_angle) { BaseCamera::SetHFOV(_angle); double angle = _angle.Radian(); - double vfov = 2.0 * atan(tan(angle / 2.0) / this->aspect); + double vfov = 2.0 * atan(tan(angle / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(vfov)); } diff --git a/ogre2/src/Ogre2Camera.cc b/ogre2/src/Ogre2Camera.cc index c259fff64..0b9272800 100644 --- a/ogre2/src/Ogre2Camera.cc +++ b/ogre2/src/Ogre2Camera.cc @@ -76,7 +76,7 @@ void Ogre2Camera::SetHFOV(const math::Angle &_angle) { BaseCamera::SetHFOV(_angle); double angle = _angle.Radian(); - double vfov = 2.0 * atan(tan(angle / 2.0) / this->aspect); + double vfov = 2.0 * atan(tan(angle / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(vfov)); } From a7cdf545320c99e380ea45984090448b5cacb70a Mon Sep 17 00:00:00 2001 From: youhy Date: Thu, 26 May 2022 12:10:19 -0700 Subject: [PATCH 02/11] thermal and depth cam aspect ratio, didnt test Signed-off-by: youhy --- ogre2/src/Ogre2DepthCamera.cc | 3 +-- ogre2/src/Ogre2ThermalCamera.cc | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ogre2/src/Ogre2DepthCamera.cc b/ogre2/src/Ogre2DepthCamera.cc index c949e2e29..30ed58cb9 100644 --- a/ogre2/src/Ogre2DepthCamera.cc +++ b/ogre2/src/Ogre2DepthCamera.cc @@ -418,8 +418,7 @@ void Ogre2DepthCamera::CreateRenderTexture() void Ogre2DepthCamera::CreateDepthTexture() { // set aspect ratio and fov - double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->aspect); - this->ogreCamera->setAspectRatio(this->aspect); + double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(this->LimitFOV(vfov))); // Load depth material diff --git a/ogre2/src/Ogre2ThermalCamera.cc b/ogre2/src/Ogre2ThermalCamera.cc index 5cb5a2d50..d5168850f 100644 --- a/ogre2/src/Ogre2ThermalCamera.cc +++ b/ogre2/src/Ogre2ThermalCamera.cc @@ -613,8 +613,7 @@ void Ogre2ThermalCamera::CreateRenderTexture() void Ogre2ThermalCamera::CreateThermalTexture() { // set aspect ratio and fov - double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->aspect); - this->ogreCamera->setAspectRatio(this->aspect); + double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(vfov)); // Load thermal material From 9723e19ae4153b756f8f1d01ada210ddd3e59325 Mon Sep 17 00:00:00 2001 From: youhy Date: Thu, 26 May 2022 12:10:38 -0700 Subject: [PATCH 03/11] add comment to aspect in BaseCamera Signed-off-by: youhy --- include/ignition/rendering/base/BaseCamera.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/include/ignition/rendering/base/BaseCamera.hh b/include/ignition/rendering/base/BaseCamera.hh index 9c57bfcd9..bd1abeaa6 100644 --- a/include/ignition/rendering/base/BaseCamera.hh +++ b/include/ignition/rendering/base/BaseCamera.hh @@ -217,6 +217,7 @@ namespace ignition protected: double farClip = 1000.0; /// \brief Aspect ratio + /// Do not use this variable. Use ApsectRatio() instead. protected: double aspect = 1.3333333; /// \brief Horizontal camera field of view From 2286b601b2dd8a3c57f905c0efa28945289eaa3d Mon Sep 17 00:00:00 2001 From: youhy Date: Thu, 26 May 2022 14:32:10 -0700 Subject: [PATCH 04/11] update aspect in SetHFOV Signed-off-by: youhy --- include/ignition/rendering/base/BaseCamera.hh | 1 - ogre/src/OgreCamera.cc | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/ignition/rendering/base/BaseCamera.hh b/include/ignition/rendering/base/BaseCamera.hh index bd1abeaa6..9c57bfcd9 100644 --- a/include/ignition/rendering/base/BaseCamera.hh +++ b/include/ignition/rendering/base/BaseCamera.hh @@ -217,7 +217,6 @@ namespace ignition protected: double farClip = 1000.0; /// \brief Aspect ratio - /// Do not use this variable. Use ApsectRatio() instead. protected: double aspect = 1.3333333; /// \brief Horizontal camera field of view diff --git a/ogre/src/OgreCamera.cc b/ogre/src/OgreCamera.cc index 32eb8890c..31de81f83 100644 --- a/ogre/src/OgreCamera.cc +++ b/ogre/src/OgreCamera.cc @@ -73,6 +73,8 @@ void OgreCamera::SetHFOV(const math::Angle &_angle) double angle = _angle.Radian(); double vfov = 2.0 * atan(tan(angle / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(vfov)); + // keep aspect in BaseCamera the same as aspect in Ogre lib + this->aspect = this->AspectRatio(); } ////////////////////////////////////////////////// From 8133de42ad77b9f1b0037dc583f9bd6ddd284b28 Mon Sep 17 00:00:00 2001 From: youhy Date: Thu, 26 May 2022 14:38:36 -0700 Subject: [PATCH 05/11] codecheck fix Signed-off-by: youhy --- ogre2/src/Ogre2DepthCamera.cc | 3 ++- ogre2/src/Ogre2ThermalCamera.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ogre2/src/Ogre2DepthCamera.cc b/ogre2/src/Ogre2DepthCamera.cc index 30ed58cb9..b2b67ea90 100644 --- a/ogre2/src/Ogre2DepthCamera.cc +++ b/ogre2/src/Ogre2DepthCamera.cc @@ -418,7 +418,8 @@ void Ogre2DepthCamera::CreateRenderTexture() void Ogre2DepthCamera::CreateDepthTexture() { // set aspect ratio and fov - double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->AspectRatio()); + double vfov; + vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(this->LimitFOV(vfov))); // Load depth material diff --git a/ogre2/src/Ogre2ThermalCamera.cc b/ogre2/src/Ogre2ThermalCamera.cc index d5168850f..d0e63b9ff 100644 --- a/ogre2/src/Ogre2ThermalCamera.cc +++ b/ogre2/src/Ogre2ThermalCamera.cc @@ -613,7 +613,8 @@ void Ogre2ThermalCamera::CreateRenderTexture() void Ogre2ThermalCamera::CreateThermalTexture() { // set aspect ratio and fov - double vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->AspectRatio()); + double vfov; + vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(vfov)); // Load thermal material From fbbbc4bd0d25a59a292cf20c1bd0042b51303d08 Mon Sep 17 00:00:00 2001 From: youhy Date: Tue, 31 May 2022 15:23:19 -0700 Subject: [PATCH 06/11] update aspect ratio after resizing Signed-off-by: youhy --- include/ignition/rendering/base/BaseCamera.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/ignition/rendering/base/BaseCamera.hh b/include/ignition/rendering/base/BaseCamera.hh index 9c57bfcd9..a78039b47 100644 --- a/include/ignition/rendering/base/BaseCamera.hh +++ b/include/ignition/rendering/base/BaseCamera.hh @@ -286,6 +286,7 @@ namespace ignition void BaseCamera::SetImageWidth(const unsigned int _width) { this->RenderTarget()->SetWidth(_width); + this->aspect = this->AspectRatio(); } ////////////////////////////////////////////////// @@ -300,6 +301,7 @@ namespace ignition void BaseCamera::SetImageHeight(const unsigned int _height) { this->RenderTarget()->SetHeight(_height); + this->aspect = this->AspectRatio(); } ////////////////////////////////////////////////// From 932053a25f4cd3c7d4c95301ca658fcb825e0184 Mon Sep 17 00:00:00 2001 From: youhy Date: Wed, 1 Jun 2022 09:41:31 -0700 Subject: [PATCH 07/11] remove change of aspect after changing HFOV Signed-off-by: youhy --- ogre/src/OgreCamera.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/ogre/src/OgreCamera.cc b/ogre/src/OgreCamera.cc index 31de81f83..32eb8890c 100644 --- a/ogre/src/OgreCamera.cc +++ b/ogre/src/OgreCamera.cc @@ -73,8 +73,6 @@ void OgreCamera::SetHFOV(const math::Angle &_angle) double angle = _angle.Radian(); double vfov = 2.0 * atan(tan(angle / 2.0) / this->AspectRatio()); this->ogreCamera->setFOVy(Ogre::Radian(vfov)); - // keep aspect in BaseCamera the same as aspect in Ogre lib - this->aspect = this->AspectRatio(); } ////////////////////////////////////////////////// From dcd59839dd281631c35e09cd0e687c68a6ef2bbd Mon Sep 17 00:00:00 2001 From: youhy Date: Fri, 3 Jun 2022 14:08:06 -0700 Subject: [PATCH 08/11] add aspect ratio for camera test Signed-off-by: youhy --- src/Camera_TEST.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Camera_TEST.cc b/src/Camera_TEST.cc index e6f497801..7da7bb725 100644 --- a/src/Camera_TEST.cc +++ b/src/Camera_TEST.cc @@ -178,6 +178,11 @@ void CameraTest::RenderTexture(const std::string &_renderEngine) camera->SetImageHeight(80u); EXPECT_EQ(80u, camera->ImageHeight()); + double width = 100 + camera.SetImageWidth(width) + double aspectRatio = width / camera.ImageHeight() + EXPECT_NEAR(aspectRatio, camera.AspectRatio(), 1e-6) + EXPECT_NE(PixelFormat::PF_UNKNOWN, camera->ImageFormat()); camera->SetImageFormat(PixelFormat::PF_B8G8R8); EXPECT_EQ(PixelFormat::PF_B8G8R8, camera->ImageFormat()); From 2ad35e317d9db8f261b8d37ec9a373503eb375f5 Mon Sep 17 00:00:00 2001 From: youhy Date: Mon, 6 Jun 2022 13:19:21 -0700 Subject: [PATCH 09/11] fix camera test Signed-off-by: youhy --- src/Camera_TEST.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Camera_TEST.cc b/src/Camera_TEST.cc index 3e4eec4a0..c5fad413f 100644 --- a/src/Camera_TEST.cc +++ b/src/Camera_TEST.cc @@ -178,10 +178,15 @@ void CameraTest::RenderTexture(const std::string &_renderEngine) camera->SetImageHeight(80u); EXPECT_EQ(80u, camera->ImageHeight()); - double width = 100 - camera.SetImageWidth(width) - double aspectRatio = width / camera.ImageHeight() - EXPECT_NEAR(aspectRatio, camera.AspectRatio(), 1e-6) + double width = 100; + camera->SetImageWidth(width); + double aspectRatio = width / camera->ImageHeight(); + EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); + + double height = 80; + camera->SetImageHeight(height); + aspectRatio = camera->ImageWidth() / height; + EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); EXPECT_NE(PixelFormat::PF_UNKNOWN, camera->ImageFormat()); camera->SetImageFormat(PixelFormat::PF_B8G8R8); From 8d4e5425f86b6ff4885eb8362fc74c1ee21d993d Mon Sep 17 00:00:00 2001 From: youhy Date: Tue, 7 Jun 2022 08:14:29 -0700 Subject: [PATCH 10/11] add SetAspectRatio to SetImageHeight and SetImageWidth Signed-off-by: youhy --- include/ignition/rendering/base/BaseCamera.hh | 4 ++-- src/Camera_TEST.cc | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/ignition/rendering/base/BaseCamera.hh b/include/ignition/rendering/base/BaseCamera.hh index a78039b47..a747f76ce 100644 --- a/include/ignition/rendering/base/BaseCamera.hh +++ b/include/ignition/rendering/base/BaseCamera.hh @@ -286,7 +286,7 @@ namespace ignition void BaseCamera::SetImageWidth(const unsigned int _width) { this->RenderTarget()->SetWidth(_width); - this->aspect = this->AspectRatio(); + this->SetAspectRatio(1.0 * _width / this->ImageHeight()); } ////////////////////////////////////////////////// @@ -301,7 +301,7 @@ namespace ignition void BaseCamera::SetImageHeight(const unsigned int _height) { this->RenderTarget()->SetHeight(_height); - this->aspect = this->AspectRatio(); + this->SetAspectRatio(1.0 * this->ImageWidth() / _height); } ////////////////////////////////////////////////// diff --git a/src/Camera_TEST.cc b/src/Camera_TEST.cc index c5fad413f..c2bfceab2 100644 --- a/src/Camera_TEST.cc +++ b/src/Camera_TEST.cc @@ -178,15 +178,16 @@ void CameraTest::RenderTexture(const std::string &_renderEngine) camera->SetImageHeight(80u); EXPECT_EQ(80u, camera->ImageHeight()); + double height = 80; + camera->SetImageHeight(height); + double aspectRatio = camera->ImageWidth() / height; + EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); + double width = 100; camera->SetImageWidth(width); - double aspectRatio = width / camera->ImageHeight(); + aspectRatio = width / camera->ImageHeight(); EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); - double height = 80; - camera->SetImageHeight(height); - aspectRatio = camera->ImageWidth() / height; - EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); EXPECT_NE(PixelFormat::PF_UNKNOWN, camera->ImageFormat()); camera->SetImageFormat(PixelFormat::PF_B8G8R8); From 545a534f816270ddf93d0a9d5b8eb50f365fce61 Mon Sep 17 00:00:00 2001 From: youhy Date: Thu, 9 Jun 2022 07:55:06 -0700 Subject: [PATCH 11/11] static cast to double Signed-off-by: youhy --- include/ignition/rendering/base/BaseCamera.hh | 6 ++++-- src/Camera_TEST.cc | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/ignition/rendering/base/BaseCamera.hh b/include/ignition/rendering/base/BaseCamera.hh index a747f76ce..28e797235 100644 --- a/include/ignition/rendering/base/BaseCamera.hh +++ b/include/ignition/rendering/base/BaseCamera.hh @@ -286,7 +286,8 @@ namespace ignition void BaseCamera::SetImageWidth(const unsigned int _width) { this->RenderTarget()->SetWidth(_width); - this->SetAspectRatio(1.0 * _width / this->ImageHeight()); + this->SetAspectRatio( + static_cast(_width) / static_cast(this->ImageHeight())); } ////////////////////////////////////////////////// @@ -301,7 +302,8 @@ namespace ignition void BaseCamera::SetImageHeight(const unsigned int _height) { this->RenderTarget()->SetHeight(_height); - this->SetAspectRatio(1.0 * this->ImageWidth() / _height); + this->SetAspectRatio( + static_cast(this->ImageWidth()) / static_cast(_height)); } ////////////////////////////////////////////////// diff --git a/src/Camera_TEST.cc b/src/Camera_TEST.cc index c2bfceab2..a3c928d2c 100644 --- a/src/Camera_TEST.cc +++ b/src/Camera_TEST.cc @@ -171,28 +171,26 @@ void CameraTest::RenderTexture(const std::string &_renderEngine) // render texture parameters EXPECT_GT(camera->ImageWidth(), 0u); - camera->SetImageWidth(100u); - EXPECT_EQ(100u, camera->ImageWidth()); - EXPECT_GT(camera->ImageHeight(), 0u); - camera->SetImageHeight(80u); - EXPECT_EQ(80u, camera->ImageHeight()); - double height = 80; + unsigned int height = 80; camera->SetImageHeight(height); - double aspectRatio = camera->ImageWidth() / height; + EXPECT_EQ(height, camera->ImageHeight()); + double aspectRatio = + static_cast(camera->ImageWidth()) / static_cast(height); EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); - double width = 100; + unsigned int width = 100; camera->SetImageWidth(width); - aspectRatio = width / camera->ImageHeight(); + EXPECT_EQ(width, camera->ImageWidth()); + aspectRatio = + static_cast(width) / static_cast(camera->ImageHeight()); EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6); - EXPECT_NE(PixelFormat::PF_UNKNOWN, camera->ImageFormat()); camera->SetImageFormat(PixelFormat::PF_B8G8R8); EXPECT_EQ(PixelFormat::PF_B8G8R8, camera->ImageFormat()); - EXPECT_EQ(100u*80u*3u, camera->ImageMemorySize()); + EXPECT_EQ(width*height*3u, camera->ImageMemorySize()); // verify render texture GL Id