From b3ae4e889872ca0b9ca76f1d17b2f0b961226729 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Mon, 05 Aug 2019 21:48:55 -0400 Subject: [PATCH] Fix physics UI --- CameraPane.java | 225 ++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 170 insertions(+), 55 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index fdb5f77..28e9ff5 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -187,6 +187,18 @@ } private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); + + public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException + { + try + { + cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); + } catch (IOException e) + { + System.out.println("NAME = " + name); + e.printStackTrace(); // throw new RuntimeException(e); + } + } void SetAsGLRenderer(boolean b) { @@ -1485,6 +1497,8 @@ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); } + float[] colorV = new float[4]; + void SetColor(Object3D obj, Vertex p0) { CameraPane display = this; @@ -1552,8 +1566,6 @@ { return; } - - float[] colorV = new float[3]; if (false) // marked) { @@ -8932,7 +8944,7 @@ if (cubemap == null) { - LoadEnvy(5); + //LoadEnvy(1); } //cubemap.enable(); @@ -9219,37 +9231,58 @@ cubemap = null; return; case 1: - name = "cubemaps/box_"; - ext = "png"; + name = "cubemaps/rgb/"; + ext = "jpg"; reverseUP = false; break; case 2: - name = "cubemaps/uffizi_"; - ext = "png"; - break; // reverseUP = true; break; + name = "cubemaps/uffizi/"; + ext = "jpg"; + reverseUP = false; + break; case 3: - name = "cubemaps/CloudyHills_"; - ext = "tga"; + name = "cubemaps/CloudyHills/"; + ext = "jpg"; reverseUP = false; break; case 4: - name = "cubemaps/cornell_"; + name = "cubemaps/cornell/"; ext = "png"; reverseUP = false; break; + case 5: + name = "cubemaps/skycube/"; + ext = "jpg"; + reverseUP = false; + break; + case 6: + name = "cubemaps/SaintLazarusChurch3/"; + ext = "jpg"; + reverseUP = false; + break; + case 7: + name = "cubemaps/Sodermalmsallen/"; + ext = "jpg"; + reverseUP = false; + break; + case 8: + name = "cubemaps/Sodermalmsallen2/"; + ext = "jpg"; + reverseUP = false; + break; + case 9: + name = "cubemaps/UnionSquare/"; + ext = "jpg"; + reverseUP = false; + break; default: - name = "cubemaps/rgb_"; - ext = "png"; /*mipmap = true;*/ reverseUP = false; + name = "cubemaps/box/"; + ext = "png"; /*mipmap = true;*/ + reverseUP = false; break; } - - try - { - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); - } catch (IOException e) - { - throw new RuntimeException(e); - } + + LoadSkybox(name, ext, mipmap); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) @@ -9281,8 +9314,12 @@ static double[] model = new double[16]; double[] camera2light = new double[16]; double[] light2camera = new double[16]; - int newenvy = -1; - boolean envyoff = true; // false; + + //int newenvy = -1; + //boolean envyoff = false; + + String loadedskyboxname; + cVector light0 = new cVector(0, 0, 0); // 1,3,2); //float[] light0 = { 0,0,0 }; cVector dirlight = new cVector(0, 0, 1); // 1,3,2); @@ -9762,10 +9799,12 @@ rati = 1 / rati; gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); } - assert (newenvy == -1); + + //assert (newenvy == -1); + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); - DrawSkyBox(gl); + DrawSkyBox(gl, (float)rati); gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); accPerspective(gl, renderCamera.shaper_fovy / ratio, @@ -11018,13 +11057,27 @@ gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); } - if (newenvy > -1) +// if (newenvy > -1) +// { +// LoadEnvy(newenvy); +// } +// +// newenvy = -1; + + if (object.skyboxname != null) { - LoadEnvy(newenvy); + if (!object.skyboxname.equals(this.loadedskyboxname)) + { + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); + loadedskyboxname = object.skyboxname; + } } - - newenvy = -1; - + else + { + cubemap = null; + loadedskyboxname = null; + } + ratio = ((double) getWidth()) / getHeight(); //System.out.println("ratio = " + ratio); @@ -11040,7 +11093,7 @@ if (!IsFrozen() && !ambientOcclusion) { - DrawSkyBox(gl); + DrawSkyBox(gl, (float)ratio); } //if (selection_view == -1) @@ -11326,7 +11379,7 @@ // if (cam != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 } LA.xformDir(lightposition, cam.toScreen, lightposition); @@ -12400,7 +12453,7 @@ //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); - String program = + String programmin = // Min shader "!!ARBfp1.0\n" + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + @@ -12451,7 +12504,8 @@ //"SUB ndotl.y, zero123.y, ndotl.y;" + //"MUL ndotl.y, ndotl.y, pow2.z;" + - "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient // Pigment "TEX temp, fragment.texcoord[0], texture[0], 2D;" + @@ -12466,7 +12520,7 @@ "MOV result.color, temp;" + "END"; - String program2 = + String programmax = "!!ARBfp1.0\n" + //"OPTION ARB_fragment_program_shadow;" + @@ -12991,7 +13045,7 @@ // display shadow only (fakedepth == 0) "SUB temp.x, half.x, shadow.x;" + "MOV temp.y, -params5.z;" + // params6.x;" + - "SLT temp.z, temp.y, -one2048th.x;" + + "SLT temp.z, temp.y, -c256i.x;" + "SUB temp.y, one.x, temp.z;" + "MUL temp.x, temp.x, temp.y;" + "KIL temp.x;" + @@ -13322,6 +13376,13 @@ //once = true; } + String program = programmax; + + if (Globals.MINSHADER) + { + program = programmin; + } + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); @@ -14571,9 +14632,9 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, -speed); - else manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); + else + manipCamera.RotatePosition(0, -speed); /**/ if ((mod & SHIFT) == SHIFT) { @@ -14592,9 +14653,9 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, speed); - else manipCamera.BackForth(0, speed*delta, 0); // getWidth()); + else + manipCamera.RotatePosition(0, speed); /**/ if ((mod & SHIFT) == SHIFT) { @@ -15315,20 +15376,24 @@ OCCLUSION_CULLING ^= true; System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); break; - case '0': envyoff ^= true; repaint(); break; + //case '0': envyoff ^= true; repaint(); break; case '1': case '2': case '3': case '4': case '5': - newenvy = Character.getNumericValue(key); - repaint(); - break; case '6': case '7': case '8': case '9': - BGcolor = (key - '6')/3.f; + if (true) // envyoff) + { + BGcolor = (key - '1')/8.f; + } + else + { + //newenvy = Character.getNumericValue(key); + } repaint(); break; case '!': @@ -16033,7 +16098,7 @@ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; case Object3D.hitScale: gr.setColor(Color.cyan); - gr.drawLine(X, Y, 0, 0); + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; } @@ -16519,6 +16584,8 @@ private /*static*/ boolean firstime; private /*static*/ cVector newView = new cVector(); private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, @@ -16531,29 +16598,66 @@ { com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); + int usedsuf = 0; + for (int i = 0; i < suffixes.length; i++) { - String resourceName = basename + suffixes[i] + "." + suffix; - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), - mipmapped, - FileUtil.getFileSuffix(resourceName)); - if (data == null) + String[] suffixe = suffixes; + String[] fallback = suffixes2; + String[] fallfallback = suffixes3; + + for (int c=usedsuf; --c>=0;) { - throw new IOException("Unable to load texture " + resourceName); +// String[] temp = suffixe; +// suffixe = fallback; +// fallback = fallfallback; +// fallfallback = temp; } + + String resourceName = basename + suffixe[i] + "." + suffix; + TextureData data; + + try + { + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + catch (Exception e) + { + try + { + resourceName = basename + fallback[i] + "." + suffix; + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + catch (Exception e2) + { + resourceName = basename + fallfallback[i] + "." + suffix; + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + } + //System.out.println("Target = " + targets[i]); cubemap.updateImage(data, targets[i]); } return cubemap; } + int bigsphere = -1; float BGcolor = 0.5f; - private void DrawSkyBox(GL gl) + float ambientLight[] = {1f, 1f, 1f, 1.0f}; + + private void DrawSkyBox(GL gl, float ratio) { - if (envyoff || cubemap == null) + if (//envyoff || + cubemap == null) { gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); gl.glClear(gl.GL_COLOR_BUFFER_BIT); @@ -16568,7 +16672,17 @@ // Compensates for ExaminerViewer's modification of modelview matrix gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); + gl.glScalef(1,ratio,1); +// colorV[0] = 2; +// colorV[1] = 2; +// colorV[2] = 2; +// colorV[3] = 1; +// gl.glDisable(gl.GL_COLOR_MATERIAL); +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); +// +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); + //gl.glActiveTexture(GL.GL_TEXTURE1); //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); @@ -16600,6 +16714,7 @@ { gl.glScalef(1.0f, -1.0f, 1.0f); } + gl.glScalef(-1.0f, 1.0f, 1.0f); gl.glMultMatrixd(viewrot_1, 0); gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); //viewer.updateInverseRotation(gl); @@ -16858,7 +16973,7 @@ //new Exception().printStackTrace(); System.out.println("select buffer init"); // Use debug pipeline - drawable.setGL(new DebugGL(drawable.getGL())); + //drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); -- Gitblit v1.6.2