Add BoundingBox interface to Camera
This commit is contained in:
@@ -6,6 +6,7 @@ import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.engine.core.gl.shader.constant.UniformName;
|
||||
import com.bartlomiejpluta.base.engine.world.object.Model;
|
||||
import com.bartlomiejpluta.base.internal.render.ShaderManager;
|
||||
import lombok.Getter;
|
||||
import org.joml.FrustumIntersection;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
@@ -16,6 +17,18 @@ public class DefaultCamera extends Model implements Camera {
|
||||
private final Matrix4f projectionViewMatrix = new Matrix4f();
|
||||
private final FrustumIntersection frustum = new FrustumIntersection();
|
||||
|
||||
@Getter
|
||||
private float minX = 0f;
|
||||
|
||||
@Getter
|
||||
private float maxX = 0f;
|
||||
|
||||
@Getter
|
||||
private float minY = 0f;
|
||||
|
||||
@Getter
|
||||
private float maxY = 0f;
|
||||
|
||||
@Override
|
||||
public Matrix4fc computeViewModelMatrix(Matrix4fc modelMatrix) {
|
||||
return new Matrix4f(viewMatrix).mul(modelMatrix);
|
||||
@@ -35,10 +48,13 @@ public class DefaultCamera extends Model implements Camera {
|
||||
|
||||
@Override
|
||||
public void render(Screen screen, ShaderManager shaderManager) {
|
||||
var screenWidth = screen.getWidth();
|
||||
var screenHeight = screen.getHeight();
|
||||
|
||||
// Update matrices
|
||||
projectionMatrix
|
||||
.identity()
|
||||
.setOrtho2D(0, screen.getWidth(), screen.getHeight(), 0);
|
||||
.setOrtho2D(0, screenWidth, screenHeight, 0);
|
||||
|
||||
viewMatrix
|
||||
.identity()
|
||||
@@ -51,6 +67,11 @@ public class DefaultCamera extends Model implements Camera {
|
||||
|
||||
frustum.set(projectionViewMatrix);
|
||||
|
||||
this.minX = position.x;
|
||||
this.maxX = position.x + screenWidth / scaleX;
|
||||
this.minY = position.y;
|
||||
this.maxY = position.y + screenHeight / scaleY;
|
||||
|
||||
shaderManager.setUniform(UniformName.UNI_PROJECTION_MATRIX, projectionMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user