Sign in to follow this  

LibGDX "fake 3d" camera / rendering questions

This topic is 414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone,

There was an interesting post on reddit the other day about a "fake 3d" style of graphics used notably in NIUM (gif) whereby you draw "slices" of your object, and render them with an offset to create a kind of stacked-layer 3d effect (explained here).

I've been trying to reproduce this style using LibGDX, and drawing the images to the screen with a Y-offset is simple enough. I am however really struggling with actually creating the sort of camera shown in the example NIUM gif. I'm using the OrthographicCamera LibGDX provides to render the scene itself, and each object in the world has it's own x and y world coordinate, as would the movable player character. 

From what I can understand:

  • Either the objects in the world rotate around the centerpoint of the camera's view when the "camera" is moved (however this means they are moving their world coordinates, which is bad)
  • ...or the "camera" itself is rotating its view of the world, preserving each objects relative x and y location. LibGDX's camera also has a rotate method, but this entirely flips the items around, and I'm not managing to get the objects own scaling and rotations correct when using this, although it seems like it should be the correct way to do this? This also rotates the axis, which complicates things.
  • The "up" direction by which the layers are offset, and also the Y-axis on which they are scaled for perspective, needs to always be up relative to the screen and ignore the camera rotation. So if I do rotate the camera itself and not the objects, as the axis get rotated as well, "up" (adjusting the value of Y) is now relative to the rotation.

I've been trying to use the Affine2 class in LibGDX to do the translations, rotation, scaling etc. for the "layered objects" , and some attempts to use the rotation of the camera itself, but I think I'm just not understanding fully what I actually need to rotate/translate and in what order to accomplish this, so I'd really appreciate any pointers on the correct way to do this. Thanks!

Share this post


Link to post
Share on other sites

Eh cant you like get a similar look out of pure 3D and be done with it?

 

Have in mind that "technique" appears to be derived from the limitations of GameMaker. You instead do have a 3D framework capable of doing 3D and shaders just fine. Games like Project Zomboid get a very nice pixel-y lo-fi look from 3D models already.

Share this post


Link to post
Share on other sites

* Either the objects in the world rotate around the centerpoint of the camera's view when the "camera" is moved (however this means they are moving their world coordinates, which is bad)

This is somewhat close but, like you say, you wouldn't actually want to be changing the "world space" position of objects. Rather, you apply the camera's transform to each object as you render them, this gives you their "view space" coordinates. Which is more like what you're saying in your next bullet point...

 

* ...or the "camera" itself is rotating its view of the world, preserving each objects relative x and y location. LibGDX's camera also has a rotate method, but this entirely flips the items around, and I'm not managing to get the objects own scaling and rotations correct when using this, although it seems like it should be the correct way to do this? This also rotates the axis, which complicates things.

I'm not an expert with LibGDX's cameras, but a quick scan through the javadoc reveals the rotateAround method which sounds to me like what you need. You would set the point of rotation to be the main character, the axis to be the 'up' vector (pointing up to the sky: (0,1,0)) and then set the angle as appropriate.
 
I think that will give you a camera which rotates around the main character; to get a correct effect you would also have to make sure that the camera was already positioned a suitable distance away from the main character and also set the camera to lookat the point of rotation (the main character's position).

 

The "up" direction by which the layers are offset, and also the Y-axis on which they are scaled for perspective, needs to always be up relative to the screen and ignore the camera rotation. So if I do rotate the camera itself and not the objects, as the axis get rotated as well, "up" (adjusting the value of Y) is now relative to the rotation.

Correct.

You want to transform each object position into "view-space" first and then apply the Y-axis offsets for the layers from that. I.e. You multiply the camera's view matrix by each object's world matrix, translate an origin point (0,0,0) by that matrix (which gives you the object's position in view-space) and then offset its Y coordinate as needed for each layer.

 

The key thing that makes this work is that view-space shares cardinal directions with the screen: up in view-space is up in screen-space, etc.

Edited by dmatter

Share this post


Link to post
Share on other sites

This topic is 414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this