From 61025972eb983c1cfae8a2bb5d9d938c26743a98 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 8 Jan 2022 23:42:20 -0500 Subject: [PATCH] Plant launch lerp animation --- .../mindustry/graphics/g3d/PlanetParams.java | 4 ++++ .../mindustry/graphics/g3d/PlanetRenderer.java | 7 ++++++- core/src/mindustry/type/Planet.java | 3 ++- core/src/mindustry/ui/dialogs/PlanetDialog.java | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/graphics/g3d/PlanetParams.java b/core/src/mindustry/graphics/g3d/PlanetParams.java index 9116592fae..ee31f7d172 100644 --- a/core/src/mindustry/graphics/g3d/PlanetParams.java +++ b/core/src/mindustry/graphics/g3d/PlanetParams.java @@ -10,6 +10,10 @@ import mindustry.type.*; public class PlanetParams{ /** Camera direction relative to the planet. Length is determined by zoom. */ public Vec3 camPos = new Vec3(0f, 0f, 4f); + /** If not null, this is the position of the "previous" planet for smooth camera movement. */ + public @Nullable Vec3 otherCamPos; + /** Interpolation value for otherCamPos. */ + public float otherCamAlpha = 0f; /** Camera up vector. */ public Vec3 camUp = new Vec3(0f, 1f, 0f); /** the unit length direction vector of the camera **/ diff --git a/core/src/mindustry/graphics/g3d/PlanetRenderer.java b/core/src/mindustry/graphics/g3d/PlanetRenderer.java index dbdac3100b..f42e6ec7c8 100644 --- a/core/src/mindustry/graphics/g3d/PlanetRenderer.java +++ b/core/src/mindustry/graphics/g3d/PlanetRenderer.java @@ -69,7 +69,12 @@ public class PlanetRenderer implements Disposable{ cam.resize(w, h); params.camPos.setLength((params.planet.radius + params.planet.camRadius) * camLength + (params.zoom-1f) * (params.planet.radius + params.planet.camRadius) * 2); - cam.position.set(params.planet.position).add(params.camPos); + + if(params.otherCamPos != null){ + cam.position.set(params.otherCamPos).lerp(params.planet.position, params.otherCamAlpha).add(params.camPos); + }else{ + cam.position.set(params.planet.position).add(params.camPos); + } //cam.up.set(params.camUp); //TODO broken cam.lookAt(params.planet.position); cam.update(); diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index 064deb1077..3892cd0b6d 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -276,7 +276,8 @@ public class Planet extends UnlockableContent{ } } - launchCandidates = candidates; + //TODO currently, mutual launch candidates are simply a nuisance. + //launchCandidates = candidates; clipRadius = Math.max(clipRadius, radius + atmosphereRadOut + 0.5f); } diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index e57fb31e75..e2db4e670c 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -172,6 +172,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ rebuildButtons(); mode = look; + state.otherCamPos = null; selected = hovered = launchSector = null; launching = false; @@ -259,6 +260,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ //automatically select next planets; TODO pan! if(sector.planet.launchCandidates.size == 1){ state.planet = sector.planet.launchCandidates.first(); + state.otherCamPos = sector.planet.position; + state.otherCamAlpha = 0f; } //TODO pan over to correct planet @@ -284,6 +287,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ zoom = 1f; state.zoom = 1f; state.uiAlpha = 0f; + state.otherCamPos = null; launchSector = sector; mode = select; @@ -669,6 +673,19 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ public void act(float delta){ super.act(delta); + //update lerp + if(state.otherCamPos != null){ + state.otherCamAlpha = Mathf.lerpDelta(state.otherCamAlpha, 1f, 0.05f); + state.camPos.set(0f, camLength, 0.1f); + + if(Mathf.equal(state.otherCamAlpha, 1f, 0.01f)){ + //cam.position.set(params.otherCamPos).lerp(params.planet.position, params.otherCamAlpha).add(params.camPos); + state.camPos.set(Tmp.v31.set(state.otherCamPos).lerp(state.planet.position, state.otherCamAlpha).add(state.camPos).sub(state.planet.position)); + + state.otherCamPos = null; + } + } + if(hovered != null && !mobile && state.planet.hasGrid()){ addChild(hoverLabel); hoverLabel.toFront();