From f9325048496d7cdbcad233f8a6b84c88e79adcc2 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Tue, 17 Sep 2019 20:11:47 -0400 Subject: [PATCH] Rename link2master to link2support. --- Camera.java | 137 ++++++++++++++++++++++++++++++++++++++------- 1 files changed, 114 insertions(+), 23 deletions(-) diff --git a/Camera.java b/Camera.java index f5243d4..9968d81 100644 --- a/Camera.java +++ b/Camera.java @@ -20,7 +20,7 @@ //<-2.2,0.7,-2> and pointed it at <-0.61,0.3,-0.6> // location = LA.newVector(2,0.7,-2); // lookAt = new cVector(0.6,0.3,-0.6); - location = LA.newVector(3,2,2); + location = LA.newVector(6,2,4); lookAt = new cVector(0.0,0.5,0); direction = new cVector(); toParent = LA.newMatrix(); @@ -52,7 +52,7 @@ perspective = true; break; case 1: // '\001' - location = LA.newVector(0, 0, 4); + location = LA.newVector(0, 0, 4); // Needed for translation direction perspective = false; break; case 2: // '\002' @@ -63,7 +63,7 @@ //LA.matXRotate(fromScreen, LA.toRadians(90)); break; case 3: // '\003' - location = LA.newVector(4, 0, 0); + location = LA.newVector(4, 0, 0); // Needed for translation direction //LA.matZRotate(toScreen, LA.toRadians(-90)); //LA.matXRotate(toScreen, LA.toRadians(-90)); //LA.matXRotate(fromScreen, LA.toRadians(90)); @@ -71,7 +71,7 @@ perspective = false; break; case 4: // Default light - location = LA.newVector(10, 30, 20); + location = LA.newVector(-5, 15, 10); perspective = false; break; } @@ -104,6 +104,15 @@ focalLength = 1; setAspect(4, 3); background = LA.newVector(0.8, 0.8, 0.8); + } + + void CreateMaterial(boolean multiply) + { + super.CreateMaterial(multiply); + + material.shift = 90; + material.cameralight = 0.2f; + material.shadowbias = 10; } void setAspect(int width, int height) @@ -150,6 +159,11 @@ void RotatePosition(float dx, float dy) { if(hAspect != 0) return; + + if (CameraPane.IMAGEFLIP) + { + dx = -dx; + } if (CameraPane.ROTATECAMERA) { @@ -207,6 +221,11 @@ void Translate(float dx, float dy, float scale) { if(hAspect != 0) return; + + if (CameraPane.IMAGEFLIP) + { + dx = -dx; + } if (CameraPane.ROTATECAMERA) { @@ -267,24 +286,34 @@ if (scale == 0) { // Zoom - LA.vecSub(location, lookAt, location); - - cVector p = location; - double factor = Math.exp(-dy/300.0); // (1 + dy/100); - p.x *= factor; - p.y *= factor; - p.z *= factor; + if (viewCode != 0) + { + LA.vecSub(location, lookAt, location); - LA.vecAdd(location, lookAt, location); + cVector p = location; + + p.x *= factor; + p.y *= factor; + p.z *= factor; + + LA.vecAdd(location, lookAt, location); + } + else + if (//shaper_fovy < 180 && factor > 1 || + shaper_fovy * factor < 150) + { + shaper_fovy *= factor; + //System.out.println("fovy = " + shaper_fovy); + } } else { LA.vecSub(location, lookAt, direction); //scale /= Distance(); - scale /= shaper_fovy/20; + // scale /= shaper_fovy/20; location.x -= dy * direction.x / scale; //location.y -= dy * direction.y / scale; @@ -305,19 +334,29 @@ void RotateInterest(float dx, float dy) { + right.mul(-1); + cStatic.point1.set(location); location.set(lookAt); lookAt.set(cStatic.point1); - right.mul(-1); + + 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); + + cStatic.point1.set(locationBuf); + locationBuf.set(lookAtBuf); + lookAtBuf.set(cStatic.point1); computeTransform(); } @@ -332,17 +371,52 @@ 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; + + locationBuf.y = location.y * K + locationBuf.y * (1 - K); + lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K); + + 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; @@ -352,6 +426,7 @@ LA.vecCross(away, up2, right2); if (!(right2.length2() > 0)) { + System.exit(0); // old problem... assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever up2.x = UP.x = 0; @@ -381,10 +456,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); @@ -396,9 +471,16 @@ LA.matConcat(fromScreen, rotate, fromScreen); //LA.matConcat(toScreen, rotate_1, toScreen); } + + if (CameraPane.IMAGEFLIP) + { + double[][] flip = { { -1,0,0,0 }, { 0,1,0,0}, { 0,0,1,0}, { 0,0,0,1 } }; + + LA.matConcat(fromScreen, flip, fromScreen); + } + //if (this == CameraPane.lightCamera) //CameraPane.lighttouched = true; - LA.matInvert(fromScreen, toScreen); } @@ -464,11 +546,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[][]; + + double[][] toScreen; + double[][] fromScreen; + boolean perspective; int hAspect = 0; // Free camera int vAspect; -- Gitblit v1.6.2