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

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

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

Post 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.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post 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?
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post 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
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
VF.zgeproj
(200.08 KiB) Downloaded 594 times
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Ville, really nice improvement. Kjell, really nice example.
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Post 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!
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

I agree, real nice example Kjell and thanks for sharing the zgeproj.
Post Reply