refactor
This commit is contained in:
@@ -8,16 +8,21 @@ public class Camera {
|
||||
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;
|
||||
|
||||
private float yaw = 0.0f;
|
||||
private float pitch = 0.0f;
|
||||
|
||||
public Camera() {
|
||||
this.pos = new Vector3f(1.5f, 1.5f, 0);
|
||||
setRotation(0.0f, -3.14150f / 2.0f);
|
||||
this.pos = new Vector3f(0.0f, camHeight, 0.0f);
|
||||
this.angle = 0.0f;
|
||||
}
|
||||
|
||||
public void move(float x, float y) {
|
||||
@@ -25,23 +30,25 @@ public class Camera {
|
||||
this.pos.y += y;
|
||||
}
|
||||
|
||||
public void rotate(float yaw, float pitch) {
|
||||
this.yaw += yaw;
|
||||
this.pitch += pitch;
|
||||
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 getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public float getFov() {
|
||||
return fov;
|
||||
}
|
||||
@@ -58,70 +65,19 @@ public class Camera {
|
||||
this.pos.z = z;
|
||||
}
|
||||
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
resetPosition();
|
||||
resetRotation();
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
pos = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
public void resetRotation() {
|
||||
yaw = 0.0f;
|
||||
pitch = 0.0f;
|
||||
}
|
||||
|
||||
public void moveForward(float distance) {
|
||||
pos.x += distance * (float) Math.cos(yaw);
|
||||
pos.y += distance * (float) Math.sin(yaw);
|
||||
}
|
||||
|
||||
public void moveRight(float distance) {
|
||||
pos.x += distance * (float) Math.cos(yaw);
|
||||
pos.y += distance * (float) Math.sin(yaw);
|
||||
}
|
||||
|
||||
public void moveUp(float distance) {
|
||||
pos.z += distance;
|
||||
}
|
||||
|
||||
public void moveDown(float distance) {
|
||||
pos.z -= distance;
|
||||
}
|
||||
|
||||
public void addYaw(float angle) {
|
||||
yaw += angle;
|
||||
}
|
||||
|
||||
public void addPitch(float angle) {
|
||||
pitch += angle;
|
||||
}
|
||||
|
||||
public void setPosition(Vector3f pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public void setRotation(float yaw, float pitch) {
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setAspectRatio(float aspectRatio) {
|
||||
this.aspectRatio = aspectRatio;
|
||||
}
|
||||
|
||||
public Matrix4f getMatrix() {
|
||||
return new Matrix4f()
|
||||
.perspective((float) (Math.toRadians(fov)), aspectRatio, zNear, zFar)
|
||||
.lookAt(pos, new Vector3f(0.0f, 0, 0), new Vector3f(0.0f, 1.0f, 0.0f));
|
||||
public Matrix4f getPerspectiveMatrix() {
|
||||
return new Matrix4f().perspective((float) (Math.toRadians(fov)), aspectRatio, zNear, zFar);
|
||||
}
|
||||
|
||||
public Matrix4f getViewMatrix() {
|
||||
return new Matrix4f().lookAt(pos, center, up);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user