Thanks man! I ended up figuring it out and I did something similar. Since it’ll cover some of your todo’s I’ll add it here:
What I ended up doing was creating a SetOffAxisMatrix blueprint option so that I could dynamically update it.
I also made a special function which I’ll attach below: (forgive the c# code, I’m not to good with C++)
The function takes 3 parameters: The height of the screen, the width of the screen, and the position of the eye relative to the center of the screen, all in MM. (so 0,0,0 would mean you’re in the middle of the tv, 0,0,500 would mean your head is 500mm back from the center of the screen and -20,0,500 would mean your head is back and slightly to the left of the center of the scren) I think the math reduces away the differences between mm,cm or Unreal world units so it doesn’t matter what you use so long as its all the same scale.
Thanks again man, I couldn’t have done this without your help!
public static Matrix4 UpdateFrustrum(float ScreenWidth,float ScreenHeight,Vector3 eyePosition)
{
float headX = eyePosition.X / ScreenHeight;
float headY = eyePosition.Y / ScreenHeight;
float headDist = eyePosition.Z / ScreenHeight;
float screenAspect = ScreenWidth / ScreenHeight;
float nearPlane = 1f;
Matrix4 resultM = Matrix4.CreatePerspectiveOffCenter( nearPlane*(-.5f * screenAspect - headX)/headDist,
nearPlane*(.5f * screenAspect - headX)/headDist,
nearPlane*(-.5f + headY)/headDist,
nearPlane*(.5f + headY)/headDist,
nearPlane, 1000);
return MagicFix (resultM);
}
private static Matrix4 MagicFix(Matrix4 matrix){
float[,] result = Matrix2Float (matrix);
//result [1, 2] = 0f;
result[2,3] = 1f;
result[2,2] = 0.0f;
result[3,0] = 0.0f;
result[3,1] = 0.0f;
result = ScaleMatrix(result, (1.0f / result [0, 0]));
result[3,2] = nearClipPlane;
return Float2Matrix (result);
}