collinsmith / riiablo

Diablo II remade using Java and LibGDX
http://riiablo.com
Apache License 2.0
872 stars 99 forks source link

improve isometric camera #55

Closed collinsmith closed 4 years ago

collinsmith commented 5 years ago

I've created and begun working on an improved camera system com.riiablo.camera. This camera should support a 1:1 ratio with the game world and simplify the many screen↔map coordinate conversions that take place -- specifically regarding position and rounding coordinates to convert to and from tiles. This change/distinction is needed because I want OrthographicCamera to hide the zoom/camera position properties from IsometricCamera so when entities are working with their position/angle data they don't need to take into account client-specific camera properties -- this should provide more consistency and simplify the implementation of a proper physics engine.

Essentially this should consist of two main classes:

As of now, I am not planning on adding support for the perspective mode -- this may require a different implementation of MapRenderer and is outside the scope of the initial design. It could be as simple as applying an additional camera extension for PerspectiveCamera with a lower angle of attack (i.e., to transform the output of MapRenderer) and some FOV, but I can't say without further investigation.

collinsmith commented 5 years ago

I'm going to group this in with this issue for now: MapRenderer drawing results in jitter (desktop) and gaps (mobile). I think this is caused by the rounding that's performed when drawing the textures onto a projected buffer and temp fix I've been using is to just stretch the height of floor tiles by 1, but some walls show a gap also in the vertical dimension even on desktop. This is very distracting if you're looking for it and I think it should be reasonably simple to fix.

The fix I'd like to look into is drawing to a buffer without any stretching (identity matrix) to get a perfect 1:1 pixel scale and then stretching that buffer in one go to eliminate the tile gap (upscale filter will sample guaranteed non-transparent pixels this way). I think this approach may also remove most of the jitter (some may still be present from upscaling, don't think that's fixable unless I go with a different upscaler). I.e., layers will render using an identity matrix and then the layers will have the OrthographicCamera projection matrix applied upon final rendering.

This change will be easiest to make when MapRenderer is decoupled from its built-in camera fields and support for IsometricCamera is added.

collinsmith commented 4 years ago

IsometricCamera has been roughly tested with CameraTool, I need to go through it and document the methods because they're confusing as to what they actually do. I'm really happy with the result though, but concerned about the behavior this will have on iso position versus offset (camera position is centered on the tile, but the center of the tile is really the iso position + (0,-Tile.SUBTILE_HEIGHT50)

collinsmith commented 4 years ago

d6105d9f9a580c3b542c8adbeaee0d3656bc4ebe closes this