Skip to content

Commit

Permalink
bugfix: IllegalArgumentException in Camera.setFov() (issue #2078)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Oct 9, 2023
1 parent 68c4271 commit a94c37a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions jme3-core/src/main/java/com/jme3/input/FlyByCamera.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2021 jMonkeyEngine
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -383,9 +383,24 @@ protected void rotateCamera(float value, Vector3f axis) {
* @param value zoom amount
*/
protected void zoomCamera(float value) {
float newFov = cam.getFov() + value * 0.1F * zoomSpeed;
if (newFov > 0) {
cam.setFov(newFov);
if (cam.isParallelProjection()) {
float zoomFactor = 1.0F + value * 0.01F * zoomSpeed;
if (zoomFactor > 0F) {
float left = zoomFactor * cam.getFrustumLeft();
float right = zoomFactor * cam.getFrustumRight();
float top = zoomFactor * cam.getFrustumTop();
float bottom = zoomFactor * cam.getFrustumBottom();

float near = cam.getFrustumNear();
float far = cam.getFrustumFar();
cam.setFrustum(near, far, left, right, top, bottom);
}

} else { // perspective projection
float newFov = cam.getFov() + value * 0.1F * zoomSpeed;
if (newFov > 0) {
cam.setFov(newFov);
}
}
}

Expand Down

0 comments on commit a94c37a

Please sign in to comment.