From f868664f7e7626f651e6ade9c9f6863851ef43b7 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Wed, 06 Nov 2019 23:12:57 -0500 Subject: [PATCH] Dangerous "reset". --- Camera.java | 121 +++++++++++++++++++++++++++++++--------- 1 files changed, 94 insertions(+), 27 deletions(-) diff --git a/Camera.java b/Camera.java index e2f05a8..2bb124c 100644 --- a/Camera.java +++ b/Camera.java @@ -288,25 +288,15 @@ // Zoom double factor = Math.exp(-dy/300.0); // (1 + dy/100); - if (viewCode != 0) - { - LA.vecSub(location, lookAt, location); + LA.vecSub(location, lookAt, location); - cVector p = location; + cVector p = location; - p.x *= factor; - p.y *= factor; - p.z *= factor; + p.x *= factor; + p.y *= factor; + p.z *= factor; - LA.vecAdd(location, lookAt, location); - } - else - if (//shaper_fovy < 180 && factor > 1 || - shaper_fovy * factor < 180) - { - shaper_fovy *= factor; - //System.out.println("fovy = " + shaper_fovy); - } + LA.vecAdd(location, lookAt, location); } else { @@ -334,19 +324,35 @@ void RotateInterest(float dx, float dy) { + right.mul(-1); + cStatic.point1.set(location); location.set(lookAt); lookAt.set(cStatic.point1); - right.mul(-1); + + if (viewCode == 0 && locationBuf != null) + { + cStatic.point1.set(locationBuf); + locationBuf.set(lookAtBuf); + lookAtBuf.set(cStatic.point1); + } // UP.mul(-1); RotatePosition(dx,-dy); // UP.mul(-1); right.mul(-1); + cStatic.point1.set(location); location.set(lookAt); lookAt.set(cStatic.point1); + + if (viewCode == 0 && locationBuf != null) + { + cStatic.point1.set(locationBuf); + locationBuf.set(lookAtBuf); + lookAtBuf.set(cStatic.point1); + } computeTransform(); } @@ -361,33 +367,85 @@ fromScreen = LA.newMatrix(); } + if (locationBuf == null) + { + locationBuf = new cVector(); + locationBuf.set(location); + lookAtBuf = new cVector(); + lookAtBuf.set(lookAt); + upBuf = new cVector(); + upBuf.set(UP); +// up2Buf = new cVector(); +// up2Buf.set(UP2); + } + else + { + double K = 0.25; + + if (!CameraPane.capsLocked || CameraPane.ambientOcclusion) + K = 1; + + locationBuf.y = location.y * K + locationBuf.y * (1 - K); + lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K); + + int Y = 1; + + if (UP.y < 0) + Y = -1; + + UP.x = 0 * K + UP.x * (1 - K); + UP.y = Y * K + UP.y * (1 - K); + UP.z = 0 * K + UP.z * (1 - K); + UP.normalize(); + + if (CameraPane.capsLocked && !CameraPane.ambientOcclusion) + K = 0.1; + + upBuf.x = UP.x * K + upBuf.x * (1 - K); + upBuf.y = UP.y * K + upBuf.y * (1 - K); + upBuf.z = UP.z * K + upBuf.z * (1 - K); + upBuf.normalize(); +// up2Buf.x = UP2.x * K + up2Buf.x * (1 - K); +// up2Buf.y = UP2.y * K + up2Buf.y * (1 - K); +// up2Buf.z = UP2.z * K + up2Buf.z * (1 - K); + + K = 1; + + locationBuf.x = location.x * K + locationBuf.x * (1 - K); + locationBuf.z = location.z * K + locationBuf.z * (1 - K); + lookAtBuf.x = lookAt.x * K + lookAtBuf.x * (1 - K); + lookAtBuf.z = lookAt.z * K + lookAtBuf.z * (1 - K); + } + cVector up2 = up; cVector right2 = right; - up2.x = UP.x; - up2.y = UP.y; - up2.z = UP.z; - LA.vecSub(lookAt, location, away); + up2.x = upBuf.x; + up2.y = upBuf.y; + up2.z = upBuf.z; + LA.vecSub(lookAtBuf, locationBuf, away); LA.vecNormalize(away); LA.vecCross(away, up2, right2); if (right2.length2() < 0.0001) { + //System.out.println("right2.length2() < 0.0001"); // UP failed up2.x = UP2.x; up2.y = UP2.y; up2.z = UP2.z; - LA.vecSub(lookAt, location, away); - LA.vecNormalize(away); LA.vecCross(away, up2, right2); if (!(right2.length2() > 0)) { + System.out.println("NO UP VECTOR: " + up2); + System.out.println("lookAtBuf: " + lookAtBuf); + System.out.println("locationBuf: " + locationBuf); + System.exit(0); + // old problem... assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever up2.x = UP.x = 0; up2.y = UP.y = 1; up2.z = UP.z = 0; - LA.vecSub(lookAt, location, away); - LA.vecNormalize(away); LA.vecCross(away, up2, right2); } } @@ -410,10 +468,10 @@ } for (int i=0; i < 3; i++) - fromScreen[3][i] = location.get(i); + fromScreen[3][i] = locationBuf.get(i); for (int i=0; i < 3; i++) - temp[3][i] = -location.get(i); + temp[3][i] = -locationBuf.get(i); LA.matConcat(temp, toScreen, toScreen); @@ -500,11 +558,20 @@ static final int viewFront = 2; static final int viewSide = 3; int viewCode; + cVector location; cVector lookAt; + + transient cVector locationBuf; + transient cVector lookAtBuf; + transient cVector upBuf; + //transient cVector up2Buf; + cVector direction; + double[][] toScreen; double[][] fromScreen; + boolean perspective; int hAspect = 0; // Free camera int vAspect; -- Gitblit v1.6.2