# Interpolating orthograpfic and perspective projection matrices

**URL:** <https://forums.unrealengine.com/t/interpolating-orthograpfic-and-perspective-projection-matrices/405128>\
**Category:** Cinematics & Media\
**Tags:** projection-matrix, unreal-engine, UE4, CPP, question\
**Created:** [September 21, 2017, 12:52pm UTC](https://forums.unrealengine.com/t/interpolating-orthograpfic-and-perspective-projection-matrices/405128 "2017-09-21T12:52:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Totoro83](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Totoro83](https://forums.unrealengine.com/u/Totoro83)\
**Post date:** [September 21, 2017, 12:52pm UTC](https://forums.unrealengine.com/t/interpolating-orthograpfic-and-perspective-projection-matrices/405128/1 "2017-09-21T12:52:51Z")

</div>

I want to have a smooth transition between two different projection modes, orthographic and perspective.

After some researching I discovered that it is possible to feed different projection matrices overriding ULocalPlayer::GetProjectionData, so I made something like this:

```
bool UOrthoLocalPlayer::GetProjectionData(FViewport* Viewport, EStereoscopicPass StereoPass, FSceneViewProjectionData& ProjectionData) const
{
	bool ret = Super::GetProjectionData(Viewport, StereoPass, ProjectionData);

	FMinimalViewInfo ViewInfo;
	GetViewPoint(/*out*/ ViewInfo, StereoPass);

	FMatrix originalMatrix = ProjectionData.ProjectionMatrix;

	ViewInfo.ProjectionMode = ECameraProjectionMode::Orthographic;
	FMinimalViewInfo::CalculateProjectionMatrixGivenView(ViewInfo, AspectRatioAxisConstraint, ViewportClient->Viewport, /*inout*/ ProjectionData);

	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
			ProjectionData.ProjectionMatrix.M[i][j] = ProjectionData.ProjectionMatrix.M[i][j] * OrthoQuantity + originalMatrix.M[i][j] * (1 - OrthoQuantity);

	return ret;
}

```

This should interpolate between the two projection matrices changing the OrthoQuantity parameter from 0 to 1. And for these very values it works perfectly, but when I change the value in something between them I only obtain a very strange result: I simply have the scene like if it was with the perspective matrix but moving, like the camera was changing the direction it seens, more and more as I approach the value 1. I suppose something happens behind the curtrain, but I can’t understand what.
