Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change aspect to AspectRatio() #635

Merged
merged 12 commits into from
Jun 9, 2022
4 changes: 4 additions & 0 deletions include/ignition/rendering/base/BaseCamera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ namespace ignition
void BaseCamera<T>::SetImageWidth(const unsigned int _width)
{
this->RenderTarget()->SetWidth(_width);
this->SetAspectRatio(
static_cast<double>(_width) / static_cast<double>(this->ImageHeight()));
}

//////////////////////////////////////////////////
Expand All @@ -300,6 +302,8 @@ namespace ignition
void BaseCamera<T>::SetImageHeight(const unsigned int _height)
{
this->RenderTarget()->SetHeight(_height);
this->SetAspectRatio(
static_cast<double>(this->ImageWidth()) / static_cast<double>(_height));
}

//////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion ogre/src/OgreCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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));
}

Expand Down
2 changes: 1 addition & 1 deletion ogre2/src/Ogre2Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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());
jennuine marked this conversation as resolved.
Show resolved Hide resolved
this->ogreCamera->setFOVy(Ogre::Radian(vfov));
}

Expand Down
4 changes: 2 additions & 2 deletions ogre2/src/Ogre2DepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +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->aspect);
this->ogreCamera->setAspectRatio(this->aspect);
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
Expand Down
4 changes: 2 additions & 2 deletions ogre2/src/Ogre2ThermalCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +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->aspect);
this->ogreCamera->setAspectRatio(this->aspect);
double vfov;
vfov = 2.0 * atan(tan(this->HFOV().Radian() / 2.0) / this->AspectRatio());
this->ogreCamera->setFOVy(Ogre::Radian(vfov));

// Load thermal material
Expand Down
21 changes: 15 additions & 6 deletions src/Camera_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +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());

unsigned int height = 80;
camera->SetImageHeight(height);
EXPECT_EQ(height, camera->ImageHeight());
double aspectRatio =
static_cast<double>(camera->ImageWidth()) / static_cast<double>(height);
EXPECT_NEAR(aspectRatio, camera->AspectRatio(), 1e-6);

unsigned int width = 100;
camera->SetImageWidth(width);
EXPECT_EQ(width, camera->ImageWidth());
aspectRatio =
static_cast<double>(width) / static_cast<double>(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
Expand Down