Skip to content

Commit 0baa453

Browse files
committed
Main: AutoParamDataSource - allow injecting cameras
1 parent 57fc7df commit 0baa453

File tree

2 files changed

+48
-32
lines changed

2 files changed

+48
-32
lines changed

OgreMain/include/OgreAutoParamDataSource.h

+2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ namespace Ogre {
163163
size_t getBoneMatrixCount(void) const;
164164
OGRE_DEPRECATED size_t getWorldMatrixCount(void) const { return getBoneMatrixCount(); }
165165
const Affine3& getViewMatrix(void) const;
166+
Affine3 getViewMatrix(const Camera* cam) const;
166167
const Matrix4& getViewProjectionMatrix(void) const;
167168
const Matrix4& getProjectionMatrix(void) const;
169+
Matrix4 getProjectionMatrix(const Camera* cam) const;
168170
const Matrix4& getWorldViewProjMatrix(void) const;
169171
const Affine3& getWorldViewMatrix(void) const;
170172
const Affine3& getInverseWorldMatrix(void) const;

OgreMain/src/OgreAutoParamDataSource.cpp

+46-32
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,26 @@ namespace Ogre {
306306
return mWorldMatrixArray + int(MeshManager::getBonesUseObjectSpace());
307307
}
308308
//-----------------------------------------------------------------------------
309-
const Affine3& AutoParamDataSource::getViewMatrix(void) const
309+
Affine3 AutoParamDataSource::getViewMatrix(const Camera* cam) const
310310
{
311-
if (mViewMatrixDirty)
311+
Affine3 view;
312+
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityView())
313+
view = Affine3::IDENTITY;
314+
else
312315
{
313-
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityView())
314-
mViewMatrix = Affine3::IDENTITY;
315-
else
316+
view = cam->getViewMatrix(true);
317+
if (mCameraRelativeRendering)
316318
{
317-
mViewMatrix = mCurrentCamera->getViewMatrix(true);
318-
if (mCameraRelativeRendering)
319-
{
320-
mViewMatrix.setTrans(Vector3::ZERO);
321-
}
322-
319+
view.setTrans(Vector3::ZERO);
323320
}
321+
}
322+
return view;
323+
}
324+
const Affine3& AutoParamDataSource::getViewMatrix(void) const
325+
{
326+
if (mViewMatrixDirty)
327+
{
328+
mViewMatrix = getViewMatrix(mCurrentCamera);
324329
mViewMatrixDirty = false;
325330
}
326331
return mViewMatrix;
@@ -336,31 +341,40 @@ namespace Ogre {
336341
return mViewProjMatrix;
337342
}
338343
//-----------------------------------------------------------------------------
344+
Matrix4 AutoParamDataSource::getProjectionMatrix(const Camera* cam) const
345+
{
346+
Matrix4 proj;
347+
348+
// NB use API-independent projection matrix since GPU programs
349+
// bypass the API-specific handedness and use right-handed coords
350+
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityProjection())
351+
{
352+
// Use identity projection matrix, still need to take RS depth into account.
353+
RenderSystem* rs = Root::getSingleton().getRenderSystem();
354+
rs->_convertProjectionMatrix(Matrix4::IDENTITY, proj, true);
355+
}
356+
else
357+
{
358+
proj = mCurrentCamera->getProjectionMatrixWithRSDepth();
359+
}
360+
361+
if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
362+
{
363+
// Because we're not using setProjectionMatrix, this needs to be done here
364+
// Invert transformed y
365+
proj[1][0] = -proj[1][0];
366+
proj[1][1] = -proj[1][1];
367+
proj[1][2] = -proj[1][2];
368+
proj[1][3] = -proj[1][3];
369+
}
370+
371+
return proj;
372+
}
339373
const Matrix4& AutoParamDataSource::getProjectionMatrix(void) const
340374
{
341375
if (mProjMatrixDirty)
342376
{
343-
// NB use API-independent projection matrix since GPU programs
344-
// bypass the API-specific handedness and use right-handed coords
345-
if (mCurrentRenderable && mCurrentRenderable->getUseIdentityProjection())
346-
{
347-
// Use identity projection matrix, still need to take RS depth into account.
348-
RenderSystem* rs = Root::getSingleton().getRenderSystem();
349-
rs->_convertProjectionMatrix(Matrix4::IDENTITY, mProjectionMatrix, true);
350-
}
351-
else
352-
{
353-
mProjectionMatrix = mCurrentCamera->getProjectionMatrixWithRSDepth();
354-
}
355-
if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
356-
{
357-
// Because we're not using setProjectionMatrix, this needs to be done here
358-
// Invert transformed y
359-
mProjectionMatrix[1][0] = -mProjectionMatrix[1][0];
360-
mProjectionMatrix[1][1] = -mProjectionMatrix[1][1];
361-
mProjectionMatrix[1][2] = -mProjectionMatrix[1][2];
362-
mProjectionMatrix[1][3] = -mProjectionMatrix[1][3];
363-
}
377+
mProjectionMatrix = getProjectionMatrix(mCurrentCamera);
364378
mProjMatrixDirty = false;
365379
}
366380
return mProjectionMatrix;

0 commit comments

Comments
 (0)