Skip to content

Commit

Permalink
Camera: trivial refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Aug 16, 2023
1 parent 1bab72b commit f018864
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/src/main/java/com/github/stephengold/vsport/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ public Camera setLocation(Vector3fc location) {
* @return the (modified) current instance (for chaining)
*/
public Camera setLookDirection(Vector3fc direction) {
this.azimuthRadians = FastMath.atan2(direction.z, direction.x);
float nxz = MyMath.hypotenuse(direction.x, direction.z);
this.upAngleRadians = FastMath.atan2(direction.y, nxz);
float y = direction.y();
float z = direction.z();
this.azimuthRadians = FastMath.atan2(z, direction.x());
float nxz = MyMath.hypotenuse(direction.x(), z);
this.upAngleRadians = FastMath.atan2(y, nxz);
updateDirectionVectors();

return this;
Expand Down Expand Up @@ -327,8 +329,11 @@ public float upAngle() {
* @param storeMatrix the matrix to update (not null, modified)
*/
void updateViewMatrix(Matrix4f storeMatrix) {
Vector3f tmpTarget = new Vector3f(eyeLocation).add(lookDirection);
storeMatrix.setLookAt(eyeLocation, tmpTarget, upDirection);
storeMatrix.setLookAt(eyeLocation.x, eyeLocation.y, eyeLocation.z,
eyeLocation.x + lookDirection.x,
eyeLocation.y + lookDirection.y,
eyeLocation.z + lookDirection.z,
upDirection.x, upDirection.y, upDirection.z);
}

/**
Expand Down

0 comments on commit f018864

Please sign in to comment.