class documentation - a shitload of it
All checks were successful
Linux arm64 / Build (push) Successful in 33s

This commit is contained in:
2025-05-18 20:08:22 +02:00
parent 523eb094e1
commit 97950403a5
85 changed files with 378 additions and 94 deletions

View File

@@ -5,6 +5,9 @@ import org.joml.Vector2f;
import org.joml.Vector3f;
import org.joml.Vector4f;
/**
* 3D camera
*/
public class Camera {
public static final float fov = 70.0f;
public static final float zNear = 0.01f;
@@ -66,6 +69,9 @@ public class Camera {
return new Matrix4f().lookAt(pos, center, up);
}
/**
* Performs a ray casting to find the selected cell by the cursor
*/
public Vector2f getCursorWorldFloorPos(Vector2f screenPos, int windowWidth, int windowHeight) {
float relativeX = (screenPos.x / (float) windowWidth * 2.0f) - 1.0f;
float relativeY = 1.0f - (screenPos.y / (float) windowHeight * 2.0f);

View File

@@ -6,6 +6,9 @@ import java.util.List;
import chess.view.DDDrender.opengl.VertexArray;
/**
* OpenGL model.
*/
public class DDDModel implements Closeable {
private final List<VertexArray> vaos;

View File

@@ -4,7 +4,10 @@ import org.joml.Vector2f;
import chess.model.Coordinate;
class DDDPlacement {
/**
* Helper functions to convert from 2D to 3D coordinates systems.
*/
public class DDDPlacement {
public static Vector2f coordinatesToVector(Coordinate coo) {
return coordinatesToVector(coo.getX(), coo.getY());
}

View File

@@ -73,46 +73,38 @@ public class DDDView extends GameAdapter implements CommandSender {
if (this.click == null) { // case: first click
List<Coordinate> allowedMoves = getPieceAllowedMoves(coordinate);
if (allowedMoves.isEmpty()) { // case: no movement possible for piece
System.out.println("This piece cannot be moved at the moment.");
return;
}
setClick(coordinate);
previewMoves(coordinate);
// this.boardEntity.setCellColor(coordinate, BLUE);
System.out.println("First click on " + coordinate);
return;
}
// case: second click
GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(this.click);
if (sendCommand(movesCommand) == CommandResult.NotAllowed) { // case: invalid piece to move
cancelPreview(this.click);
System.out.println("Nothing to do here.");
cancelClick();
return;
}
List<Coordinate> allowedMoves = movesCommand.getDestinations();
if (allowedMoves.isEmpty()) { // case: no movement possible for piece
cancelPreview(this.click);
System.out.println("This piece cannot be moved at the moment.");
cancelClick();
return;
}
if (allowedMoves.contains(coordinate)) { // case: valid attempt to move
System.out.println("Move on " + coordinate);
cancelPreview(this.click);
sendMove(new Move(click, coordinate));
cancelClick();
return;
}
if (!(coordinate == this.click)) {
System.out.println("New click on " + coordinate); // cases: invalid move, selecting another piece
if (coordinate != this.click) { // cases: invalid move, selecting another piece
cancelPreview(this.click);
previewMoves(coordinate);
setClick(coordinate);
return;
}
System.out.println("Cancelling click."); // case: cancelling previous click
cancelClick();
cancelClick(); // case: cancelling previous click
}
private void previewMoves(Coordinate coordinate) {

View File

@@ -15,6 +15,9 @@ import chess.view.DDDrender.shader.BoardShader;
import chess.view.DDDrender.shader.PieceShader;
import chess.view.DDDrender.shader.ShaderProgram;
/**
* Basic 3D renderer
*/
public class Renderer implements Closeable {
private BoardShader boardShader;
private PieceShader pieceShader;

View File

@@ -37,6 +37,9 @@ import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
/**
* GLFW window.
*/
public class Window implements Closeable {
// The window handle

View File

@@ -15,6 +15,9 @@ import chess.model.pieces.Queen;
import chess.model.pieces.Rook;
import chess.view.DDDrender.DDDModel;
/**
* Visitor that returns the 3d model of a piece.
*/
public class Piece3DModel implements PieceVisitor<String> {
private static final String basePath = "3d/";

View File

@@ -11,6 +11,9 @@ import chess.view.DDDrender.loader.BoardModelLoader;
import chess.view.DDDrender.opengl.VertexArray;
import chess.view.DDDrender.opengl.VertexBuffer;
/**
* Abstraction of the 3D model of the board.
*/
public class BoardEntity extends Entity {
private final VertexArray vao;

View File

@@ -6,6 +6,9 @@ import org.joml.Matrix4f;
import chess.view.DDDrender.Renderer;
/**
* Abstract class for all entities in the 3D view.
*/
public abstract class Entity implements Closeable{
public abstract void render(Renderer renderer);

View File

@@ -8,6 +8,9 @@ import org.joml.Vector3f;
import chess.view.DDDrender.DDDModel;
import chess.view.DDDrender.Renderer;
/**
* Generic type for 3D model that can be rendered.
*/
public class ModelEntity extends Entity {
protected Vector3f position;

View File

@@ -7,6 +7,9 @@ import org.joml.Vector3f;
import chess.model.Piece;
import chess.view.DDDrender.loader.Piece3DModel;
/**
* Model entity of a piece. Loads the correct model of the resources files for the kind of piece.
*/
public class PieceEntity extends ModelEntity {
private static final Piece3DModel modelLoader = new Piece3DModel();

View File

@@ -9,6 +9,9 @@ import chess.model.Coordinate;
import chess.model.Move;
import chess.model.Piece;
/**
* Contains all 3D entities.
*/
public class World implements Closeable{
/** Renderable entity list */
private final List<Entity> entites;