29 lines
770 B
Java
29 lines
770 B
Java
package de.jfritzsche.homegarden.gfx;
|
|
|
|
import de.jfritzsche.homegarden.math.Mat4;
|
|
import de.jfritzsche.homegarden.math.Vec3;
|
|
|
|
/**
|
|
* First-Person-Kamera. yaw=0 schaut Richtung -Z.
|
|
* pitch wird vom Controller geclamped (knapp unter +/-90 Grad).
|
|
*/
|
|
public final class Camera {
|
|
public final Vec3 position = new Vec3(0, 0, 0);
|
|
public float yaw = 0f;
|
|
public float pitch = 0f;
|
|
|
|
public Vec3 forward() {
|
|
float cp = (float) Math.cos(pitch);
|
|
return new Vec3(
|
|
-(float) Math.sin(yaw) * cp,
|
|
(float) Math.sin(pitch),
|
|
-(float) Math.cos(yaw) * cp
|
|
);
|
|
}
|
|
|
|
public Mat4 viewMatrix() {
|
|
Vec3 center = position.add(forward());
|
|
return Mat4.lookAt(position, center, new Vec3(0, 1, 0));
|
|
}
|
|
}
|