feat: change board cells color
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package chess.view.DDDrender.world;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import chess.model.Coordinate;
|
||||
import chess.view.DDDrender.Renderer;
|
||||
import chess.view.DDDrender.loader.BoardModelLoader;
|
||||
import chess.view.DDDrender.opengl.VertexArray;
|
||||
import chess.view.DDDrender.opengl.VertexBuffer;
|
||||
|
||||
public class BoardEntity extends Entity {
|
||||
|
||||
private final VertexArray vao;
|
||||
private final VertexBuffer colorVbo;
|
||||
|
||||
private static final Vector3f WHITE = new Vector3f(1, 1, 1);
|
||||
private static final Vector3f BLACK = new Vector3f(0, 0, 0);
|
||||
|
||||
public BoardEntity() {
|
||||
this.vao = BoardModelLoader.GetBoardModel();
|
||||
this.colorVbo = this.vao.getVertexBuffers().get(1);
|
||||
}
|
||||
|
||||
public void setCellColor(Coordinate coord, Vector3f color) {
|
||||
float[] data = { color.x, color.y, color.z, color.x, color.y, color.z, color.x, color.y, color.z, color.x,
|
||||
color.y, color.z};
|
||||
int cellNumber = (Coordinate.VALUE_MAX - 1 - coord.getX()) * Coordinate.VALUE_MAX + Coordinate.VALUE_MAX - 1 - coord.getY();
|
||||
int offset = cellNumber * 4 * 4 * 3;
|
||||
this.colorVbo.UpdateData(offset, data);
|
||||
}
|
||||
|
||||
public void resetCellColor(Coordinate coord) {
|
||||
setCellColor(coord, (coord.getX() + coord.getY()) % 2 == 0 ? WHITE : BLACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Renderer renderer) {
|
||||
renderer.RenderVao(renderer.getBoardShader(), vao);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user