mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
fixed camera not putting actor at the centre of the screen
- Actually may not be fixed, but it does not cause render bugs at least!
This commit is contained in:
@@ -5,10 +5,12 @@ import net.torvald.terrarum.langpack.Lang
|
|||||||
object CreditSingleton {
|
object CreditSingleton {
|
||||||
|
|
||||||
val credit: List<String>; get() =
|
val credit: List<String>; get() =
|
||||||
("${Lang["CREDITS_PROGRAMMER"]}\n\nTorvald (minjaesong)\n\n" +
|
("${Lang["CREDITS_PROGRAMMER"]}\n\nTorvald (minjaesong)\n\n\n" +
|
||||||
"${Lang["CREDITS_ARTIST_PLURAL"]}\n\nTorvald (minjaesong)\nRoundworld (leedonggeun)\n\n" +
|
"${Lang["CREDITS_ARTIST_PLURAL"]}\n\nTorvald (minjaesong)\nRoundworld (leedonggeun)\n\n\n" +
|
||||||
"${Lang["CREDITS_POLYGLOT"]}" +
|
"${Lang["CREDITS_POLYGLOT"]}\n\n\n" +
|
||||||
|
"${Lang["CREDITS_SOUNDTRACK"]}: FreeSound.org\n" +
|
||||||
"""
|
"""
|
||||||
|
Klankbeeld
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -144,21 +146,7 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
Kotlin translated and modified code Copyright (C) 2016 Minjaesong (Torvald)
|
Kotlin translated and modified code Copyright (C) 2016 Minjaesong (Torvald)
|
||||||
|
|
||||||
|
""").split('\n')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ambient sound recordings:
|
|
||||||
|
|
||||||
ambient_forest_01.ogg
|
|
||||||
ambient_meadow_01.ogg
|
|
||||||
ambient_windy_01.ogg
|
|
||||||
ambient_woods_01.ogg
|
|
||||||
crickets_01.ogg
|
|
||||||
crickets_02.ogg
|
|
||||||
|
|
||||||
Copyright (C) 2012, 2013, 2015, 2016, 2017 Klankbeeld
|
|
||||||
Sound from http://www.freesound.org/people/klankbeeld/""").split('\n')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -580,10 +580,12 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
blendNormal()
|
blendNormal()
|
||||||
|
|
||||||
BlocksDrawer.renderWall(batch)
|
BlocksDrawer.renderWall(batch)
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
actorsRenderBehind.forEach { it.drawBody(batch) }
|
actorsRenderBehind.forEach { it.drawBody(batch) }
|
||||||
particlesContainer.forEach { it.drawBody(batch) }
|
particlesContainer.forEach { it.drawBody(batch) }
|
||||||
BlocksDrawer.renderTerrain(batch)
|
BlocksDrawer.renderTerrain(batch)
|
||||||
@@ -591,9 +593,11 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
/////////////////
|
/////////////////
|
||||||
// draw actors //
|
// draw actors //
|
||||||
/////////////////
|
/////////////////
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
actorsRenderMiddle.forEach { it.drawBody(batch) }
|
actorsRenderMiddle.forEach { it.drawBody(batch) }
|
||||||
actorsRenderMidTop.forEach { it.drawBody(batch) }
|
actorsRenderMidTop.forEach { it.drawBody(batch) }
|
||||||
player.drawBody(batch)
|
player.drawBody(batch)
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
actorsRenderFront.forEach { it.drawBody(batch) }
|
actorsRenderFront.forEach { it.drawBody(batch) }
|
||||||
// --> Change of blend mode <-- introduced by childs of ActorWithBody //
|
// --> Change of blend mode <-- introduced by childs of ActorWithBody //
|
||||||
|
|
||||||
@@ -607,6 +611,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
FeaturesDrawer.drawEnvOverlay(batch)
|
FeaturesDrawer.drawEnvOverlay(batch)
|
||||||
|
|
||||||
|
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
|
|
||||||
|
|
||||||
// mix lighpmap canvas to this canvas (Colors -- RGB channel)
|
// mix lighpmap canvas to this canvas (Colors -- RGB channel)
|
||||||
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw
|
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw
|
||||||
setCameraPosition(0f, 0f)
|
setCameraPosition(0f, 0f)
|
||||||
@@ -634,6 +641,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
batch.shader = null
|
batch.shader = null
|
||||||
|
|
||||||
|
|
||||||
@@ -666,6 +674,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
blendNormal()
|
blendNormal()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// draw actor glows //
|
// draw actor glows //
|
||||||
//////////////////////
|
//////////////////////
|
||||||
@@ -675,10 +684,13 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
actorsRenderMiddle.forEach { it.drawGlow(batch) }
|
actorsRenderMiddle.forEach { it.drawGlow(batch) }
|
||||||
actorsRenderMidTop.forEach { it.drawGlow(batch) }
|
actorsRenderMidTop.forEach { it.drawGlow(batch) }
|
||||||
player.drawGlow(batch)
|
player.drawGlow(batch)
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
actorsRenderFront.forEach { it.drawGlow(batch) }
|
actorsRenderFront.forEach { it.drawGlow(batch) }
|
||||||
// --> blendNormal() <-- introduced by childs of ActorWithBody //
|
// --> blendNormal() <-- introduced by childs of ActorWithBody //
|
||||||
|
|
||||||
|
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
|
|
||||||
// mix lighpmap canvas to this canvas (UV lights -- A channel written on RGB as greyscale image)
|
// mix lighpmap canvas to this canvas (UV lights -- A channel written on RGB as greyscale image)
|
||||||
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw
|
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw
|
||||||
setCameraPosition(0f, 0f)
|
setCameraPosition(0f, 0f)
|
||||||
@@ -723,8 +735,8 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||||
glowTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
glowTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||||
|
|
||||||
worldTex.bind(0)
|
|
||||||
glowTex.bind(1)
|
glowTex.bind(1)
|
||||||
|
worldTex.bind(0)
|
||||||
|
|
||||||
|
|
||||||
Terrarum.shaderBlendGlow.begin()
|
Terrarum.shaderBlendGlow.begin()
|
||||||
@@ -735,11 +747,14 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
Terrarum.shaderBlendGlow.end()
|
Terrarum.shaderBlendGlow.end()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||||
|
|
||||||
|
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
blendNormal()
|
blendNormal()
|
||||||
|
|
||||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // reset active textureunit to zero (i don't know tbh, but it won't work without this)
|
|
||||||
batch.shader = null
|
batch.shader = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -751,6 +766,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
|
camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
|
||||||
batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
batch.inUse {
|
batch.inUse {
|
||||||
|
|
||||||
batch.shader = null
|
batch.shader = null
|
||||||
|
|
||||||
setCameraPosition(0f, 0f)
|
setCameraPosition(0f, 0f)
|
||||||
@@ -771,6 +787,8 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
// draw framebuffers to screen //
|
// draw framebuffers to screen //
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
|
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
|
||||||
blendedTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
blendedTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
@@ -780,6 +798,8 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// an old code.
|
// an old code.
|
||||||
/*batch.shader = null
|
/*batch.shader = null
|
||||||
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
|
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ object Terrarum : Screen {
|
|||||||
/**
|
/**
|
||||||
* To be used with physics simulator
|
* To be used with physics simulator
|
||||||
*/
|
*/
|
||||||
val TARGET_FPS: Double = 26.6666666666666666666666666 // lower value == faster gravity response (IT WON'T HOTSWAP!!)
|
val TARGET_FPS: Double = 26.0 + (2.0 / 3.0) // lower value == faster gravity response (IT WON'T HOTSWAP!!)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be used with render, to achieve smooth frame drawing
|
* To be used with render, to achieve smooth frame drawing
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
|||||||
val codomainSize = cameraNodes.size
|
val codomainSize = cameraNodes.size
|
||||||
val x = actor.hitbox.canonicalX.toFloat()
|
val x = actor.hitbox.canonicalX.toFloat()
|
||||||
|
|
||||||
val p1 = (x / (domainSize / codomainSize)).floorInt()
|
val p1 = (x / (domainSize / codomainSize)).floorInt() fmod cameraNodes.size
|
||||||
val p0 = (p1 - 1) fmod codomainSize
|
val p0 = ((p1 - 1) fmod codomainSize) fmod cameraNodes.size
|
||||||
val p2 = (p1 + 1) fmod codomainSize
|
val p2 = ((p1 + 1) fmod codomainSize) fmod cameraNodes.size
|
||||||
val p3 = (p1 + 2) fmod codomainSize
|
val p3 = ((p1 + 2) fmod codomainSize) fmod cameraNodes.size
|
||||||
val u: Float = 1f - (p2 - (x / (domainSize / codomainSize))) / (p2 - p1)
|
val u: Float = 1f - (p2 - (x / (domainSize / codomainSize))) / (p2 - p1)
|
||||||
|
|
||||||
//val targetYPos = FastMath.interpolateCatmullRom(u, catmullRomTension, cameraNodes[p0], cameraNodes[p1], cameraNodes[p2], cameraNodes[p3])
|
//val targetYPos = FastMath.interpolateCatmullRom(u, catmullRomTension, cameraNodes[p0], cameraNodes[p1], cameraNodes[p2], cameraNodes[p3])
|
||||||
@@ -254,6 +254,11 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderDemoWorld() {
|
private fun renderDemoWorld() {
|
||||||
|
println("camera TL: ${WorldCamera.x}, ${WorldCamera.y}")
|
||||||
|
println("camera CN: ${WorldCamera.gdxCamX}, ${WorldCamera.gdxCamY}")
|
||||||
|
println()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// draw skybox //
|
// draw skybox //
|
||||||
|
|
||||||
|
|||||||
@@ -405,8 +405,6 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
|||||||
|
|
||||||
|
|
||||||
displaceHitbox()
|
displaceHitbox()
|
||||||
//applyNormalForce()
|
|
||||||
//applyControllerMoveVelo() // TODO
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
hitbox.translate(externalForce)
|
hitbox.translate(externalForce)
|
||||||
@@ -1148,11 +1146,22 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
|||||||
private fun clampHitbox() {
|
private fun clampHitbox() {
|
||||||
val worldsizePxl = world.width.times(TILE_SIZE)
|
val worldsizePxl = world.width.times(TILE_SIZE)
|
||||||
|
|
||||||
|
// DEAR FUTURE ME,
|
||||||
|
//
|
||||||
|
// this code potentially caused a collision bug which only happens near the "edge" of the world.
|
||||||
|
//
|
||||||
|
// -- Signed, 2017-09-17
|
||||||
|
|
||||||
|
|
||||||
|
// wrap around for X-axis
|
||||||
|
val actorMinimumX = Terrarum.HALFW // to make camera's X stay positive
|
||||||
|
val actorMaximumX = worldsizePxl + actorMinimumX // to make camera's X stay positive
|
||||||
|
|
||||||
hitbox.setPositionFromPointed(
|
hitbox.setPositionFromPointed(
|
||||||
//clampW(hitbox.canonicalX),
|
//clampW(hitbox.canonicalX),
|
||||||
if (hitbox.canonicalX < 0)
|
if (hitbox.canonicalX < actorMinimumX)
|
||||||
hitbox.canonicalX + worldsizePxl
|
hitbox.canonicalX + worldsizePxl
|
||||||
else if (hitbox.canonicalX >= worldsizePxl)
|
else if (hitbox.canonicalX >= actorMaximumX)
|
||||||
hitbox.canonicalX - worldsizePxl
|
hitbox.canonicalX - worldsizePxl
|
||||||
else
|
else
|
||||||
hitbox.canonicalX, // ROUNDWORLD impl
|
hitbox.canonicalX, // ROUNDWORLD impl
|
||||||
|
|||||||
@@ -2,10 +2,7 @@ package net.torvald.terrarum.worlddrawer
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.*
|
||||||
import net.torvald.terrarum.gameactors.floor
|
|
||||||
import net.torvald.terrarum.gameactors.floorInt
|
|
||||||
import net.torvald.terrarum.gameactors.roundInt
|
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
import net.torvald.terrarum.round
|
import net.torvald.terrarum.round
|
||||||
|
|
||||||
@@ -19,25 +16,32 @@ object WorldCamera {
|
|||||||
private set
|
private set
|
||||||
var y: Int = 0 // top position
|
var y: Int = 0 // top position
|
||||||
private set
|
private set
|
||||||
var gdxCamX: Float = 0f // centre position
|
inline val gdxCamX: Float // centre position
|
||||||
private set
|
get() = xCentre.toFloat()
|
||||||
var gdxCamY: Float = 0f // centre position
|
inline val gdxCamY: Float// centre position
|
||||||
private set
|
get() = yCentre.toFloat()
|
||||||
var width: Int = 0
|
var width: Int = 0
|
||||||
private set
|
private set
|
||||||
var height: Int = 0
|
var height: Int = 0
|
||||||
private set
|
private set
|
||||||
val xCentre: Int
|
inline val xCentre: Int
|
||||||
get() = x + width.ushr(1)
|
get() = x + width.ushr(1)
|
||||||
val yCentre: Int
|
inline val yCentre: Int
|
||||||
get() = y + height.ushr(1)
|
get() = y + height.ushr(1)
|
||||||
|
|
||||||
fun update(world: GameWorld, player: ActorWithBody) {
|
fun update(world: GameWorld, player: ActorWithPhysics) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// FIXME player is stucked to the left (titlescreen AND ingame)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
width = FastMath.ceil(Terrarum.WIDTH / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul
|
width = FastMath.ceil(Terrarum.WIDTH / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul
|
||||||
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))
|
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))
|
||||||
|
|
||||||
// position - (WH / 2)
|
// TOP-LEFT position of camera border
|
||||||
x = player.hitbox.startX.toFloat().floorInt() // X only: ROUNDWORLD implementation
|
x = player.hitbox.centeredX.toFloat().minus(width / 2).floorInt() // X only: ROUNDWORLD implementation
|
||||||
y = (FastMath.clamp(
|
y = (FastMath.clamp(
|
||||||
player.hitbox.centeredY.toFloat() - height / 2,
|
player.hitbox.centeredY.toFloat() - height / 2,
|
||||||
TILE_SIZE.toFloat(),
|
TILE_SIZE.toFloat(),
|
||||||
@@ -45,9 +49,6 @@ object WorldCamera {
|
|||||||
)).floorInt().clampCameraY(world)
|
)).floorInt().clampCameraY(world)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gdxCamX = x + (width / 2f).floor()
|
|
||||||
gdxCamY = y + (height / 2f).floor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Int.clampCameraY(world: GameWorld): Int {
|
private fun Int.clampCameraY(world: GameWorld): Int {
|
||||||
|
|||||||
Reference in New Issue
Block a user