From 083883f1a90ca02c2892cfb52824f9b5121cf49d Mon Sep 17 00:00:00 2001 From: Aditya Date: Thu, 1 Sep 2022 23:48:31 -0700 Subject: [PATCH] Simplified math calculation Signed-off-by: Aditya --- include/gz/rendering/base/BaseCamera.hh | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/include/gz/rendering/base/BaseCamera.hh b/include/gz/rendering/base/BaseCamera.hh index ca4ff7c66..08fc2c287 100644 --- a/include/gz/rendering/base/BaseCamera.hh +++ b/include/gz/rendering/base/BaseCamera.hh @@ -505,22 +505,16 @@ namespace gz template math::Matrix3d BaseCamera::CameraIntrinsicMatrix() const { + // Extracting the intrinsic matrix : + // https://ogrecave.github.io/ogre/api/13/class_ogre_1_1_math.html const math::Matrix4d& projectionMat = this->ProjectionMatrix(); - double right = this->ImageWidth(); - double left = 0.0; - double top = this->ImageHeight(); - double bottom = 0.0; - - double inverseWidth = 1.0 / (right - left); - double inverseHeight = 1.0 / (top - bottom); - - double fX = projectionMat(0, 0)/ (2*inverseWidth); - double fY = projectionMat(1, 1) / (2*inverseHeight); - double cX = -((projectionMat(0, 2) - - ((right + left) / (right - left))) * (right - left)) / 2; - double cY = this->ImageHeight() + ((projectionMat(1, 2) - - ((top + bottom) / (top - bottom))) * (top - bottom)) / 2; + const double width = static_cast(this->ImageWidth()); + const double height = static_cast(this->ImageHeight()); + double fX = (projectionMat(0, 0) * width) / 2.0; + double fY = (projectionMat(1, 1) * height) / 2.0; + double cX = (-1.0 * width * (projectionMat(0, 2) - 1.0) / 2.0; + double cY = height + (height * (projectionMat(1, 2) - 1)) / 2.0; return math::Matrix3d(fX, 0, cX, 0, fY, cY,