add world interface

This commit is contained in:
2025-04-27 11:00:14 +02:00
parent c488f3b4e0
commit 9bc09cf812
9 changed files with 235 additions and 71 deletions

View File

@@ -0,0 +1,9 @@
package chess.view.DDDrender.world;
import chess.view.DDDrender.Renderer;
public abstract class Entity {
public abstract void render(Renderer renderer);
}

View File

@@ -0,0 +1,55 @@
package chess.view.DDDrender.world;
import java.io.IOException;
import org.joml.Vector3f;
import chess.model.Piece;
import chess.view.DDDrender.DDDModel;
import chess.view.DDDrender.Renderer;
import chess.view.DDDrender.loader.Piece3DModel;
public class PieceEntity extends Entity {
private static final Piece3DModel modelLoader = new Piece3DModel();
private final Piece piece;
private Vector3f position;
private Vector3f color;
private float rotation;
private DDDModel model;
public PieceEntity(Piece piece, Vector3f position, Vector3f color, float rotation) {
this.piece = piece;
this.position = position;
this.color = color;
this.rotation = rotation;
try {
this.model = modelLoader.getModel(piece);
} catch (IOException e) {
e.printStackTrace();
}
}
public Piece getPiece() {
return piece;
}
@Override
public void render(Renderer renderer) {
renderer.Render(model, color, position, rotation);
}
public void setPosition(Vector3f position) {
this.position = position;
}
public void setColor(Vector3f color) {
this.color = color;
}
public void setRotation(float rotation) {
this.rotation = rotation;
}
}

View File

@@ -0,0 +1,40 @@
package chess.view.DDDrender.world;
import java.util.ArrayList;
import java.util.List;
import chess.model.Piece;
import chess.view.DDDrender.Camera;
public class World {
private final Camera camera;
private final List<Entity> entites;
public World(Camera camera) {
this.camera = camera;
this.entites = new ArrayList<>();
}
public PieceEntity getEntity(Piece piece) {
for (Entity entity : entites) {
if (entity instanceof PieceEntity p) {
if (p.getPiece() == piece)
return p;
}
}
return null;
}
public void addEntity(Entity entity) {
this.entites.add(entity);
}
public Camera getCamera() {
return camera;
}
public List<Entity> getEntites() {
return entites;
}
}