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.