Howto modify the projection matrix

Hi Hurricane and all.

I’ve downloaded your source but I get compiler errors - namely it says it can’t load the IHeadMountedDisplay.h file. I’ve tried changing this line to include the whole the path to the source but then it just comes up with a whole load of other errors.

Is it because i’m trying to build it in my game’s source folder rather than the engine?

Ah - do I try to build it in the plugin folder maybe?

Any help (for a C++ newb) would be much appreciated.

Thanks for spending the time to publish this source on the answerhub - i’m really interested in using this to create a kind of 3d boardgame effect for a TV show where the projection is calculated from the point of view of the tv studio camera.

Hi Hurricane - I replied to the bottom of this but probably should have replied to this post in order to get your attention. I’m very keen to get this kind of projection working in my build - hopefully using a volume (flattened to 2d) to define the corners of the projected screen. I tried to compile your source from the zip you posted but - being a bit of a newb - had problems getting it to compile - maybe because i’m using 4.7? Is this something you’d be interested in helping out with (for some financial reimbursement perhaps?). Dan.

link text

@Dan & kor6en

attached there is a UE 4.7.1 project :slight_smile:
checks the test map

Thank You, but It requires UE4Editor-OffAxisTest.dll

It can’t compile and says that it must be rebuilt from source manually.

Hi kor6en. You need to download visual studio and set it up for UE - there are tutorials for that - then you can right click on the project icon and generate the source files and compile it. I’ve only just taken a look at this (thanks hurricane) but haven’t got my head around how it works yet.

Maybe it’s fault of 4.7.0 version. Because I did everything You explained…and still there’s no dll and he offers me to rebuild them and then fails…and tells me to do that manualy

I open solution file into VS and output gives following:

D:\Users\user\Documents\Unreal Projects\31979-offaxistest\Intermediate\ProjectFiles\OffAxisTest.vcxproj : error : Project “D:\Users\user\Documents\Unreal Projects\31979-offaxistest\Intermediate\ProjectFiles\OffAxisTest.vcxproj” could not be found.

D:\Users\user\Documents\Unreal Projects\31979-offaxistest\Intermediate\ProjectFiles\UE4.vcxproj : error : Project “D:\Users\user\Documents\Unreal Projects\31979-offaxistest\Intermediate\ProjectFiles\UE4.vcxproj” could not be found.

I think you have to create a folder in your projects folder called ‘OffAxisTest’ and in there put the contents of the zip - but not the root folder (31979-offaxis…)

Then don’t try to load the solution until you’ve right clicked on the Unreal Engine Project File (OffAxisTest.uproject) and choose Generate project files - then load the VS solution

Thank You very much for Your time, but it still is hungry for dll files:

1>------ Build started: Project: OffAxisTest, Configuration: DebugGame_Editor x64 ------
1> Performing 3 actions (4 in parallel)
1> OffAxisTest.generated.cpp
1> OffAxisGameViewportClient.cpp
1>D:\Users\user\Documents\Unreal Projects\OffAxisTest\Intermediate\Build\Win64\Inc\OffAxisTest\OffAxisGameViewportClient.generated.h(16): error C4099: ‘FMatrix’ : type name first seen using ‘class’ now seen using ‘struct’
1> c:\program files\epic games\4.7\engine\source\runtime\core\public\math\Matrix.h(13) : see declaration of ‘FMatrix’
1>d:\users\user\documents\unreal projects\offaxistest\intermediate\build\win64\inc\offaxistest\OffAxisGameViewportClient.generated.h(16): error C4099: ‘FMatrix’ : type name first seen using ‘class’ now seen using ‘struct’
1> c:\program files\epic games\4.7\engine\source\runtime\core\public\math\Matrix.h(13) : see declaration of ‘FMatrix’
1> -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: D:\Users\user\Documents\Unreal Projects\OffAxisTest\Binaries\Win64\UE4Editor-OffAxisTest-Win64-DebugGame.dll
1> Cumulative action seconds (8 processors): 0,00 building projects, 1,39 compiling, 0,00 creating app bundles, 0,00 generating debug info, 0,00 linking, 0,00 other
1> UBT execution time: 4,08 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ““C:\Program Files\Epic Games\4.7\Engine\Build\BatchFiles\Build.bat” OffAxisTestEditor Win64 DebugGame “D:\Users\user\Documents\Unreal Projects\OffAxisTest\OffAxisTest.uproject” -rocket” exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Don’t know how to help - the only thing I’m doing differently is my build is set to development editor rather than debug editor.

