optimize rendering
This commit is contained in:
@@ -70,10 +70,10 @@ public class Renderer implements Closeable {
|
||||
this.pieceShader.SetCamMatrix(cam);
|
||||
}
|
||||
|
||||
public void Render(DDDModel model, Vector3f color, Vector3f position, float rotation) {
|
||||
public void Render(DDDModel model, Vector3f color, Matrix4f transform) {
|
||||
this.pieceShader.Start();
|
||||
this.pieceShader.setModelColor(color);
|
||||
this.pieceShader.setModelTransform(new Matrix4f().translate(position).rotate(rotation, new Vector3f(0, 1, 0)));
|
||||
this.pieceShader.setModelTransform(transform);
|
||||
Render(model);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,15 +93,6 @@ public class Window implements Closeable {
|
||||
ImGui.destroyContext();
|
||||
}
|
||||
|
||||
private void setCallbacks() {
|
||||
glfwSetMouseButtonCallback(this.window, (window, button, action, mods) -> {
|
||||
if (button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS) {
|
||||
if (this.lastCell.isValid())
|
||||
this.OnCellClick.emit(this.lastCell);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initImGui() {
|
||||
ImGui.setCurrentContext(ImGui.createContext());
|
||||
|
||||
@@ -163,8 +154,6 @@ public class Window implements Closeable {
|
||||
|
||||
GL.createCapabilities();
|
||||
|
||||
setCallbacks();
|
||||
|
||||
initImGui();
|
||||
|
||||
renderer.Init();
|
||||
@@ -218,6 +207,11 @@ public class Window implements Closeable {
|
||||
this.OnCellEnter.emit(selectedCell);
|
||||
this.lastCell = selectedCell;
|
||||
}
|
||||
|
||||
if (ImGui.getIO().getMouseClicked(0)) {
|
||||
if (this.lastCell != null && this.lastCell.isValid())
|
||||
this.OnCellClick.emit(this.lastCell);
|
||||
}
|
||||
}
|
||||
|
||||
private void newFrame() {
|
||||
@@ -229,10 +223,10 @@ public class Window implements Closeable {
|
||||
}
|
||||
|
||||
private void renderWindow() {
|
||||
// ImGui.showDemoWindow();
|
||||
ImGui.showDemoWindow();
|
||||
|
||||
ImGui.begin("Hello");
|
||||
ImGui.button("test");
|
||||
ImGui.text("FPS : " + ImGui.getIO().getFramerate());
|
||||
ImVec2 mousePos = ImGui.getIO().getMousePos();
|
||||
ImVec2 framePos = ImGui.getCursorScreenPos();
|
||||
checkCursor(mousePos.x - framePos.x, 800 - (mousePos.y - framePos.y), 800, 800);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user