dev #12
@@ -2,9 +2,11 @@ package chess.view.DDDrender;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import chess.controller.commands.MoveCommand;
|
import chess.controller.commands.MoveCommand;
|
||||||
import chess.controller.event.GameListener;
|
import chess.controller.event.GameListener;
|
||||||
|
import imgui.ImGui;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
@@ -34,6 +36,9 @@ public class DDDView extends GameAdaptator implements GameListener {
|
|||||||
private final Camera camera;
|
private final Camera camera;
|
||||||
private Coordinate click = null;
|
private Coordinate click = null;
|
||||||
|
|
||||||
|
private static final float animationTime = 1.5f; // in seconds
|
||||||
|
private static final int animationTurns = 1;
|
||||||
|
|
||||||
public DDDView(CommandExecutor commandExecutor) {
|
public DDDView(CommandExecutor commandExecutor) {
|
||||||
this.commandExecutor = commandExecutor;
|
this.commandExecutor = commandExecutor;
|
||||||
this.world = new World();
|
this.world = new World();
|
||||||
@@ -195,9 +200,19 @@ public class DDDView extends GameAdaptator implements GameListener {
|
|||||||
this.window.OnCellClick.connect(this::onCellClick);
|
this.window.OnCellClick.connect(this::onCellClick);
|
||||||
this.window.OnCellEnter.connect(this::onCellEnter);
|
this.window.OnCellEnter.connect(this::onCellEnter);
|
||||||
this.window.OnCellExit.connect(this::onCellExit);
|
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 {
|
private void initBoard() throws IOException {
|
||||||
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
||||||
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
|
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());
|
Vector3f pieceWorldPos = new Vector3f(pieceBoardPos.x(), 0, pieceBoardPos.y());
|
||||||
this.world.getPiece(move.getStart()).setPosition(pieceWorldPos);
|
this.world.getPiece(move.getStart()).setPosition(pieceWorldPos);
|
||||||
this.world.movePiece(this.world.getPiece(move.getStart()), move);
|
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() {
|
public void run() {
|
||||||
// this.window.addRegularTask((delta) -> {
|
|
||||||
// final float angle = 1f;
|
|
||||||
// this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta);
|
|
||||||
// });
|
|
||||||
this.window.run();
|
this.window.run();
|
||||||
|
|
||||||
// free OpenGL resources
|
// free OpenGL resources
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package chess.view.DDDrender;
|
package chess.view.DDDrender;
|
||||||
|
|
||||||
|
import common.Signal0;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
import org.lwjgl.*;
|
import org.lwjgl.*;
|
||||||
import org.lwjgl.glfw.*;
|
import org.lwjgl.glfw.*;
|
||||||
@@ -53,6 +54,9 @@ public class Window implements Closeable {
|
|||||||
public final Signal1<Coordinate> OnCellEnter = new Signal1<>();
|
public final Signal1<Coordinate> OnCellEnter = new Signal1<>();
|
||||||
public final Signal1<Coordinate> OnCellExit = new Signal1<>();
|
public final Signal1<Coordinate> OnCellExit = new Signal1<>();
|
||||||
|
|
||||||
|
public final Signal0 OnImGuiTopRender = new Signal0();
|
||||||
|
public final Signal0 OnImGuiBottomRender = new Signal0();
|
||||||
|
|
||||||
public Window(Renderer renderer, World world, Camera camera) {
|
public Window(Renderer renderer, World world, Camera camera) {
|
||||||
this.renderer = new Renderer();
|
this.renderer = new Renderer();
|
||||||
this.cam = camera;
|
this.cam = camera;
|
||||||
@@ -65,6 +69,8 @@ public class Window implements Closeable {
|
|||||||
this.regularTasks.add(task);
|
this.regularTasks.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeRegularTask(Consumer<Float> task) {this.regularTasks.remove(task);}
|
||||||
|
|
||||||
public synchronized void scheduleTask(Runnable runnable) {
|
public synchronized void scheduleTask(Runnable runnable) {
|
||||||
this.tasks.add(runnable);
|
this.tasks.add(runnable);
|
||||||
}
|
}
|
||||||
@@ -225,12 +231,13 @@ public class Window implements Closeable {
|
|||||||
private void renderWindow() {
|
private void renderWindow() {
|
||||||
ImGui.showDemoWindow();
|
ImGui.showDemoWindow();
|
||||||
|
|
||||||
ImGui.begin("Hello");
|
ImGui.begin("Main Window");
|
||||||
ImGui.text("FPS : " + ImGui.getIO().getFramerate());
|
this.OnImGuiTopRender.emit();
|
||||||
ImVec2 mousePos = ImGui.getIO().getMousePos();
|
ImVec2 mousePos = ImGui.getIO().getMousePos();
|
||||||
ImVec2 framePos = ImGui.getCursorScreenPos();
|
ImVec2 framePos = ImGui.getCursorScreenPos();
|
||||||
checkCursor(mousePos.x - framePos.x, 800 - (mousePos.y - framePos.y), 800, 800);
|
checkCursor(mousePos.x - framePos.x, 800 - (mousePos.y - framePos.y), 800, 800);
|
||||||
ImGui.image(1, new ImVec2(800, 800));
|
ImGui.image(1, new ImVec2(800, 800));
|
||||||
|
this.OnImGuiBottomRender.emit();
|
||||||
ImGui.end();
|
ImGui.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user