[libgdx] Mixing Orthogonal and Perpective Camera?

If I have a 2D game, all nice, flat if you will, and now I want some simple 3D elements there, how to do this easily ?

The only way I could figure it out would be: use only perpective camera, and then use planes but I think libgdx doesnt really have them, maybe billboards, so I would end up with thin boxes on the floor haven the texture… but that makes the rendering a nightmare…

no way to just introduce 3d objects easily in a 2D orthographic game ?

How does your game look currently? is it a platformer, or is it top down? I don’t understand what kind of 3d element you’d want to add to a 2d game:3

Actually this is just a tech question, I mean does it matter ?

I thought of like GTA 2, its all flat, but the buildings are actually blocks, so as the camera moves you can see that the blocks are actually 3D
just one example of all 2D and minimal 3D

but if it were a platformer, imagine one all 2D and then the save point or whatever is a rotating 3D object, and there you go

Oh right okay, I understand. It really depends on what you want to do - I’ve never played GTA 2, so I wouldn’t know if this would work, but drawing all the 2d first as a ‘background’ then drawing your 3d assets on top would probably work. Just change the camera projection between drawing, I thiiiink that might work:P

If you want your 3d assets to actually go under, or through, the 2D though, You need to render the 2D onto a texture and put that on a 3D plane, maybe?

Not really too sure on this, changing the camera projection should work as far as I know though ^^

what about rendering your 3D assets to a texture(FBO), and then render that into your game?

Using SpriteBatch you dont have to worry about the plane to draw on.

I can give more info if you are interested. :persecutioncomplex:

I think its inherently a bad idea since 2D is all rasterized pixels and 3D is all vectors, so you can’t align those 2
of course the 2D mode aka orthographic is cheated, but still

you can make it easy and just

each frame >>

  • start with 2D projection
  • render stuff in 2D
  • load a 3D projection that matches the 2D somewhat
  • render stuff in 3D
  • win

if you have a class for data required for the 2D projection you can use those numbers and add a constant fov-y and distance and make a match with try and error.

You can draw actual 3d models in the orthogonal camera in libgdx, if that’s what you want, or you can use PerspectiveCamera with billboard sprites from top down, I guess.

How though ?
If I do


	    modelBatch.begin(camera);
	    	modelBatch.render(instances, environment);
	    modelBatch.end();

Where camera is now a Orthographic one, I cannot seem to find the 3D object anywhere

I create the 3D box by using


        ModelBuilder modelBuilder = new ModelBuilder();
        Model model = modelBuilder.createBox(5f, 5f, 5f, 
            new Material(),
            Usage.Position | Usage.Normal);
        
        ModelInstance ins = new ModelInstance(model);

so it should be 5x5x5 (which I’m not sure how to convert to pixels later but whatever) and I didnt translate it, so it should be in the 0 point.

However going to camera position 0,0, zoom 1 doesnt show it

OrthographicCamera probably needs to have z greater than 0

Ah yes I kinda assumed that zoom was z and Orthographic Cameras dont have z
Of course to zoom and to dolly are different

ofc once you go 3D you can start dealing with all its burdens like …

2D is much nicer to code. most time just regular grids and http://en.wikipedia.org/wiki/Painter's_algorithm