mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +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 {
|
||||
|
||||
val credit: List<String>; get() =
|
||||
("${Lang["CREDITS_PROGRAMMER"]}\n\nTorvald (minjaesong)\n\n" +
|
||||
"${Lang["CREDITS_ARTIST_PLURAL"]}\n\nTorvald (minjaesong)\nRoundworld (leedonggeun)\n\n" +
|
||||
"${Lang["CREDITS_POLYGLOT"]}" +
|
||||
("${Lang["CREDITS_PROGRAMMER"]}\n\nTorvald (minjaesong)\n\n\n" +
|
||||
"${Lang["CREDITS_ARTIST_PLURAL"]}\n\nTorvald (minjaesong)\nRoundworld (leedonggeun)\n\n\n" +
|
||||
"${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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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')
|
||||
""").split('\n')
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -580,10 +580,12 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
|
||||
|
||||
batch.color = Color.WHITE
|
||||
blendNormal()
|
||||
|
||||
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) }
|
||||
particlesContainer.forEach { it.drawBody(batch) }
|
||||
BlocksDrawer.renderTerrain(batch)
|
||||
@@ -591,9 +593,11 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
/////////////////
|
||||
// draw actors //
|
||||
/////////////////
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||
actorsRenderMiddle.forEach { it.drawBody(batch) }
|
||||
actorsRenderMidTop.forEach { it.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) }
|
||||
// --> Change of blend mode <-- introduced by childs of ActorWithBody //
|
||||
|
||||
@@ -607,6 +611,9 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
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)
|
||||
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw
|
||||
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
|
||||
|
||||
|
||||
@@ -666,6 +674,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
blendNormal()
|
||||
|
||||
|
||||
|
||||
//////////////////////
|
||||
// draw actor glows //
|
||||
//////////////////////
|
||||
@@ -675,10 +684,13 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
actorsRenderMiddle.forEach { it.drawGlow(batch) }
|
||||
actorsRenderMidTop.forEach { it.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) }
|
||||
// --> 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)
|
||||
if (!KeyToggler.isOn(Input.Keys.F6)) { // F6 to disable lightmap draw
|
||||
setCameraPosition(0f, 0f)
|
||||
@@ -723,8 +735,8 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
glowTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
|
||||
worldTex.bind(0)
|
||||
glowTex.bind(1)
|
||||
worldTex.bind(0)
|
||||
|
||||
|
||||
Terrarum.shaderBlendGlow.begin()
|
||||
@@ -735,11 +747,14 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
Terrarum.shaderBlendGlow.end()
|
||||
|
||||
|
||||
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
|
||||
|
||||
|
||||
batch.inUse {
|
||||
batch.color = Color.WHITE
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -751,6 +766,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
camera.setToOrtho(true, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
|
||||
batch.projectionMatrix = camera.combined
|
||||
batch.inUse {
|
||||
|
||||
batch.shader = null
|
||||
|
||||
setCameraPosition(0f, 0f)
|
||||
@@ -771,6 +787,8 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
// draw framebuffers to screen //
|
||||
/////////////////////////////////
|
||||
|
||||
|
||||
|
||||
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
|
||||
blendedTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
batch.color = Color.WHITE
|
||||
@@ -780,6 +798,8 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// an old code.
|
||||
/*batch.shader = null
|
||||
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
|
||||
|
||||
@@ -108,7 +108,7 @@ object Terrarum : Screen {
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -72,10 +72,10 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
|
||||
val codomainSize = cameraNodes.size
|
||||
val x = actor.hitbox.canonicalX.toFloat()
|
||||
|
||||
val p1 = (x / (domainSize / codomainSize)).floorInt()
|
||||
val p0 = (p1 - 1) fmod codomainSize
|
||||
val p2 = (p1 + 1) fmod codomainSize
|
||||
val p3 = (p1 + 2) fmod codomainSize
|
||||
val p1 = (x / (domainSize / codomainSize)).floorInt() fmod cameraNodes.size
|
||||
val p0 = ((p1 - 1) fmod codomainSize) fmod cameraNodes.size
|
||||
val p2 = ((p1 + 1) fmod codomainSize) fmod cameraNodes.size
|
||||
val p3 = ((p1 + 2) fmod codomainSize) fmod cameraNodes.size
|
||||
val u: Float = 1f - (p2 - (x / (domainSize / codomainSize))) / (p2 - p1)
|
||||
|
||||
//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() {
|
||||
println("camera TL: ${WorldCamera.x}, ${WorldCamera.y}")
|
||||
println("camera CN: ${WorldCamera.gdxCamX}, ${WorldCamera.gdxCamY}")
|
||||
println()
|
||||
|
||||
|
||||
|
||||
// draw skybox //
|
||||
|
||||
|
||||
@@ -405,8 +405,6 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
|
||||
|
||||
displaceHitbox()
|
||||
//applyNormalForce()
|
||||
//applyControllerMoveVelo() // TODO
|
||||
}
|
||||
else {
|
||||
hitbox.translate(externalForce)
|
||||
@@ -1148,11 +1146,22 @@ open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val
|
||||
private fun clampHitbox() {
|
||||
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(
|
||||
//clampW(hitbox.canonicalX),
|
||||
if (hitbox.canonicalX < 0)
|
||||
if (hitbox.canonicalX < actorMinimumX)
|
||||
hitbox.canonicalX + worldsizePxl
|
||||
else if (hitbox.canonicalX >= worldsizePxl)
|
||||
else if (hitbox.canonicalX >= actorMaximumX)
|
||||
hitbox.canonicalX - worldsizePxl
|
||||
else
|
||||
hitbox.canonicalX, // ROUNDWORLD impl
|
||||
|
||||
@@ -2,10 +2,7 @@ package net.torvald.terrarum.worlddrawer
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.floor
|
||||
import net.torvald.terrarum.gameactors.floorInt
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.round
|
||||
|
||||
@@ -19,25 +16,32 @@ object WorldCamera {
|
||||
private set
|
||||
var y: Int = 0 // top position
|
||||
private set
|
||||
var gdxCamX: Float = 0f // centre position
|
||||
private set
|
||||
var gdxCamY: Float = 0f // centre 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
|
||||
val xCentre: Int
|
||||
inline val xCentre: Int
|
||||
get() = x + width.ushr(1)
|
||||
val yCentre: Int
|
||||
inline val yCentre: Int
|
||||
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
|
||||
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))
|
||||
|
||||
// position - (WH / 2)
|
||||
x = player.hitbox.startX.toFloat().floorInt() // X only: ROUNDWORLD implementation
|
||||
// TOP-LEFT position of camera border
|
||||
x = player.hitbox.centeredX.toFloat().minus(width / 2).floorInt() // X only: ROUNDWORLD implementation
|
||||
y = (FastMath.clamp(
|
||||
player.hitbox.centeredY.toFloat() - height / 2,
|
||||
TILE_SIZE.toFloat(),
|
||||
@@ -45,9 +49,6 @@ object WorldCamera {
|
||||
)).floorInt().clampCameraY(world)
|
||||
|
||||
|
||||
|
||||
gdxCamX = x + (width / 2f).floor()
|
||||
gdxCamY = y + (height / 2f).floor()
|
||||
}
|
||||
|
||||
private fun Int.clampCameraY(world: GameWorld): Int {
|
||||
|
||||
Reference in New Issue
Block a user