From 2d549ea833f1945a906ce8fcb94d58d1e6caa7ae Mon Sep 17 00:00:00 2001 From: pspeed42 Date: Tue, 12 Aug 2014 17:56:56 -0400 Subject: [PATCH] Modified to keep its projectionMatrixOverride around to avoid garbage creation in setClipPlane(). --- .../main/java/com/jme3/renderer/Camera.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/Camera.java b/jme3-core/src/main/java/com/jme3/renderer/Camera.java index add8acc84..77b494d49 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/Camera.java +++ b/jme3-core/src/main/java/com/jme3/renderer/Camera.java @@ -195,7 +195,8 @@ public class Camera implements Savable, Cloneable { * store the value for field parallelProjection */ private boolean parallelProjection = true; - protected Matrix4f projectionMatrixOverride; + protected Matrix4f projectionMatrixOverride = new Matrix4f(); + private boolean overrideProjection; protected Matrix4f viewMatrix = new Matrix4f(); protected Matrix4f projectionMatrix = new Matrix4f(); protected Matrix4f viewProjectionMatrix = new Matrix4f(); @@ -328,15 +329,9 @@ public class Camera implements Savable, Cloneable { } this.parallelProjection = cam.parallelProjection; - if (cam.projectionMatrixOverride != null) { - if (this.projectionMatrixOverride == null) { - this.projectionMatrixOverride = cam.projectionMatrixOverride.clone(); - } else { - this.projectionMatrixOverride.set(cam.projectionMatrixOverride); - } - } else { - this.projectionMatrixOverride = null; - } + this.overrideProjection = cam.overrideProjection; + this.projectionMatrixOverride.set(cam.projectionMatrixOverride); + this.viewMatrix.set(cam.viewMatrix); this.projectionMatrix.set(cam.projectionMatrix); this.viewProjectionMatrix.set(cam.viewProjectionMatrix); @@ -395,7 +390,7 @@ public class Camera implements Savable, Cloneable { TempVars vars = TempVars.get(); try { - Matrix4f p = projectionMatrix.clone(); + Matrix4f p = projectionMatrixOverride.set(projectionMatrix); Matrix4f ivm = viewMatrix; @@ -1091,7 +1086,13 @@ public class Camera implements Savable, Cloneable { * @param projMatrix */ public void setProjectionMatrix(Matrix4f projMatrix) { - projectionMatrixOverride = projMatrix; + if (projMatrix == null) { + overrideProjection = false; + projectionMatrixOverride.loadIdentity(); + } else { + overrideProjection = true; + projectionMatrixOverride.set(projMatrix); + } updateViewProjection(); } @@ -1102,7 +1103,7 @@ public class Camera implements Savable, Cloneable { * of the camera. */ public Matrix4f getProjectionMatrix() { - if (projectionMatrixOverride != null) { + if (overrideProjection) { return projectionMatrixOverride; } @@ -1113,7 +1114,7 @@ public class Camera implements Savable, Cloneable { * Updates the view projection matrix. */ public void updateViewProjection() { - if (projectionMatrixOverride != null) { + if (overrideProjection) { viewProjectionMatrix.set(projectionMatrixOverride).multLocal(viewMatrix); } else { //viewProjectionMatrix.set(viewMatrix).multLocal(projectionMatrix);