Normand Briere
2019-08-16 64e20f390e4b8e58bd0006dde8fa10fba1dac1d5
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);
....@@ -9233,6 +9238,8 @@
92339238
92349239 void LoadEnvy(int which)
92359240 {
9241
+ assert(false);
9242
+
92369243 String name;
92379244 String ext;
92389245
....@@ -11077,18 +11084,34 @@
1107711084 //
1107811085 // newenvy = -1;
1107911086
11080
- if (object.skyboxname != null)
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1108111088 {
11082
- if (!object.skyboxname.equals(this.loadedskyboxname))
11089
+ if (cubemaprgb == null)
1108311090 {
11084
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
- loadedskyboxname = object.skyboxname;
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
1108611092 }
11093
+
11094
+ cubemap = cubemaprgb;
1108711095 }
1108811096 else
1108911097 {
11090
- cubemap = null;
11091
- 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;
1109211115 }
1109311116
1109411117 ratio = ((double) getWidth()) / getHeight();
....@@ -13396,8 +13419,12 @@
1339613419 program = programmin;
1339713420 }
1339813421
13399
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13400
- 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
+
1340113428 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1340213429
1340313430 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13444,7 +13471,8 @@
1344413471 "\n" +
1344513472 "END\n";
1344613473
13447
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13474
+ if (Globals.DEBUG)
13475
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1344813476 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1344913477
1345013478 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -14643,11 +14671,17 @@
1464314671 void GoDown(int mod)
1464414672 {
1464514673 MODIFIERS |= COMMAND;
14674
+ boolean isVR = (mouseMode&VR)!=0;
1464614675 /**/
1464714676 if((mod&SHIFT) == SHIFT)
14648
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14677
+ {
14678
+ if (isVR)
14679
+ manipCamera.RotateInterest(0, -speed);
14680
+ else
14681
+ manipCamera.RotatePosition(0, -speed);
14682
+ }
1464914683 else
14650
- manipCamera.RotatePosition(0, -speed);
14684
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1465114685 /**/
1465214686 if ((mod & SHIFT) == SHIFT)
1465314687 {
....@@ -14657,6 +14691,8 @@
1465714691 mouseMode |= BACKFORTH;
1465814692 }
1465914693
14694
+ targetLookAt.set(manipCamera.lookAt);
14695
+
1466014696 //prevX = X = anchorX;
1466114697 prevY = Y = anchorY - (int) (renderCamera.Distance());
1466214698 }
....@@ -14665,10 +14701,17 @@
1466514701 {
1466614702 MODIFIERS |= COMMAND;
1466714703 /**/
14704
+ boolean isVR = (mouseMode&VR)!=0;
14705
+
1466814706 if((mod&SHIFT) == SHIFT)
14669
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14707
+ {
14708
+ if (isVR)
14709
+ manipCamera.RotateInterest(0, speed);
14710
+ else
14711
+ manipCamera.RotatePosition(0, speed);
14712
+ }
1467014713 else
14671
- manipCamera.RotatePosition(0, speed);
14714
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1467214715 /**/
1467314716 if ((mod & SHIFT) == SHIFT)
1467414717 {
....@@ -14678,6 +14721,8 @@
1467814721 mouseMode |= BACKFORTH;
1467914722 }
1468014723
14724
+ targetLookAt.set(manipCamera.lookAt);
14725
+
1468114726 //prevX = X = anchorX;
1468214727 prevY = Y = anchorY + (int) (renderCamera.Distance());
1468314728 }
....@@ -14687,9 +14732,14 @@
1468714732 MODIFIERS |= COMMAND;
1468814733 /**/
1468914734 if((mod&SHIFT) == SHIFT)
14690
- manipCamera.Translate(speed*delta, 0, getWidth());
14735
+ manipCamera.Translate(speed*delta, 0, getWidth());
1469114736 else
14692
- manipCamera.RotatePosition(speed, 0);
14737
+ {
14738
+ if ((mouseMode&VR)!=0)
14739
+ manipCamera.RotateInterest(-speed, 0);
14740
+ else
14741
+ manipCamera.RotatePosition(speed, 0);
14742
+ }
1469314743 /**/
1469414744 if ((mod & SHIFT) == SHIFT)
1469514745 {
....@@ -14699,6 +14749,8 @@
1469914749 mouseMode |= ROTATE;
1470014750 } // TRANSLATE;
1470114751
14752
+ targetLookAt.set(manipCamera.lookAt);
14753
+
1470214754 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1470314755 prevY = Y = anchorY;
1470414756 }
....@@ -14708,9 +14760,15 @@
1470814760 MODIFIERS |= COMMAND;
1470914761 /**/
1471014762 if((mod&SHIFT) == SHIFT)
14711
- manipCamera.Translate(-speed*delta, 0, getWidth());
14763
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1471214764 else
14713
- manipCamera.RotatePosition(-speed, 0);
14765
+ {
14766
+ if ((mouseMode&VR)!=0)
14767
+ manipCamera.RotateInterest(speed, 0);
14768
+ else
14769
+ manipCamera.RotatePosition(-speed, 0);
14770
+ }
14771
+
1471414772 /**/
1471514773 if ((mod & SHIFT) == SHIFT)
1471614774 {
....@@ -14720,6 +14778,8 @@
1472014778 mouseMode |= ROTATE;
1472114779 } // TRANSLATE;
1472214780
14781
+ targetLookAt.set(manipCamera.lookAt);
14782
+
1472314783 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1472414784 prevY = Y = anchorY;
1472514785 }
....@@ -16104,7 +16164,7 @@
1610416164 {
1610516165 switch (hitSomething)
1610616166 {
16107
- case Object3D.hitCenter: gr.setColor(Color.pink);
16167
+ case Object3D.hitCenter: gr.setColor(Color.white);
1610816168 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1610916169 break;
1611016170 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -16130,7 +16190,7 @@
1613016190 if (hasMarquee)
1613116191 {
1613216192 gr.setXORMode(Color.white);
16133
- gr.setColor(Color.red);
16193
+ gr.setColor(Color.white);
1613416194 if (!firstime)
1613516195 {
1613616196 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16769,7 +16829,8 @@
1676916829 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1677016830
1677116831 cubemap.disable();
16772
- ////cubemap.unbind();
16832
+ //cubemap.dispose();
16833
+
1677316834 if (CULLFACE)
1677416835 {
1677516836 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17305,6 +17366,7 @@
1730517366
1730617367 public void init(GLAutoDrawable drawable)
1730717368 {
17369
+ if (Globals.DEBUG)
1730817370 System.out.println("shadow buffer init");
1730917371
1731017372 GL gl = drawable.getGL();
....@@ -17533,10 +17595,14 @@
1753317595 gl.glFlush();
1753417596
1753517597 /**/
17536
- 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);
1753717599
17538
- float[] pixels = occlusionsizebuffer.array();
17600
+ float[] depths = occlusiondepthbuffer.array();
1753917601
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
+
1754017606 double r = 0, g = 0, b = 0;
1754117607
1754217608 double count = 0;
....@@ -17547,7 +17613,7 @@
1754717613
1754817614 double FACTOR = 1;
1754917615
17550
- for (int i = 0; i < pixels.length; i++)
17616
+ for (int i = 0; i < depths.length; i++)
1755117617 {
1755217618 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1755317619 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17630,7 +17696,7 @@
1763017696
1763117697 double scale = ray.z; // 1; // cos
1763217698
17633
- float depth = pixels[newindex];
17699
+ float depth = depths[newindex];
1763417700
1763517701 /*
1763617702 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17827,11 +17893,14 @@
1782717893 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1782817894 static IntBuffer bigAAbuffer;
1782917895 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17830
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17896
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1783117897 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1783217898 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1783317899 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17834
- 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
+
1783517904 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1783617905 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1783717906 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();