84 lines
1.9 KiB
Java
84 lines
1.9 KiB
Java
package chess.view.DDDrender;
|
|
|
|
import org.joml.Matrix4f;
|
|
import org.joml.Vector3f;
|
|
|
|
public class Camera {
|
|
public static final float fov = 70.0f;
|
|
public static final float zNear = 0.01f;
|
|
public static final float zFar = 1000.0f;
|
|
|
|
private static final Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
|
|
private static final Vector3f center = new Vector3f(0.0f, 0.0f, 0.0f);
|
|
|
|
private final float distance = 1.5f;
|
|
private final float camHeight = 1.5f;
|
|
|
|
|
|
private float aspectRatio;
|
|
private float angle;
|
|
|
|
private Vector3f pos;
|
|
|
|
public Camera() {
|
|
this.pos = new Vector3f(0.0f, camHeight, 0.0f);
|
|
this.angle = 0.0f;
|
|
}
|
|
|
|
public void move(float x, float y) {
|
|
this.pos.x += x;
|
|
this.pos.y += y;
|
|
}
|
|
|
|
public void setRotateAngle(float angle) {
|
|
this.angle = angle;
|
|
updatePostion();
|
|
}
|
|
|
|
private void updatePostion() {
|
|
final float finalX = (float) Math.sin(angle);
|
|
final float finalZ = (float) -Math.cos(angle);
|
|
this.pos.set(distance * finalX, this.pos.get(1), distance * finalZ);
|
|
}
|
|
|
|
public float getRotateAngle() {
|
|
return angle;
|
|
}
|
|
|
|
public Vector3f getPos() {
|
|
return pos;
|
|
}
|
|
|
|
public float getFov() {
|
|
return fov;
|
|
}
|
|
|
|
public void setX(float x) {
|
|
this.pos.x = x;
|
|
}
|
|
|
|
public void setY(float y) {
|
|
this.pos.y = y;
|
|
}
|
|
|
|
public void setZ(float z) {
|
|
this.pos.z = z;
|
|
}
|
|
|
|
public void setPosition(Vector3f pos) {
|
|
this.pos = pos;
|
|
}
|
|
|
|
public void setAspectRatio(float aspectRatio) {
|
|
this.aspectRatio = aspectRatio;
|
|
}
|
|
|
|
public Matrix4f getPerspectiveMatrix() {
|
|
return new Matrix4f().perspective((float) (Math.toRadians(fov)), aspectRatio, zNear, zFar);
|
|
}
|
|
|
|
public Matrix4f getViewMatrix() {
|
|
return new Matrix4f().lookAt(pos, center, up);
|
|
}
|
|
}
|