tried development editor as well…same problem

Hey Hurricane - I want to say thanks for this - i’ve built it but have been swamped with my day job before actually being able to try it - that’s why I haven’t got back to you following your kind release of your code. (I ran it quickly but i’m guessing you need to have a HMD running to make it function? - i’ll plug my occulus in when I get a chance)

Hi, Hurricane. I’ve finaly managed to generate project and made test.
I understood that imaginary projection plane is located on 0 against viewer. But seems that its not completely working as should.
Look at blueprint, video

I tried to move camera with viewer position focusing camera to 0,0,140 where center of that transparent/checkered “window”.
If some plane located in same plane with projection matrix for viewport, then it means that at any circumstances this checkered plane should stay undeformed as curtain for portal - but it does.
Looks that In Your version program is not calculating right view angle against plane for matrix deform.
Does not helping even different coefficients for side and depth locations against plane.
Maybe I did not formulate right: that checkered plane should not make effect of rotation…and pattern should stay paralel with monitor frame…and also 0 pont of that checkered plane is moving sideways as my camera is pointed to center of it.
While looking on result it seems that camera after Generate Off Axis Matix is turned to infinite by Z axis point.
And By changing Z distance of viewer, size of plane on projection plane should not change…only angle of view should. Right?

Could You suggest something to solve problem?

Many thanks For Your previous work on this!!!

Hi, @kor6en

It’s so difficult for me to help you here without a test case. but I think that the problem is in the function named UpdateProjectionMatrix inside the file OffAxisGameViewportClient.cpp

try to replace the line 137:

FVector viewOrigin(0.0f, 0.0f, View->ProjectionMatrixUnadjustedForRHI.M[3][3]);

with:

FVector viewOrigin(FVector::ZeroVector);

these because you are already moving the camera!

ps remember to compile the sources again

Ha! I’m buggered if I can make this work! I’m trying to use the position of my oculus as the ‘head’ position - i’m just plugging the output of the HMD position into the eye position pin but it’s not really working - it’s doing something - The Z coord seems to change the FOV. Thanks helping out us stumbling fools Hurricane. What are you using to drive your position? I eventually want to buy one of those Tobii eye-x eye position readers to do this.

Hi, @hurricane86!

I changed the code. And no big progress here. Camera changes target angle to infinite(seems) distance - not on plane.
For test You can just place some plane object where projection matrix plane(portal/window) should be, and focus/orbit camera on it. That plane must stay still at any circumstances.
I’ll try to multiply camera rotation. So it points on my object on 0,0,0 relatively to projection.

And You told that previously I was already moving the camera, but I tried to not move it…it modified proj.matrix, but did not rotate view on point on projection plane…it moved view paralelly…again, as focusing point is in infinite distance, not on portal 0 point…how to control that?

link text

@kor6en

now should work…
I have updated the “test map”…check the level BP inside…
You can move the “head point” (relative to the monitor) with the left/right/up/down keys …the transparent plane should be the monitor and reamains fixed!

This is great! I’m pretty sure my y and z axis are mixed up between world space and the oculus tracker but with a bit of a re-patch it works! How are you derriving the center coordinates of the screen edges? is it just a flat plane straight through the 0,0,0? Now I just have to work out how to tame the oculus driver - I can’t prevent it from adding the head offset to the camera position. Thanks again Hurricane - if you’d like any donations get in touch. Dan.

Updated: I made it work. I switched off camera rotation…but kept moving. So now I just need to adapt amount of camera motion. One thing that I should inverse x and y axis values for off axis generator.

Another problem stays: antialiasing. Can it be on?

Hi. Ti calibrate realworld with virtual You must make same size screenon same height above ground with semi transparent, textured material.
Then I multiplying coif. and add offsets to input(oculus or kinect) data while playing with camera by switching off generator of offaxis. Then I move in real world sideways and up down to centers and edges of screen…and acclibrate scale with coif. and offset with adding values. Your pont in real world must apear on center of screen.
Then I switch on offaxis generator and multiply input data until virtual screen matches real.
This process very much related with imagination and feel of 3d space as 2d resulting image is not very alternating 3Dspace until You have proper stereo vision. So You must understand where horisont must stay