From ddb10cb84dddfeef1ef9946f2e13cef3c93e6cc4 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Wed, 20 Nov 2019 20:49:12 -0500 Subject: [PATCH] New maze --- CameraPane.java | 468 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 347 insertions(+), 121 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index e49e0a3..3edc07b 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -1,4 +1,5 @@ +import com.bulletphysics.dynamics.RigidBody; import java.awt.*; import java.awt.event.*; import java.awt.image.*; @@ -49,10 +50,12 @@ static int STEP = 1; + //static int[] pixels = new int[10000000]; + private static BufferedImage CreateBim(byte[] bytes, int width, int height) { int[] pixels = new int[bytes.length/3]; - for (int i=pixels.length; --i>=0;) + for (int i=bytes.length/3; --i>=0;) { int i3 = i*3; pixels[i] = 0xFF; @@ -123,7 +126,7 @@ static boolean LOCALTRANSFORM = false; static boolean FULLSCREEN = false; static boolean SUPPORT = true; -static boolean INERTIA = true; +static boolean INERTIA = false; // true; static boolean FAST = false; static boolean SLOWPOSE = false; static boolean FOOTCONTACT = true; @@ -192,6 +195,18 @@ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); + public void Jump2Target() + { + if (manipCamera.hAspect == 0) + { + tmp.set(targetLookAt); + tmp.sub(manipCamera.lookAt); + manipCamera.lookAt.add(tmp); + manipCamera.location.add(tmp); + manipCamera.computeTransform(); + } + } + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException { try @@ -249,7 +264,7 @@ public javax.media.opengl.GL GetGL0() { - return null; + return currentGL; } public int GenList() @@ -1529,7 +1544,7 @@ } } float b = 0; - if (obj.support != null && obj.link2master) + if (obj.support != null && obj.Link2Support()) { b = 1; } @@ -2177,9 +2192,18 @@ //SwitchCameras(); } + cVector origin = new cVector(); + void RevertCamera() { - SwapCamera(1, 0); + if (lightMode) + { + CreateSelectedPoint(); + selectedpoint.GetOrigin(origin); + lightCamera.setAim(new cVector(3,4,5), origin); + } + else + SwapCamera(1, 0); //SwitchCameras(); } @@ -2227,6 +2251,13 @@ // else repaint(); // start loop // may 2013 } + + public void ToggleAntialiasing() + { + CURRENTANTIALIAS = ((CURRENTANTIALIAS != 0) ? 0 : 1); + System.out.println("Antialias ACSIZE = " + ACSIZE); + System.out.println("CURRENTANTIALIAS = " + CURRENTANTIALIAS); + } public void ToggleSupport() { @@ -2272,6 +2303,7 @@ { IMAGEFLIP ^= true; } + public void ToggleSpeakerMocap() { @@ -3829,12 +3861,13 @@ switch (resolution) { - case 0: restarget = 256*256; break; - case 1: restarget = 512*512; break; - case 2: restarget = 1024*1024; break; - case 3: restarget = 2048*2048; break; - case 4: restarget = 4096*4096; break; - case 5: restarget = 8192*8192; break; + case 0: restarget = 128*128; break; + case 1: restarget = 256*256; break; + case 2: restarget = 512*512; break; + case 3: restarget = 1024*1024; break; + case 4: restarget = 2048*2048; break; + case 5: restarget = 4096*4096; break; + case 6: restarget = 8192*8192; break; } // restarget = 512*512; // 512*512; // 2048; // 512; // 1024; @@ -6961,30 +6994,30 @@ short residu = 0; // wraparound workarounds - short fuck = (short) (buffer[i] & 0xFF); + short ww = (short) (buffer[i] & 0xFF); /* - residu += (fuck%2); - if(fuck/2 < 256-residu/2) + residu += (ww%2); + if(ww/2 < 256-residu/2) { - fuck = (short)((fuck/2) + residu/2); + ww = (short)((ww/2) + residu/2); if(residu == 2) residu = 0; } else { residu = 0; - fuck /= 2; + ww /= 2; } */ - if (i < imglength / 3 || rnd.nextFloat() < 0.5 || fuck >= 254) + if (i < imglength / 3 || rnd.nextFloat() < 0.5 || ww >= 254) { - fuck /= 2; + ww /= 2; } else { - fuck = (short) ((fuck / 2) + fuck % 2); + ww = (short) ((ww / 2) + ww % 2); } - buffer[i] = (byte) fuck; + buffer[i] = (byte) ww; } //System.out.print(bytes[i] + " "); //if(buffer[i] >= 0 && buffer[i]<=eps-1) buffer[i] = eps; @@ -9366,7 +9399,9 @@ boolean pointselection = false; ///*static*/ boolean lighttouched = true; boolean deselect; - private boolean ambientOcclusion = false; + + static boolean ambientOcclusion = false; + static boolean flash = false; /*static*/ boolean wait = false; boolean displaydone = false; // after repaint() calls @@ -9618,7 +9653,7 @@ pixdx, pixdy, edx, edy, focus); } - static int ACSIZE = 4; // 16; + static int ACSIZE = 16; // 16; static int MAXACSIZE = 256; // 1024; static float[] jx8 = new float[MAXACSIZE]; static float[] jy8 = new float[MAXACSIZE]; @@ -9652,8 +9687,8 @@ void ResetOptions() { options1[0] = 100; - options1[1] = 0.025f; - options1[2] = 0.01f; + options1[1] = 0.01f; // .025f; + options1[2] = 3f; options1[3] = 0; options1[4] = 0; @@ -9993,7 +10028,7 @@ ext = "png"; Iterator iter = ImageIO.getImageWritersByFormatName(ext); if (iter.hasNext()) { - writer = (ImageWriter)iter.next(); + writer = (ImageWriter)iter.next(); } // patch for NULLE PART @@ -10760,7 +10795,9 @@ } /**/ - if (selection) + boolean control = ((modifiers & CTRL) != 0); + + if (selection && (!Globals.isLIVE() || control)) { selectbuffer.display(); return; @@ -10858,61 +10895,64 @@ { //pingthread.mute = true; - boolean keyon = false; - - if (keys[DOWN_ARROW]) + if (capsLocked) { - speed = ++speedkey[DOWN_ARROW]; - if (speed > 20) - speed = 20; - GoDown(modifiers); - keyon = true; - } - else - speedkey[DOWN_ARROW] = 0; + boolean keyon = false; - if (keys[UP_ARROW]) - { - speed = ++speedkey[UP_ARROW]; - if (speed > 20) - speed = 20; - GoUp(modifiers); - keyon = true; - } - else - speedkey[UP_ARROW] = 0; + if (keys[DOWN_ARROW]) + { + speed = ++speedkey[DOWN_ARROW]; + if (speed > 20) + speed = 20; + GoDown(modifiers); + keyon = true; + } + else + speedkey[DOWN_ARROW] = 0; - if (keys[LEFT_ARROW]) - { - speed = ++speedkey[LEFT_ARROW]; - if (speed > 20) - speed = 20; - GoLeft(modifiers); - keyon = true; - } - else - speedkey[LEFT_ARROW] = 0; + if (keys[UP_ARROW]) + { + speed = ++speedkey[UP_ARROW]; + if (speed > 20) + speed = 20; + GoUp(modifiers); + keyon = true; + } + else + speedkey[UP_ARROW] = 0; - if (keys[RIGHT_ARROW]) - { - speed = ++speedkey[RIGHT_ARROW]; - if (speed > 20) - speed = 20; - GoRight(modifiers); - keyon = true; - } - else - speedkey[RIGHT_ARROW] = 0; - - if (Globals.WALK && capsLocked) - { - Walk(); - keyon = true; - } - - if (keyon) - { - repaint(); + if (keys[LEFT_ARROW]) + { + speed = ++speedkey[LEFT_ARROW]; + if (speed > 20) + speed = 20; + GoLeft(modifiers); + keyon = true; + } + else + speedkey[LEFT_ARROW] = 0; + + if (keys[RIGHT_ARROW]) + { + speed = ++speedkey[RIGHT_ARROW]; + if (speed > 20) + speed = 20; + GoRight(modifiers); + keyon = true; + } + else + speedkey[RIGHT_ARROW] = 0; + + if (Globals.WALK) + { + Walk(); + keyon = true; + } + + if (keyon) + { + repaint(); + } } //pingthread.mute = false; @@ -11257,7 +11297,7 @@ //gl.glEnable(gl.GL_ALPHA_TEST); //gl.glActiveTexture(GL.GL_TEXTURE0); - if (!IsFrozen() && !ambientOcclusion) + if (!IsFrozen()) // && !ambientOcclusion) { DrawSkyBox(gl, (float)ratio); } @@ -11865,7 +11905,10 @@ } if (Globals.isLIVE() && DrawMode() == DEFAULT || pingthread.live) // may 2013 + { + renderCamera.computeTransform(); repaint(); + } displaydone = true; } @@ -14337,6 +14380,7 @@ public void mouseClicked(MouseEvent e) { System.out.println("mouseClicked: " + e); + System.exit(0); } public void mousePressed(MouseEvent e) @@ -14406,14 +14450,9 @@ int ay = anchorY; MODIFIERS &= ~COMMAND; mouseMode = 0; // autorepeat - tmp.set(targetLookAt); - tmp.sub(manipCamera.lookAt); - if (manipCamera.hAspect == 0) - { - manipCamera.lookAt.add(tmp); - manipCamera.location.add(tmp); - manipCamera.computeTransform(); - } + + Jump2Target(); + // int mode = WHEEL; // if (e.metaDown()) // { @@ -14421,7 +14460,7 @@ //} SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx()); - drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0); + drag(anchorX, anchorY + e.getUnitsToScroll()*8, e.getModifiers(), e.getModifiersEx()); anchorX = ax; anchorY = ay; prevX = px; @@ -14529,6 +14568,8 @@ { if (!wasliveok) return; + + Jump2Target(); AAtimer.restart(); // Globals.TIMERRUNNING = true; @@ -14648,7 +14689,7 @@ boolean jump; boolean live; - boolean mute; + boolean mute = false; // void JumpToTarget() // { @@ -14664,10 +14705,33 @@ // only one thread!? synchronized void StepToTarget(boolean jump) { + RigidBody.pos.x = 0; + RigidBody.pos.y = 0; + RigidBody.pos.z = 0; + if (RigidBody.justclicked) + { + RigidBody.pos.x = (float)manipCamera.lookAt.x; + RigidBody.pos.y = (float)manipCamera.lookAt.y; + RigidBody.pos.z = (float)manipCamera.lookAt.z; + // System.err.println("selected point = " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][1]) + " " + Trunk(selectedpoint.toParent[3][2])); + CreateSelectedPoint(); + +// RigidBody.pos.x = (float)selectedpoint.toParent[3][0]; +// RigidBody.pos.y = (float)selectedpoint.toParent[3][1]; +// RigidBody.pos.z = (float)selectedpoint.toParent[3][2]; +// +// RigidBody.wind.set(RigidBody.pos); +// RigidBody.wind.x -= (float)manipCamera.lookAt.x; +// RigidBody.wind.y -= (float)manipCamera.lookAt.y; +// RigidBody.wind.z -= (float)manipCamera.lookAt.z; +// RigidBody.wind.scale(-1); +// RigidBody.wind.normalize(); + } + if (mute) return; - if (capsLocked) + if (capsLocked && manipCamera.viewCode == 0) { eye.x = manipCamera.location.x; eye.y = manipCamera.location.y + 0.25; @@ -14958,8 +15022,28 @@ targetLookAt.set(manipCamera.lookAt); } + void ViewAngle(float dy) + { + double factor = Math.exp(-dy/300.0); // (1 + dy/100); + + if (manipCamera.shaper_fovy * factor > 1 && + manipCamera.shaper_fovy * factor < 150) + { + manipCamera.shaper_fovy *= factor; + //System.out.println("fovy = " + shaper_fovy); + } + } + void GoDown(int mod) { + LA.vecSub(manipCamera.location, manipCamera.lookAt, manipCamera.direction); + float scale = (float)manipCamera.direction.length() / 10; + + if (!capsLocked) + { + scale = 50; + } + MODIFIERS |= COMMAND; boolean isVR = (mouseMode&VR)!=0; /**/ @@ -14968,14 +15052,17 @@ // if (isVR) // manipCamera.RotateInterest(0, speed); // else - manipCamera.Translate(0, -speed*delta, getWidth()); + //if (isVR) + // ViewAngle(-speed*delta*scale); + //else + manipCamera.Translate(0, -speed*delta*scale, getWidth()); } else { if (isVR) - manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); + manipCamera.BackForth(0, -speed*delta*scale, isVR?1000:0); // getWidth()); else - manipCamera.RotatePosition(0, -speed); + manipCamera.RotatePosition(0, -speed*scale); } /**/ @@ -14995,6 +15082,16 @@ void GoUp(int mod) { + LA.vecSub(manipCamera.location, manipCamera.lookAt, manipCamera.direction); + float scale = (float)manipCamera.direction.length() / 10; + + if (!capsLocked) + { + scale = 50; + } + + RigidBody.justclicked = true; + MODIFIERS |= COMMAND; /**/ boolean isVR = (mouseMode&VR)!=0; @@ -15004,14 +15101,17 @@ // if (isVR) // manipCamera.RotateInterest(0, -speed); // else - manipCamera.Translate(0, speed*delta, getWidth()); + //if (isVR) + // ViewAngle(speed*delta*scale); + //else + manipCamera.Translate(0, speed*delta*scale, getWidth()); } else { if (isVR) - manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); + manipCamera.BackForth(0, speed*delta*scale, isVR?1000:0); // getWidth()); else - manipCamera.RotatePosition(0, speed); + manipCamera.RotatePosition(0, speed*scale); } /**/ @@ -15031,16 +15131,24 @@ void GoLeft(int mod) { + LA.vecSub(manipCamera.location, manipCamera.lookAt, manipCamera.direction); + float scale = (float)manipCamera.direction.length() / 10; + + if (!capsLocked) + { + scale = 50; + } + MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(speed*delta, 0, getWidth()); + manipCamera.Translate(speed*scale, 0, getWidth()); else { if ((mouseMode&VR)!=0) - manipCamera.RotateInterest(-speed, 0); + manipCamera.RotateInterest(-speed*scale*manipCamera.shaper_fovy/90, 0); else - manipCamera.RotatePosition(speed, 0); + manipCamera.RotatePosition(speed*scale*manipCamera.shaper_fovy/90, 0); } /**/ @@ -15063,16 +15171,24 @@ void GoRight(int mod) { + LA.vecSub(manipCamera.location, manipCamera.lookAt, manipCamera.direction); + float scale = (float)manipCamera.direction.length() / 10; + + if (!capsLocked) + { + scale = 50; + } + MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(-speed*delta, 0, getWidth()); + manipCamera.Translate(-speed*scale, 0, getWidth()); else { if ((mouseMode&VR)!=0) - manipCamera.RotateInterest(speed, 0); + manipCamera.RotateInterest(speed*scale*manipCamera.shaper_fovy/90, 0); else - manipCamera.RotatePosition(-speed, 0); + manipCamera.RotatePosition(-speed*scale*manipCamera.shaper_fovy/90, 0); } /**/ @@ -15219,6 +15335,11 @@ if ((mouseMode & ZOOM) != 0) { //if ((mouseMode & BACKFORTH) != 0) + if ((modifiersex & SHIFT) == SHIFT) + { + ViewAngle(dy); + } + else if ((mouseMode & VR) != 0) manipCamera.BackForth(dx, dy, getWidth()); else @@ -15320,6 +15441,12 @@ public void mouseReleased(MouseEvent e) { + if (isRenderer && !movingcamera) + { + RigidBody.justclicked = true; + System.out.println("justclicked: " + e); + } + Globals.MOUSEDRAGGED = false; movingcamera = false; @@ -15546,7 +15673,8 @@ { // Set the blank cursor to the JFrame. //object.editWindow.frame. - setCursor(blankCursor); + if (key == ENTER) // Globals.ADVANCED) + setCursor(blankCursor); // Contaminates other apps! if (key >= '0' && key <= '5') clampbit = (key-'0'); @@ -15631,11 +15759,9 @@ DISPLAYTEXT ^= true; repaint(); break; - case 'A': + //case 'A': case 'a': - CURRENTANTIALIAS = ((CURRENTANTIALIAS != 0) ? 0 : 1); - System.out.println("Antialias ACSIZE = " + ACSIZE); - System.out.println("CURRENTANTIALIAS = " + CURRENTANTIALIAS); + ToggleAntialiasing(); repaint(); break; case 'd': @@ -15739,6 +15865,8 @@ { //PrintMemory(); ToggleImageFlip(); + renderCamera.computeTransform(); + repaint(); break; } case 'M': @@ -15859,8 +15987,11 @@ // kompactbit = 6; // break; case ' ': - capsLocked ^= true; - repaint(); + if (manipCamera != lightCamera) + { + capsLocked ^= true; + repaint(); + } break; case 'l': lightMode ^= true; @@ -15923,10 +16054,10 @@ case ENTER: // object.editWindow.ScreenFit(); // Edit(); ToggleLive(); - if (capsLocked) - { - Globals.WALK ^= true; - } +// if (capsLocked) +// { +// Globals.WALK ^= true; +// } break; case DELETE: ClearSelection(); @@ -16011,8 +16142,13 @@ } repaint(); break; + case '.': + Globals.ONESTEP = true; + repaint(); + break; case BACKSPACE: - enablebackspace = true; + // almost working enablebackspace = true; + Globals.WALK ^= true; // SwitchCameras(false); repaint(); @@ -16044,10 +16180,61 @@ switch (e.getID()) { case KeyEvent.KEY_PRESSED: - keys[e.getKeyCode()] = true; - modifiers = e.getModifiersEx(); - keyPressed(e.getKeyChar(), modifiers); - //Globals.theRenderer.keyPressed(e.getKeyChar()); + + if (capsLocked) + { + keys[e.getKeyCode()] = true; + modifiers = e.getModifiersEx(); + keyPressed(e.getKeyChar(), modifiers); + //Globals.theRenderer.keyPressed(e.getKeyChar()); + } + else + { + if (manipCamera == lightCamera) + { + switch (e.getKeyCode()) + { + case DOWN_ARROW: + lightCamera.DECAL /= 2; + break; + case UP_ARROW: + lightCamera.DECAL *= 2; + break; + case LEFT_ARROW: + lightCamera.SCALE /= 2; + break; + case RIGHT_ARROW: + lightCamera.SCALE *= 2; + break; + default: + break; + } + + System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE); + } else + { + switch (e.getKeyCode()) + { + case DOWN_ARROW: + GoDown(e.getModifiersEx()); + break; + case UP_ARROW: + GoUp(e.getModifiersEx()); + break; + case LEFT_ARROW: + GoLeft(e.getModifiersEx()); + break; + case RIGHT_ARROW: + GoRight(e.getModifiersEx()); + break; + default: + modifiers = e.getModifiersEx(); + keyPressed(e.getKeyChar(), modifiers); + break; + } + } + } + repaint(); break; // if (!autorepeat) @@ -16717,7 +16904,8 @@ public boolean mouseDrag(Event evt, int x, int y) { - //System.out.println("mouseDrag: " + evt); + System.out.println("mouseDrag: " + evt); + System.exit(0); /* drag = true; //System.out.println("Mouse DRAG"); @@ -16836,6 +17024,7 @@ public boolean mouseUp(Event evt, int x, int y) { System.out.println("mouseUp: " + evt); + System.exit(0); /* locked = false; if (isRenderer) @@ -17106,7 +17295,7 @@ return; } - if (WIREFRAME) + //if (WIREFRAME) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL); gl.glDisable(gl.GL_CULL_FACE); @@ -17206,6 +17395,8 @@ if (WIREFRAME) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE); + else + gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL); } private void DrawChecker(GL gl) @@ -17969,7 +18160,14 @@ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); - int[] pixels = selectsizebuffer.array(); + int[] pixels = occlusioncolorbuffer.array(); + +// BufferedImage rendImage = new BufferedImage(OCCLUSION_SIZE, OCCLUSION_SIZE, BufferedImage.TYPE_INT_RGB); +// rendImage.setRGB(0,0, OCCLUSION_SIZE,OCCLUSION_SIZE, pixels, OCCLUSION_SIZE*(OCCLUSION_SIZE-1),-OCCLUSION_SIZE); +// +// Grafreed.SaveImage("testocclusion.jpg", rendImage, 0.5f); +// +// System.exit(0); double r = 0, g = 0, b = 0; @@ -17981,6 +18179,9 @@ double FACTOR = 1; + float minvalue = 1; + float maxvalue = 0; + for (int i = 0; i < depths.length; i++) { int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; @@ -18064,6 +18265,27 @@ double scale = ray.z; // 1; // cos + int pixel = pixels[newindex]; + + float value = (pixel&255) / 255.0f; + + pixel >>= 8; + + value += (pixel&255) / 255.0f; + + pixel >>= 8; + + value += (pixel&255) / 255.0f; + + value /= 3; + + if (minvalue > value) + minvalue = value; + if (maxvalue < value) + maxvalue = value; + + //scale *= value; + float depth = depths[newindex]; /* @@ -18100,6 +18322,8 @@ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]); double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR); + + factor *= value; r += factor * scale; g += factor * scale; @@ -18143,6 +18367,8 @@ stackdepth--; +// System.err.println("minvalue = " + minvalue); +// System.err.println("maxvalue = " + maxvalue); //System.err.println("depth = " + stackdepth); // DEBUG /* @@ -18210,7 +18436,7 @@ private boolean keepshadow; - public boolean capsLocked = false; // VR + static public boolean capsLocked = false; // VR static public int indexcount = 0; /*static*/ cColor vertexOcclusion = new cColor(); -- Gitblit v1.6.2