[Solved] Shifting camera

Hi !
I need have the ability to shift the camera view on X or Y. It is possible in viewport. Unfortunately, at playtime, this parameter seems to be ignored.


It seems it’s not supported in armory out-of-the-box, but looks doable by modifying the perspective matrix of the camera from what I googled.

If you don’t need it to be animated inside of blender you could add a new function that creates a perspective matrix based on the lens shift and replace the one of the camera (named P) with something like this https://stackoverflow.com/questions/1308395/how-do-you-create-an-off-center-perspectivecamera-in-wpf. Perspective matrix creation without the offset for reference https://github.com/armory3d/iron/blob/b1a1b0f928eba3fa26ba86547a02fa84f49bf0d0/Sources/iron/math/Mat4.hx#L468.

If you need it animated from Blender or use logic nodes (not sure since this post is in general) I would open an issue for a feature request because it would require some more of work for that to work.


Wow ! really impressive :smile:
It gives me a little headache, I don’t really know what to do with that…
Do I need to paste the code on a trait and apply it to a camera ? then play with it ?
I’m sure it’s not so simple.
I don’t need to animate this property, I just have to apply it at startup.
Thanks again for your answer, it would be nice if you could help me a little more.

Do I need to paste the code on a trait and apply it to a camera ? then play with it ?

Yes, that is one way. You can add a haxe trait, and on notifyOnStart put a function that creates a new matrix, and then I would pretty much copy/paste that perspective function I linked in the second link and modify it based on the first one to allow it to work with an offset. And then access the camera via iron.Scene.active.camera and modify its projection matrix by replacing its P member with the newly created.

Here is another resource I found in the unity docs https://docs.unity3d.com/ScriptReference/Camera-projectionMatrix.html, the logic is a bit different but it may work similar.

it would be nice if you could help me a little more.

Sure, ask away!

Edit: I added extra steps I forgot.

1 Like

I really appreciate your help.
I will work on it, as I have never used Haxe, then I will post a blend example as soon it is working.

Edit : Work in progress, playing with parameters I see funny weird things :star_struck:

Here is a raw solution :
ShiftCamera.hx (899 Bytes)

Place this trait on the main camera and play with left and right vars. values -1 and 1 gives a normal camera. Values like -0.5 and 1.5 shifts the camera on X axis.

Thanks again M_Ent8h :slight_smile:

1 Like