From 6a145f6c81dfcbe0653eda27d042efb48daa7512 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Wed, 21 Aug 2019 21:05:56 -0400 Subject: [PATCH] Minor tuning --- CameraPane.java | 207 +++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 156 insertions(+), 51 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index 778fb13..f2785e4 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -113,6 +113,8 @@ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; + boolean transformMode; + boolean reverseUP = false; static boolean frozen = false; boolean enablebackspace = false; // patch for back buffer refresh @@ -166,7 +168,7 @@ // OPTIONS - boolean Skinshader = true; + boolean Skinshader = false; // true; boolean cameraLight = false; boolean UVdebug = false; boolean Udebug = false; @@ -540,7 +542,8 @@ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); LA.vecCross(obj.v0, obj.v1, obj.v2); LA.vecNormalize(obj.v2); - gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z); + + SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z); } // P @@ -562,7 +565,7 @@ y += ny * obj.NORMALPUSH; z += nz * obj.NORMALPUSH; - gl.glNormal3f(nx, ny, nz); + SetGLNormal(gl, nx, ny, nz); } gl.glColor4f(pv.AO, pv.AO, pv.AO, 1); SetColor(obj, pv); @@ -594,7 +597,7 @@ y += ny * obj.NORMALPUSH; z += nz * obj.NORMALPUSH; - gl.glNormal3f(nx, ny, nz); + SetGLNormal(gl, nx, ny, nz); } //System.out.println("vertexq = " + qv.s + ", " + qv.t); // boolean locked = false; @@ -642,7 +645,7 @@ y += ny * obj.NORMALPUSH; z += nz * obj.NORMALPUSH; - gl.glNormal3f(nx, ny, nz); + SetGLNormal(gl, nx, ny, nz); } // if ((dot&4) == 0) @@ -1248,10 +1251,10 @@ { if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) { - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); } else { - gl.glNormal3f(0, 0, 1); + SetGLNormal(gl, 0, 0, 1); } if (c != null) @@ -1275,10 +1278,10 @@ { if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) { - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); } else { - gl.glNormal3f(0, 0, 1); + SetGLNormal(gl, 0, 0, 1); } if (c != null) { @@ -1303,10 +1306,10 @@ { if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) { - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); } else { - gl.glNormal3f(0, 0, 1); + SetGLNormal(gl, 0, 0, 1); } if (c != null) { @@ -1488,7 +1491,7 @@ { if (!selectmode) { - gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z); + SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z); gl.glColor4f(pv.AO, pv.AO, pv.AO, 1); if (flipV) @@ -1817,7 +1820,7 @@ display.modelParams7[0] = 0; display.modelParams7[1] = 1000; - display.modelParams7[2] = 0; + display.modelParams7[2] = material.parallax; display.modelParams7[3] = 0; //display.modelParams6[0] = 100; // criss de bug de bump @@ -2050,9 +2053,9 @@ switch(viewcode) { case 0: return "main"; - case 1: return "one"; - case 2: return "two"; - case 3: return "three"; + case 1: return "Red"; + case 2: return "Green"; + case 3: return "Blue"; case 4: return "light"; } @@ -2473,6 +2476,18 @@ return CreateBim(bytes, width, height); } + private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz) + { + gl.glNormal3f(nx, ny, nz); + + if (ny > 0.9 || ny < -0.9) + // Ground or ceiling + gl.glVertexAttrib3f(4, 1, 0, 0); + else + // Walls + gl.glVertexAttrib3f(4, 0, 1, 0); + } + /**/ class CacheTexture { @@ -2515,7 +2530,7 @@ com.sun.opengl.util.texture.TextureIO.newTextureData( getClass().getClassLoader().getResourceAsStream(name), true, - com.sun.opengl.util.texture.TextureIO.PNG); + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); } catch (java.io.IOException e) { throw new javax.media.opengl.GLException(e); @@ -10688,9 +10703,18 @@ static boolean init = false; double[][] matrix = LA.newMatrix(); + + // This is to refresh the UI of the material panel. + ObjEditor patchMaterial; public void display(GLAutoDrawable drawable) { + if (patchMaterial.patchMaterial) + { + patchMaterial.patchMaterial = false; + patchMaterial.objectPanel.setSelectedIndex(1); + } + if (Grafreed.savesound && Grafreed.hassound) { Grafreed.wav.save(); @@ -11082,11 +11106,11 @@ // // newenvy = -1; - if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) { if (cubemaprgb == null) { - cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); } cubemap = cubemaprgb; @@ -11097,6 +11121,8 @@ { if (!object.skyboxname.equals(this.loadedskyboxname)) { + if (cubemap != null && cubemap != cubemaprgb) + cubemap.dispose(); cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); loadedskyboxname = object.skyboxname; } @@ -12580,7 +12606,7 @@ "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough - "PARAM params7 = program.env[7];" + // noise power, opacity power + "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax "PARAM options0 = program.env[63];" + // fog density, intensity, elevation "PARAM options1 = program.env[62];" + // fog rgb color "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen @@ -12825,7 +12851,7 @@ "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut // mar 2013 ??? "KIL alpha.a;" + "MOV alpha, texSamp.aaaa;" + // y;" + - "KIL alpha.a;" + + "KIL alpha.a;" + // not sure with parallax mapping /* "MUL temp.xy, temp, two;" + "TXB bump, temp, texture[0], 2D;" + @@ -12911,11 +12937,6 @@ "SUB bump0, bump0, half;" + "ADD bump, bump, bump0;" + - "MOV temp.x, texSamp.a;" + - "LRP texSamp, params5.x, texSamp, one;" + // texture proportion - //"LRP texSamp0, params5.x, texSamp0, one;" + - "MOV texSamp.a, temp.x;" + - // double-sided /**/ (doublesided?"DP3 temp.z, normal, eye;" + @@ -12932,19 +12953,62 @@ "MOV normald, normal;" + "MOV normals, normal;" + + "MOV temp, fragment.texcoord[4];" + + // UV base //"DP3 UP.x,state.matrix.modelview.row[0],Y;" + //"DP3 UP.y,state.matrix.modelview.row[1],Y;" + //"DP3 UP.z,state.matrix.modelview.row[2],Y;" + - "DP3 UP.x,state.matrix.texture[7].row[0],Y;" + - "DP3 UP.y,state.matrix.texture[7].row[1],Y;" + - "DP3 UP.z,state.matrix.texture[7].row[2],Y;" + + "DP3 UP.x,state.matrix.texture[7].row[0],temp;" + + "DP3 UP.y,state.matrix.texture[7].row[1],temp;" + + "DP3 UP.z,state.matrix.texture[7].row[2],temp;" + + Normalize("UP") + + "XPD V, normal, UP;" + Normalize("V") + "XPD U, V, normal;" + Normalize("U") + // parallax mapping + + "DP3 temp2.x, V, eye;" + + "DP3 temp2.y, U, eye;" + + "DP3 temp2.z, normal, eye;" + + "RCP temp2.z, temp2.z;" + + + "DP3 temp2.w, texSamp, texSamp;" + // Height + "RSQ temp2.w, temp2.w;" + + "RCP temp2.w, temp2.w;" + + + "SUB temp2.w, temp2.w, half;" + +// "SGE temp.x, temp2.w, eps.x;" + +// "MUL temp2.w, temp2.w, temp.x;" + + + //"MOV texSamp, U;" + + + "MUL temp2.z, temp2.z, temp2.w;" + + "MUL temp2.z, temp2.z, params7.z;" + // parallax + + "MUL temp2, temp2, temp2.z;" + + + "MOV temp, fragment.texcoord[0];" + + + "SUB temp, temp, temp2;" + + + "TEX temp, temp, texture[0], 2D;" + + "POW temp.a, temp.a, params6.w;" + // punch through + + "ADD texSamp, temp, texSamp;" + + "MUL texSamp.xyz, half, texSamp;" + + + "MOV alpha, texSamp.aaaa;" + + +// parallax mapping + + "MOV temp.x, texSamp.a;" + + "LRP texSamp, params5.x, texSamp, one;" + // texture proportion + //"LRP texSamp0, params5.x, texSamp0, one;" + + "MOV texSamp.a, temp.x;" + //"MOV temp, fragment.texcoord[0];" + // @@ -13415,8 +13479,12 @@ 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 " : "")); + if (Globals.DEBUG) + { + 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); //gl.glNewList(displayListID, GL.GL_COMPILE); @@ -13463,7 +13531,8 @@ "\n" + "END\n"; - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); + if (Globals.DEBUG) + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); //gl.glNewList(displayListID, GL.GL_COMPILE); @@ -13721,7 +13790,7 @@ /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough - /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power + /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax //Object3D.cVector2[] vector2buffer; @@ -13888,7 +13957,7 @@ "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" + "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" + "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" + - "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" + + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" + "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" + //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" + @@ -13949,7 +14018,7 @@ "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" + "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" + "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" + - //"MOV result.texcoord, vertex.texcoord;" + + //"MOV result.texcoord, vertex.fogcoord;" + "MOV result.texcoord, temp;" + // border fade "MOV result.texcoord[3], vertex.texcoord;" + @@ -13996,7 +14065,9 @@ //"ADD temp.z, temp.z, one;" + - "MOV result.color, temp;" + "MOV result.texcoord[4], vertex.attrib[4];" + // U dir + + "MOV result.color, temp;" // Normal : "MOV result.color, vertex.color;") + ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;" : "") + @@ -14662,11 +14733,17 @@ void GoDown(int mod) { MODIFIERS |= COMMAND; + boolean isVR = (mouseMode&VR)!=0; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); + { + if (isVR) + manipCamera.RotateInterest(0, -speed); + else + manipCamera.RotatePosition(0, -speed); + } else - manipCamera.RotatePosition(0, -speed); + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); /**/ if ((mod & SHIFT) == SHIFT) { @@ -14676,6 +14753,8 @@ mouseMode |= BACKFORTH; } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY - (int) (renderCamera.Distance()); } @@ -14684,10 +14763,17 @@ { MODIFIERS |= COMMAND; /**/ + boolean isVR = (mouseMode&VR)!=0; + if((mod&SHIFT) == SHIFT) - manipCamera.BackForth(0, speed*delta, 0); // getWidth()); + { + if (isVR) + manipCamera.RotateInterest(0, speed); + else + manipCamera.RotatePosition(0, speed); + } else - manipCamera.RotatePosition(0, speed); + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); /**/ if ((mod & SHIFT) == SHIFT) { @@ -14697,6 +14783,8 @@ mouseMode |= BACKFORTH; } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY + (int) (renderCamera.Distance()); } @@ -14706,9 +14794,14 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(speed*delta, 0, getWidth()); + manipCamera.Translate(speed*delta, 0, getWidth()); else - manipCamera.RotatePosition(speed, 0); + { + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(-speed, 0); + else + manipCamera.RotatePosition(speed, 0); + } /**/ if ((mod & SHIFT) == SHIFT) { @@ -14718,6 +14811,8 @@ mouseMode |= ROTATE; } // TRANSLATE; + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -14727,9 +14822,15 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(-speed*delta, 0, getWidth()); + manipCamera.Translate(-speed*delta, 0, getWidth()); else - manipCamera.RotatePosition(-speed, 0); + { + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(speed, 0); + else + manipCamera.RotatePosition(-speed, 0); + } + /**/ if ((mod & SHIFT) == SHIFT) { @@ -14739,6 +14840,8 @@ mouseMode |= ROTATE; } // TRANSLATE; + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -15241,8 +15344,8 @@ case 'K': KOMPACTTEXTURE ^= true; //textures.clear(); - break; - case 'P': // Texture Projection macros + // break; + //case 'P': // Texture Projection macros // SAVETEXTURE ^= true; macromode = true; Udebug = Vdebug = NORMALdebug = false; programInitialized = false; @@ -15363,7 +15466,7 @@ targetLookAt.set(manipCamera.lookAt); repaint(); break; - case 'p': + case 'P': // p': // c'est quoi ca au juste? spherical ^= true; Skinshader ^= true; programInitialized = false; repaint(); @@ -16123,7 +16226,7 @@ { switch (hitSomething) { - case Object3D.hitCenter: gr.setColor(Color.pink); + case Object3D.hitCenter: gr.setColor(Color.white); gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; case Object3D.hitRotate: gr.setColor(Color.yellow); @@ -16149,7 +16252,7 @@ if (hasMarquee) { gr.setXORMode(Color.white); - gr.setColor(Color.red); + gr.setColor(Color.white); if (!firstime) { gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); @@ -16788,7 +16891,8 @@ gl.glDisable(GL.GL_TEXTURE_GEN_R); cubemap.disable(); - ////cubemap.unbind(); + //cubemap.dispose(); + if (CULLFACE) { gl.glEnable(gl.GL_CULL_FACE); @@ -16844,7 +16948,7 @@ gl.glScalef(1.0f, -1.0f, 1.0f); } - gl.glNormal3f(0.0f, 0.0f, 1.0f); + SetGLNormal(gl, 0.0f, 0.0f, 1.0f); float step = 2; // 0.1666f; //0.25f; float stepv = 2; // step * 1652 / 998; @@ -17324,6 +17428,7 @@ public void init(GLAutoDrawable drawable) { + if (Globals.DEBUG) System.out.println("shadow buffer init"); GL gl = drawable.getGL(); -- Gitblit v1.6.2