add 3d position cache
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package chess.view.DDDrender.world;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import chess.view.DDDrender.DDDModel;
|
||||
import chess.view.DDDrender.Renderer;
|
||||
|
||||
public class ModelEntity extends Entity {
|
||||
|
||||
protected Vector3f position;
|
||||
protected Vector3f color;
|
||||
protected float rotation;
|
||||
protected DDDModel model;
|
||||
|
||||
public ModelEntity(DDDModel model, Vector3f position, Vector3f color, float rotation) {
|
||||
this.position = position;
|
||||
this.color = color;
|
||||
this.rotation = rotation;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,51 +5,21 @@ 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 {
|
||||
public class PieceEntity extends ModelEntity {
|
||||
|
||||
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) {
|
||||
public PieceEntity(Piece piece, Vector3f position, Vector3f color, float rotation) throws IOException {
|
||||
super(modelLoader.getModel(piece), position, color, 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,19 @@ package chess.view.DDDrender.world;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Piece;
|
||||
import chess.view.DDDrender.Camera;
|
||||
|
||||
public class World {
|
||||
private final Camera camera;
|
||||
/** Renderable entity list */
|
||||
private final List<Entity> entites;
|
||||
|
||||
public World(Camera camera) {
|
||||
this.camera = camera;
|
||||
/** provides fast access to 3d pieces */
|
||||
private final PieceEntity[] pieces;
|
||||
|
||||
public World() {
|
||||
this.entites = new ArrayList<>();
|
||||
this.pieces = new PieceEntity[Coordinate.VALUE_MAX * Coordinate.VALUE_MAX];
|
||||
}
|
||||
|
||||
public PieceEntity getEntity(Piece piece) {
|
||||
@@ -25,12 +28,21 @@ public class World {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addEntity(Entity entity) {
|
||||
this.entites.add(entity);
|
||||
public void addPiece(PieceEntity entity, Coordinate coordinate) {
|
||||
addEntity(entity);
|
||||
movePiece(entity, coordinate);
|
||||
}
|
||||
|
||||
public void movePiece(PieceEntity entity, Coordinate coordinate) {
|
||||
pieces[coordinate.toIndex()] = entity;
|
||||
}
|
||||
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
public PieceEntity getPiece(Coordinate coordinate) {
|
||||
return pieces[coordinate.toIndex()];
|
||||
}
|
||||
|
||||
public void addEntity(Entity entity) {
|
||||
this.entites.add(entity);
|
||||
}
|
||||
|
||||
public List<Entity> getEntites() {
|
||||
|
||||
Reference in New Issue
Block a user