Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
l
2025-05-16 13:35:38 +00:00
parent 9ff433c257
commit 94870e65c2
9 changed files with 95 additions and 33 deletions

View File

@@ -2,6 +2,7 @@ package chess.view.DDDrender.world;
import java.io.IOException;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import chess.model.Coordinate;
@@ -45,4 +46,9 @@ public class BoardEntity extends Entity {
vao.close();
}
@Override
public Matrix4f getTransform() {
return null;
}
}

View File

@@ -2,10 +2,14 @@ package chess.view.DDDrender.world;
import java.io.Closeable;
import org.joml.Matrix4f;
import chess.view.DDDrender.Renderer;
public abstract class Entity implements Closeable{
public abstract void render(Renderer renderer);
public abstract Matrix4f getTransform();
}

View File

@@ -2,6 +2,7 @@ package chess.view.DDDrender.world;
import java.io.IOException;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import chess.view.DDDrender.DDDModel;
@@ -14,20 +15,24 @@ public class ModelEntity extends Entity {
protected float rotation;
protected DDDModel model;
private Matrix4f transform;
public ModelEntity(DDDModel model, Vector3f position, Vector3f color, float rotation) {
this.position = position;
this.color = color;
this.rotation = rotation;
this.model = model;
updateTransform();
}
@Override
public void render(Renderer renderer) {
renderer.Render(model, color, position, rotation);
renderer.Render(model, color, transform);
}
public void setPosition(Vector3f position) {
this.position = position;
updateTransform();
}
public void setColor(Vector3f color) {
@@ -36,6 +41,7 @@ public class ModelEntity extends Entity {
public void setRotation(float rotation) {
this.rotation = rotation;
updateTransform();
}
@Override
@@ -43,4 +49,13 @@ public class ModelEntity extends Entity {
this.model.close();
}
private void updateTransform() {
this.transform = new Matrix4f().translate(this.position).rotate(this.rotation, new Vector3f(0, 1, 0));
}
@Override
public Matrix4f getTransform() {
return transform;
}
}