Normand Briere
2019-08-16 83d0c2fa0bd2e96448f776144e1a89cdb1bb6998
CameraPane.java
....@@ -110,7 +110,11 @@
110110 //private Mat4f spotlightTransform = new Mat4f();
111111 //private Mat4f spotlightInverseTransform = new Mat4f();
112112 static GLContext glcontext = null;
113
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
114118 boolean reverseUP = false;
115119 static boolean frozen = false;
116120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +177,7 @@
173177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174178 boolean anisotropy = true;
175179 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177181
178182 boolean macromode = false;
179183
....@@ -188,15 +192,16 @@
188192
189193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190194
191
- public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192196 {
193197 try
194198 {
195
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196200 } catch (IOException e)
197201 {
198202 System.out.println("NAME = " + name);
199203 e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
200205 }
201206 }
202207
....@@ -2512,7 +2517,7 @@
25122517 com.sun.opengl.util.texture.TextureIO.newTextureData(
25132518 getClass().getClassLoader().getResourceAsStream(name),
25142519 true,
2515
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25162521 } catch (java.io.IOException e)
25172522 {
25182523 throw new javax.media.opengl.GLException(e);
....@@ -8778,10 +8783,12 @@
87788783
87798784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87808785 MAXSTACK = temp[0];
8781
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87828788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87838789 MAXSTACK = temp[0];
8784
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87858792
87868793 // Use debug pipeline
87878794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8789,7 +8796,8 @@
87898796 gl = drawable.getGL(); //
87908797
87918798 GL gl3 = getGL();
8792
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87938801
87948802
87958803 //float pos[] = { 100, 100, 100, 0 };
....@@ -9230,6 +9238,8 @@
92309238
92319239 void LoadEnvy(int which)
92329240 {
9241
+ assert(false);
9242
+
92339243 String name;
92349244 String ext;
92359245
....@@ -11074,18 +11084,34 @@
1107411084 //
1107511085 // newenvy = -1;
1107611086
11077
- if (object.skyboxname != null)
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1107811088 {
11079
- if (!object.skyboxname.equals(this.loadedskyboxname))
11089
+ if (cubemaprgb == null)
1108011090 {
11081
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
- loadedskyboxname = object.skyboxname;
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
1108311092 }
11093
+
11094
+ cubemap = cubemaprgb;
1108411095 }
1108511096 else
1108611097 {
11087
- cubemap = null;
11088
- loadedskyboxname = null;
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
1108911115 }
1109011116
1109111117 ratio = ((double) getWidth()) / getHeight();
....@@ -13393,8 +13419,12 @@
1339313419 program = programmin;
1339413420 }
1339513421
13396
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13397
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13422
+ if (Globals.DEBUG)
13423
+ {
13424
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13425
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13426
+ }
13427
+
1339813428 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1339913429
1340013430 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13441,7 +13471,8 @@
1344113471 "\n" +
1344213472 "END\n";
1344313473
13444
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13474
+ if (Globals.DEBUG)
13475
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1344513476 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1344613477
1344713478 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -14640,11 +14671,17 @@
1464014671 void GoDown(int mod)
1464114672 {
1464214673 MODIFIERS |= COMMAND;
14674
+ boolean isVR = (mouseMode&VR)!=0;
1464314675 /**/
1464414676 if((mod&SHIFT) == SHIFT)
14645
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14677
+ {
14678
+ if (isVR)
14679
+ manipCamera.RotateInterest(0, -speed);
14680
+ else
14681
+ manipCamera.RotatePosition(0, -speed);
14682
+ }
1464614683 else
14647
- manipCamera.RotatePosition(0, -speed);
14684
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1464814685 /**/
1464914686 if ((mod & SHIFT) == SHIFT)
1465014687 {
....@@ -14654,6 +14691,8 @@
1465414691 mouseMode |= BACKFORTH;
1465514692 }
1465614693
14694
+ targetLookAt.set(manipCamera.lookAt);
14695
+
1465714696 //prevX = X = anchorX;
1465814697 prevY = Y = anchorY - (int) (renderCamera.Distance());
1465914698 }
....@@ -14662,10 +14701,17 @@
1466214701 {
1466314702 MODIFIERS |= COMMAND;
1466414703 /**/
14704
+ boolean isVR = (mouseMode&VR)!=0;
14705
+
1466514706 if((mod&SHIFT) == SHIFT)
14666
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14707
+ {
14708
+ if (isVR)
14709
+ manipCamera.RotateInterest(0, speed);
14710
+ else
14711
+ manipCamera.RotatePosition(0, speed);
14712
+ }
1466714713 else
14668
- manipCamera.RotatePosition(0, speed);
14714
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1466914715 /**/
1467014716 if ((mod & SHIFT) == SHIFT)
1467114717 {
....@@ -14675,6 +14721,8 @@
1467514721 mouseMode |= BACKFORTH;
1467614722 }
1467714723
14724
+ targetLookAt.set(manipCamera.lookAt);
14725
+
1467814726 //prevX = X = anchorX;
1467914727 prevY = Y = anchorY + (int) (renderCamera.Distance());
1468014728 }
....@@ -14684,9 +14732,14 @@
1468414732 MODIFIERS |= COMMAND;
1468514733 /**/
1468614734 if((mod&SHIFT) == SHIFT)
14687
- manipCamera.Translate(speed*delta, 0, getWidth());
14735
+ manipCamera.Translate(speed*delta, 0, getWidth());
1468814736 else
14689
- manipCamera.RotatePosition(speed, 0);
14737
+ {
14738
+ if ((mouseMode&VR)!=0)
14739
+ manipCamera.RotateInterest(-speed, 0);
14740
+ else
14741
+ manipCamera.RotatePosition(speed, 0);
14742
+ }
1469014743 /**/
1469114744 if ((mod & SHIFT) == SHIFT)
1469214745 {
....@@ -14696,6 +14749,8 @@
1469614749 mouseMode |= ROTATE;
1469714750 } // TRANSLATE;
1469814751
14752
+ targetLookAt.set(manipCamera.lookAt);
14753
+
1469914754 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1470014755 prevY = Y = anchorY;
1470114756 }
....@@ -14705,9 +14760,15 @@
1470514760 MODIFIERS |= COMMAND;
1470614761 /**/
1470714762 if((mod&SHIFT) == SHIFT)
14708
- manipCamera.Translate(-speed*delta, 0, getWidth());
14763
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1470914764 else
14710
- manipCamera.RotatePosition(-speed, 0);
14765
+ {
14766
+ if ((mouseMode&VR)!=0)
14767
+ manipCamera.RotateInterest(speed, 0);
14768
+ else
14769
+ manipCamera.RotatePosition(-speed, 0);
14770
+ }
14771
+
1471114772 /**/
1471214773 if ((mod & SHIFT) == SHIFT)
1471314774 {
....@@ -14717,6 +14778,8 @@
1471714778 mouseMode |= ROTATE;
1471814779 } // TRANSLATE;
1471914780
14781
+ targetLookAt.set(manipCamera.lookAt);
14782
+
1472014783 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1472114784 prevY = Y = anchorY;
1472214785 }
....@@ -16101,7 +16164,7 @@
1610116164 {
1610216165 switch (hitSomething)
1610316166 {
16104
- case Object3D.hitCenter: gr.setColor(Color.pink);
16167
+ case Object3D.hitCenter: gr.setColor(Color.white);
1610516168 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1610616169 break;
1610716170 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -16127,7 +16190,7 @@
1612716190 if (hasMarquee)
1612816191 {
1612916192 gr.setXORMode(Color.white);
16130
- gr.setColor(Color.red);
16193
+ gr.setColor(Color.white);
1613116194 if (!firstime)
1613216195 {
1613316196 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16766,7 +16829,8 @@
1676616829 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1676716830
1676816831 cubemap.disable();
16769
- ////cubemap.unbind();
16832
+ //cubemap.dispose();
16833
+
1677016834 if (CULLFACE)
1677116835 {
1677216836 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17302,6 +17366,7 @@
1730217366
1730317367 public void init(GLAutoDrawable drawable)
1730417368 {
17369
+ if (Globals.DEBUG)
1730517370 System.out.println("shadow buffer init");
1730617371
1730717372 GL gl = drawable.getGL();
....@@ -17530,10 +17595,14 @@
1753017595 gl.glFlush();
1753117596
1753217597 /**/
17533
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17598
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1753417599
17535
- float[] pixels = occlusionsizebuffer.array();
17600
+ float[] depths = occlusiondepthbuffer.array();
1753617601
17602
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17603
+
17604
+ int[] pixels = selectsizebuffer.array();
17605
+
1753717606 double r = 0, g = 0, b = 0;
1753817607
1753917608 double count = 0;
....@@ -17544,7 +17613,7 @@
1754417613
1754517614 double FACTOR = 1;
1754617615
17547
- for (int i = 0; i < pixels.length; i++)
17616
+ for (int i = 0; i < depths.length; i++)
1754817617 {
1754917618 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1755017619 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17627,7 +17696,7 @@
1762717696
1762817697 double scale = ray.z; // 1; // cos
1762917698
17630
- float depth = pixels[newindex];
17699
+ float depth = depths[newindex];
1763117700
1763217701 /*
1763317702 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17824,11 +17893,14 @@
1782417893 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1782517894 static IntBuffer bigAAbuffer;
1782617895 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17827
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17896
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1782817897 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1782917898 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1783017899 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17831
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17900
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17901
+
17902
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17903
+
1783217904 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1783317905 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1783417906 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();