### Wrong projection parameters when using Custom Projection Matrix

Posted:

**Tue Aug 06, 2019 1:23 pm**Hi,

I recently used Ogre::Camera::setCustomProjectionMatrix to add Camera skew to my project by modifying slightly the Projection matrix generated by Ogre.

When I give back that custom matrix to Ogre there is a problem concerning the rendering of my shader based skybox that wasn't there before.

(Ogre 2.1 branch, under linux with, of course, OpenGL 3+ and glsl shader)

After investigation I found that Ogre::Frustum::calcProjectionParameters seems to be wrong when a custom projection matrix is used :

should have been in fact :
Because rendering coordinate goes from -0.5 to 0.5 in width and height to have a length of 1.0 (instead of -1.0 to 1.0).

Thanks to this modification, my skybox was corrected.

To verify it, simply check the result of left, top, right and bottom values for custom projection matrix by calling
with and without the custom matrix and see that values are different.

Could someone merge this modification ?

I recently used Ogre::Camera::setCustomProjectionMatrix to add Camera skew to my project by modifying slightly the Projection matrix generated by Ogre.

When I give back that custom matrix to Ogre there is a problem concerning the rendering of my shader based skybox that wasn't there before.

(Ogre 2.1 branch, under linux with, of course, OpenGL 3+ and glsl shader)

After investigation I found that Ogre::Frustum::calcProjectionParameters seems to be wrong when a custom projection matrix is used :

Code: Select all

```
if (mCustomProjMatrix)
{
// Convert clipspace corners to camera space
Matrix4 invProj = mProjMatrix.inverse();
Vector3 topLeft(-1.0f, 1.0f, 0.0f);
Vector3 bottomRight(1.0f, -1.0f, 0.0f);
topLeft = invProj * topLeft;
bottomRight = invProj * bottomRight;
left = topLeft.x;
top = topLeft.y;
right = bottomRight.x;
bottom = bottomRight.y;
}
```

Code: Select all

```
if (mCustomProjMatrix)
{
// Convert clipspace corners to camera space
Matrix4 invProj = mProjMatrix.inverse();
Vector3 topLeft(-0.5f, 0.5f, 0.0f);
Vector3 bottomRight(0.5f, -0.5f, 0.0f);
topLeft = invProj * topLeft;
bottomRight = invProj * bottomRight;
left = topLeft.x;
top = topLeft.y;
right = bottomRight.x;
bottom = bottomRight.y;
}
```

Thanks to this modification, my skybox was corrected.

To verify it, simply check the result of left, top, right and bottom values for custom projection matrix by calling

Code: Select all

`myCamera->setCustomProjectionMatrix(true, myCamera->getProjectionMatrix() );`

Could someone merge this modification ?