diff --git a/OgreMain/include/OgreAutoParamDataSource.h b/OgreMain/include/OgreAutoParamDataSource.h index 98a94abb959..34e817903a7 100644 --- a/OgreMain/include/OgreAutoParamDataSource.h +++ b/OgreMain/include/OgreAutoParamDataSource.h @@ -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; diff --git a/OgreMain/src/OgreAutoParamDataSource.cpp b/OgreMain/src/OgreAutoParamDataSource.cpp index 5fb8635ba97..dfd49e66359 100644 --- a/OgreMain/src/OgreAutoParamDataSource.cpp +++ b/OgreMain/src/OgreAutoParamDataSource.cpp @@ -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; @@ -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;