dev #12
@@ -5,11 +5,11 @@ import org.joml.Vector3f;
|
|||||||
|
|
||||||
public class Camera {
|
public class Camera {
|
||||||
public static final float fov = 70.0f;
|
public static final float fov = 70.0f;
|
||||||
// should be changed to match screen
|
|
||||||
public static final float aspect = 1.0f;
|
|
||||||
public static final float zNear = 0.01f;
|
public static final float zNear = 0.01f;
|
||||||
public static final float zFar = 1000.0f;
|
public static final float zFar = 1000.0f;
|
||||||
|
|
||||||
|
private float aspectRatio;
|
||||||
|
|
||||||
private Vector3f pos;
|
private Vector3f pos;
|
||||||
|
|
||||||
private float yaw = 0.0f;
|
private float yaw = 0.0f;
|
||||||
@@ -115,14 +115,13 @@ public class Camera {
|
|||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4f getMatrix() {
|
public void setAspectRatio(float aspectRatio) {
|
||||||
Vector3f forward = new Vector3f(
|
this.aspectRatio = aspectRatio;
|
||||||
(float) (Math.cos(yaw) * Math.cos(pitch)),
|
}
|
||||||
(float) (Math.sin(pitch)),
|
|
||||||
(float) (Math.sin(yaw) * Math.cos(pitch)));
|
|
||||||
|
|
||||||
|
public Matrix4f getMatrix() {
|
||||||
return new Matrix4f()
|
return new Matrix4f()
|
||||||
.perspective((float) (Math.toRadians(fov)), aspect, zNear, zFar)
|
.perspective((float) (Math.toRadians(fov)), aspectRatio, zNear, zFar)
|
||||||
.lookAt(pos, new Vector3f(0.0f, 0, 0), new Vector3f(0.0f, 1.0f, 0.0f));
|
.lookAt(pos, new Vector3f(0.0f, 0, 0), new Vector3f(0.0f, 1.0f, 0.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ public class Window {
|
|||||||
float y = cam.getPos().z();
|
float y = cam.getPos().z();
|
||||||
cam.setPosition(new Vector3f(x * (float) Math.cos(angle) - y * (float) Math.sin(angle), 1.0f,
|
cam.setPosition(new Vector3f(x * (float) Math.cos(angle) - y * (float) Math.sin(angle), 1.0f,
|
||||||
x * (float) Math.sin(angle) + y * (float) Math.cos(angle)));
|
x * (float) Math.sin(angle) + y * (float) Math.cos(angle)));
|
||||||
|
int width[] = new int[1];
|
||||||
|
int height[] = new int[1];
|
||||||
|
glfwGetWindowSize(window, width, height);
|
||||||
|
cam.setAspectRatio((float) width[0] / (float) height[0]);
|
||||||
renderer.Render(cam);
|
renderer.Render(cam);
|
||||||
renderPieces();
|
renderPieces();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user