light calc area shrinks when zoomed in

This commit is contained in:
minjaesong
2019-08-12 03:51:17 +09:00
parent e8b2b04c62
commit f39c4e9178
3 changed files with 55 additions and 24 deletions

View File

@@ -238,16 +238,16 @@ object Terrarum : Disposable {
/** Position of the cursor in the world */
val mouseX: Double
get() = WorldCamera.x + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()
get() = WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()
/** Position of the cursor in the world */
val mouseY: Double
get() = WorldCamera.y + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()
get() = WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()
/** Position of the cursor in the world */
val oldMouseX: Double
get() = WorldCamera.x + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()
get() = WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()
/** Position of the cursor in the world */
val oldMouseY: Double
get() = WorldCamera.y + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).toDouble()
get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).toDouble()
/** Position of the cursor in the world */
@JvmStatic val mouseTileX: Int
get() = (mouseX / CreateTileAtlas.TILE_SIZE).floorInt()

View File

@@ -119,8 +119,12 @@ object LightmapRenderer {
internal var for_y_start = 0
internal var for_x_end = 0
internal var for_y_end = 0
internal var for_x = 0
internal var for_y = 0
internal var for_draw_x_start = 0
internal var for_draw_y_start = 0
internal var for_draw_x_end = 0
internal var for_draw_y_end = 0
//internal var for_x = 0
//internal var for_y = 0
/**
* @param x world coord
@@ -174,19 +178,23 @@ object LightmapRenderer {
if (world.worldIndex == -1) return
for_x_start = WorldCamera.x / TILE_SIZE // fix for premature lightmap rendering
for_y_start = WorldCamera.y / TILE_SIZE // on topmost/leftmost side
for_x_start = WorldCamera.zoomedX / TILE_SIZE // fix for premature lightmap rendering
for_y_start = WorldCamera.zoomedY / TILE_SIZE // on topmost/leftmost side
for_draw_x_start = WorldCamera.x / TILE_SIZE
for_draw_y_start = WorldCamera.y / TILE_SIZE
if (for_x_start < 0) for_x_start -= 1 // to fix that the light shifts 1 tile to the left when WorldCamera < 0
//if (for_y_start < 0) for_y_start -= 1 // not needed when we only wrap at x axis
if (WorldCamera.x in -(TILE_SIZE - 1)..-1) for_x_start -= 1 // another edge-case fix
for_x_end = for_x_start + WorldCamera.width / TILE_SIZE + 3
for_y_end = for_y_start + WorldCamera.height / TILE_SIZE + 3 // same fix as above
for_x_end = for_x_start + WorldCamera.zoomedWidth / TILE_SIZE + 3
for_y_end = for_y_start + WorldCamera.zoomedHeight / TILE_SIZE + 3 // same fix as above
for_draw_x_end = for_draw_x_start + WorldCamera.width / TILE_SIZE + 3
for_draw_y_end = for_draw_y_start + WorldCamera.height / TILE_SIZE + 3
for_x = for_x_start + (for_x_end - for_x_start) / 2
for_y = for_y_start + (for_y_end - for_y_start) / 2
//for_x = for_x_start + (for_x_end - for_x_start) / 2
//for_y = for_y_start + (for_y_end - for_y_start) / 2
//println("$for_x_start..$for_x_end, $for_x\t$for_y_start..$for_y_end, $for_y")
@@ -609,10 +617,10 @@ object LightmapRenderer {
// when shader is not used: 0.5 ms on 6700K
AppLoader.measureDebugTime("Renderer.LightToScreen") {
val this_x_start = for_x_start// + overscan_open
val this_x_end = for_x_end// + overscan_open
val this_y_start = for_y_start// + overscan_open
val this_y_end = for_y_end// + overscan_open
val this_x_start = for_draw_x_start
val this_y_start = for_draw_y_start
val this_x_end = for_draw_x_end
val this_y_end = for_draw_y_end
// wipe out beforehand. You DO need this
lightBuffer.blending = Pixmap.Blending.None // gonna overwrite (remove this line causes the world to go bit darker)

View File

@@ -2,6 +2,8 @@ package net.torvald.terrarum.worlddrawer
import com.jme3.math.FastMath
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ceilInt
import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.ActorWithBody
@@ -21,18 +23,37 @@ object WorldCamera {
private set
var y: Int = 0 // top position
private set
var xEnd: Int = 0 // right position
private set
var yEnd: Int = 0 // bottom position
private set
inline val gdxCamX: Float // centre position
get() = xCentre.toFloat()
inline val gdxCamY: Float// centre position
get() = yCentre.toFloat()
var width: Int = 0
private set
var height: Int = 0
private set
private var zoom = 1f
private var zoomSamplePoint = 0f
// zoomed coords. Currently only being used by the lightmaprenderer.
// What about others? We just waste 3/4 of the framebuffer
val zoomedX: Int
get() = x + (width * zoomSamplePoint).toInt()
val zoomedY: Int
get() = y + (height * zoomSamplePoint).toInt()
val zoomedWidth: Int
get() = (width / zoom).ceilInt()
val zoomedHeight: Int
get() = (height / zoom).ceilInt()
var xEnd: Int = 0 // right position
private set
var yEnd: Int = 0 // bottom position
private set
inline val gdxCamX: Float // centre position
get() = xCentre.toFloat()
inline val gdxCamY: Float// centre position
get() = yCentre.toFloat()
inline val xCentre: Int
get() = x + width.ushr(1)
inline val yCentre: Int
@@ -45,6 +66,8 @@ object WorldCamera {
width = AppLoader.screenW//FastMath.ceil(AppLoader.screenW / zoom) // div, not mul
height = AppLoader.screenH//FastMath.ceil(AppLoader.screenH / zoom)
zoom = Terrarum.ingame?.screenZoom ?: 1f
zoomSamplePoint = (1f - 1f / zoom) / 2f // will never quite exceed 0.5
// TOP-LEFT position of camera border