Skip to content

Commit

Permalink
Main: AutoParamDataSource - allow injecting cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Feb 27, 2025
1 parent 57fc7df commit 0baa453
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
2 changes: 2 additions & 0 deletions OgreMain/include/OgreAutoParamDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ namespace Ogre {
size_t getBoneMatrixCount(void) const;
OGRE_DEPRECATED size_t getWorldMatrixCount(void) const { return getBoneMatrixCount(); }
const Affine3& getViewMatrix(void) const;
Affine3 getViewMatrix(const Camera* cam) const;
const Matrix4& getViewProjectionMatrix(void) const;
const Matrix4& getProjectionMatrix(void) const;
Matrix4 getProjectionMatrix(const Camera* cam) const;
const Matrix4& getWorldViewProjMatrix(void) const;
const Affine3& getWorldViewMatrix(void) const;
const Affine3& getInverseWorldMatrix(void) const;
Expand Down
78 changes: 46 additions & 32 deletions OgreMain/src/OgreAutoParamDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,26 @@ namespace Ogre {
return mWorldMatrixArray + int(MeshManager::getBonesUseObjectSpace());
}
//-----------------------------------------------------------------------------
const Affine3& AutoParamDataSource::getViewMatrix(void) const
Affine3 AutoParamDataSource::getViewMatrix(const Camera* cam) const
{
if (mViewMatrixDirty)
Affine3 view;
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityView())
view = Affine3::IDENTITY;
else
{
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityView())
mViewMatrix = Affine3::IDENTITY;
else
view = cam->getViewMatrix(true);
if (mCameraRelativeRendering)
{
mViewMatrix = mCurrentCamera->getViewMatrix(true);
if (mCameraRelativeRendering)
{
mViewMatrix.setTrans(Vector3::ZERO);
}

view.setTrans(Vector3::ZERO);
}
}
return view;
}
const Affine3& AutoParamDataSource::getViewMatrix(void) const
{
if (mViewMatrixDirty)
{
mViewMatrix = getViewMatrix(mCurrentCamera);
mViewMatrixDirty = false;
}
return mViewMatrix;
Expand All @@ -336,31 +341,40 @@ namespace Ogre {
return mViewProjMatrix;
}
//-----------------------------------------------------------------------------
Matrix4 AutoParamDataSource::getProjectionMatrix(const Camera* cam) const
{
Matrix4 proj;

// NB use API-independent projection matrix since GPU programs
// bypass the API-specific handedness and use right-handed coords
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityProjection())
{
// Use identity projection matrix, still need to take RS depth into account.
RenderSystem* rs = Root::getSingleton().getRenderSystem();
rs->_convertProjectionMatrix(Matrix4::IDENTITY, proj, true);
}
else
{
proj = mCurrentCamera->getProjectionMatrixWithRSDepth();
}

if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
{
// Because we're not using setProjectionMatrix, this needs to be done here
// Invert transformed y
proj[1][0] = -proj[1][0];
proj[1][1] = -proj[1][1];
proj[1][2] = -proj[1][2];
proj[1][3] = -proj[1][3];
}

return proj;
}
const Matrix4& AutoParamDataSource::getProjectionMatrix(void) const
{
if (mProjMatrixDirty)
{
// NB use API-independent projection matrix since GPU programs
// bypass the API-specific handedness and use right-handed coords
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityProjection())
{
// Use identity projection matrix, still need to take RS depth into account.
RenderSystem* rs = Root::getSingleton().getRenderSystem();
rs->_convertProjectionMatrix(Matrix4::IDENTITY, mProjectionMatrix, true);
}
else
{
mProjectionMatrix = mCurrentCamera->getProjectionMatrixWithRSDepth();
}
if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
{
// Because we're not using setProjectionMatrix, this needs to be done here
// Invert transformed y
mProjectionMatrix[1][0] = -mProjectionMatrix[1][0];
mProjectionMatrix[1][1] = -mProjectionMatrix[1][1];
mProjectionMatrix[1][2] = -mProjectionMatrix[1][2];
mProjectionMatrix[1][3] = -mProjectionMatrix[1][3];
}
mProjectionMatrix = getProjectionMatrix(mCurrentCamera);
mProjMatrixDirty = false;
}
return mProjectionMatrix;
Expand Down

0 comments on commit 0baa453

Please sign in to comment.