Modifying View->ViewMatrices.ProjMatrix

Hi

What I’m trying to do is calibrate a camera in Unreal so it can mimic the exact properties of another perspective camera from another engine.

This should be do-able by copying the original camera’s extrinsic matrix/properties (location and rotation) and intrinsic matrix/properties (the focal length, skew and x&y offsets).

I’ve created my own GameViewportClient, overridden the Draw method and set it as the default Game Viewport Client class in the project/engine settings.

I have set the camera’s location and rotation so it copies the original exactly. That works.

I have also set the Focal Lengths fx & fy (at locations [0,0] and [1,1] respectively in the ProjMatrix) and this also mimics the original camera’s view exactly - so far so good.

But when I try to set the projection matrix properties at locations [0,2] and [1,2], which should relate to the ‘principal point offset’ x0 and y0 (in other words just translating that view in 2d space by an x and a y value) it doesn’t do what I would expect - it starts clipping the view by that amount rather than transforming it along those axes.

I’m thinking there must be another way of doing it but have been searching for quite a while now and can’t figure how to set these ‘principal point offset’ values in UE.
Does anyone know any more about the view matrices and how they work? Or how to offset these x,y values so the rendered view is simply translated in x & y positions (in 2d space)?

I’m learning how to do all this through this series of articles: Dissecting the Camera Matrix, Part 3: The Intrinsic Matrix ← and have tried in Unity on the Camera.projectionMatrix and it works exactly how it should, however in UE it does up until trying to change the [0,2] and [1,2] values on the ViewMatrices.ProjMatrix and that’s where it falls apart.

I can provide more info if needed but am stumped on this and would really appreciate a pointer if anyone knows.

Thanks

It turns out that in the Unreal ProjMatrix the value for x0 is at matrix element [2,0] (normally at [0,2]) and the value for y0 is at matrix element [2,1] (normally at [1,2])
I’m not sure if this is because of a matrix inversion but setting the values (well actually it’s the inverse of the values so multiply by -1) generates the same camera projection matrix as the normal intrinsic matrix.
Just in case anyone else runs into this/looking for it :slight_smile:

1 Like

How do you set the new projection matrix? Which object holds it?

That’s a good question @anonymous_user_0a3a9639 !
I’ve just gone to update my code so it will work with UE 4.16 and it seems that you can no longer update the ViewMatrices.ProjMatrix as the member no longer exists.
As is fairly usual with UE4 there’s no documentation explaining why or how to access the projection matrix, not from the searching I’ve done anyway.
I’ll post it up here if I can come across it and please do the same if you’ve already found it. Or indeed if there’s anyone from Epic that knows how to update it and follows these forums?