feat: spinning turn

This commit is contained in:
fl.du.pr Grens
2025-05-16 16:20:48 +02:00
parent 94870e65c2
commit 6cec5d9e31
2 changed files with 44 additions and 6 deletions

View File

@@ -2,9 +2,11 @@ package chess.view.DDDrender;
import java.io.IOException;
import java.util.List;
import java.util.function.Consumer;
import chess.controller.commands.MoveCommand;
import chess.controller.event.GameListener;
import imgui.ImGui;
import org.joml.Vector2f;
import org.joml.Vector3f;
@@ -34,6 +36,9 @@ public class DDDView extends GameAdaptator implements GameListener {
private final Camera camera;
private Coordinate click = null;
private static final float animationTime = 1.5f; // in seconds
private static final int animationTurns = 1;
public DDDView(CommandExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
this.world = new World();
@@ -195,9 +200,19 @@ public class DDDView extends GameAdaptator implements GameListener {
this.window.OnCellClick.connect(this::onCellClick);
this.window.OnCellEnter.connect(this::onCellEnter);
this.window.OnCellExit.connect(this::onCellExit);
this.window.OnImGuiTopRender.connect(this::onHeaderRender);
this.window.OnImGuiBottomRender.connect(this::onFooterRender);
});
}
private void onHeaderRender() {
ImGui.text("FPS : " + ImGui.getIO().getFramerate());
}
private void onFooterRender() {
ImGui.button("Coucou");
}
private void initBoard() throws IOException {
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
@@ -229,13 +244,29 @@ public class DDDView extends GameAdaptator implements GameListener {
Vector3f pieceWorldPos = new Vector3f(pieceBoardPos.x(), 0, pieceBoardPos.y());
this.world.getPiece(move.getStart()).setPosition(pieceWorldPos);
this.world.movePiece(this.world.getPiece(move.getStart()), move);
cameraRotate();
}
private void cameraTick(float delta) {
int oddAnimationTurn = (2 * (animationTurns-1)) + 1;
final float angle = (float) Math.PI;
this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta * oddAnimationTurn / animationTime);
}
public void cameraRotate() {
float end = this.camera.getRotateAngle() + (float) Math.PI;
Consumer<Float> rotationConsumer = this::cameraTick;
this.window.addRegularTask(rotationConsumer);
try {
Thread.sleep((long) (animationTime * 1000));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
this.window.removeRegularTask(rotationConsumer);
this.camera.setRotateAngle(end);
}
public void run() {
// this.window.addRegularTask((delta) -> {
// final float angle = 1f;
// this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta);
// });
this.window.run();
// free OpenGL resources