Page 1 of 1

Camera upgrade (for GUI, HUD, 2d layers, menus etc)

Posted: Thu Feb 26, 2015 3:49 am
by rrTea
Related thread: Static sprites

In my project I'm using two Orthographic cameras:
a Zelda-type for ingame content (slightly tilted, zoomed out and pushed up a bit);
a simple frontal one (for various messages delivered between levels).

Now I'm trying to add a nice "wallpaper" effect (an image rendered in the back of everything) to the game itself. Using the "ingame" camera that'd be pretty cumbersome to position and maintain because first I'd have to calculate all sorts of things just to make it fit from top left to bottom right.

So during the game's PrgState OnRender, I thought the way to go about it would be to switch the camera to the frontal one, simply render the wallpaper and then switch back to the "ingame" camera for everything else. Same principle could apply for other elements (see related thread).

But although this can be easily done in ZExpression with

Code: Select all

Prg.Camera = Frontal;
//some stuff
Prg.Camera = Projection;
I discovered this doesn't work... The only way to do it right now is to use Kjell's method in Layer2d example which, if I understood correctly, requires writing transformation matrices and duplicating code that is already in ZGE. Wouldn't it be better if we could just switch cameras instead?

In my opinion the ideal implementation of this would be if the Camera component had two "modes", maybe selectable from a drop down menu under the Component's comment: selecting "Define" shows the whole Camera options like it is now, while selecting "Switch" just shows a drop down menu with the list of all the other cameras. So during OnRender one'd simply sandwich all the components between two Camera components...

I also liked this idea:
Rado1 wrote:My idea is to have, e.g., a variant (or a "2D" flag of) of the RenderTransformGroup/RenderTransform which would work in "camera's space", similarly to RenderText.

Posted: Thu Feb 26, 2015 8:26 am
by VilleK
I see, yes the problem is that App.Camera is only applied before rendering starts (once each frame). So if you switch camera mid-render then it won't take effect. We should have a way to switch camera anywhere. Kjell and others, any thoughts on this?

Posted: Fri Feb 27, 2015 11:24 am
by VilleK
Try the updated version: http://www.zgameeditor.org/files/ZGameEditor_beta.zip

Now you should be able to do things like this:

App.Camera=MyOrthoCamera;
... render stuff using this camera
App.Camera=PerspectiveCamera;
...switch to another
App.Camera=null;
...null sets back to default camera system

Posted: Fri Feb 27, 2015 3:38 pm
by Kjell
Hej Ville,

Nice job :) This makes it a lot easier to combine different projections in a single render pass. For instance, here's a simple Virtua Fighter demo .. which uses a 2D scrolling sky, 3D environment and a 2D GUI.

Image

K

Posted: Fri Feb 27, 2015 7:04 pm
by Rado1
Ville, really nice improvement. Kjell, really nice example.

Posted: Sat Feb 28, 2015 4:16 am
by rrTea
Ville: Fantastic, this is great - I'll start using it immediately! (I'll try to make a mockup of what a component equivalent could look like.)

Kjell: Very nice example!

Posted: Mon Mar 02, 2015 8:31 am
by VilleK
I agree, real nice example Kjell and thanks for sharing the zgeproj.