SFML community forums

Help => Graphics => Topic started by: elvaka on July 30, 2016, 04:17:18 pm

Title: Drawing 3D buildings on a 2D tilemap
Post by: elvaka on July 30, 2016, 04:17:18 pm
Hi guys,

I'm trying to draw 3D cubes on top of a 2D SFML scene, in a similar way of how buildings are drawn in GTA2 [1]. That is: the bottom side of the cube should be on the same plane as where SFML sprites are drawn.

How can I define my glFrustrum so that 3D elements align with the 2D layer (eg: when I move the camera, 3D and 2D stuff move at the same time)? Or it's not even possible to mix perspective and orthogonal projections like this?

[1] http://www.gouranga.com/images/gta2/gta2-3.jpg

Thanks!
Title: Re: Drawing 3D buildings on a 2D tilemap
Post by: Hapax on July 30, 2016, 05:55:18 pm
Since you're already drawing the scene in 3D for the buildings, could you not also include the ground as a plane (or multiple tiles on a plane) in 3D?
Title: Re: Drawing 3D buildings on a 2D tilemap
Post by: fallahn on July 30, 2016, 07:08:14 pm
This is exactly what my framework xygine (https://github.com/fallahn/xygine/blob/master/xygine/src/mesh/MeshRenderer.cpp#L426) does with 3D models. You can create a camera which assumes the 2D portion of your game is on the 0 z-plane by using the height of the viewport and the vertical FOV to calculate the distance the 3D camera would need to be.

http://www.youtube.com/watch?v=u2th9hMTxdU