Normand Briere
2019-04-22 4a5b9e0b9ecc97203d4089ca0cd0d6df8c76bf1c
CameraPane.java
....@@ -149,12 +149,11 @@
149149 defaultcaps.setAccumBlueBits(16);
150150 defaultcaps.setAccumAlphaBits(16);
151151 }
152
- static CameraPane theRenderer;
153
-
152
+
154153 void SetAsGLRenderer(boolean b)
155154 {
156155 isRenderer = b;
157
- theRenderer = this;
156
+ Globals.theRenderer = this;
158157 }
159158
160159 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -236,9 +235,14 @@
236235 return this.ambientOcclusion;
237236 }
238237
238
+ public boolean IsDebugSelection()
239
+ {
240
+ return DEBUG_SELECTION;
241
+ }
242
+
239243 public boolean IsFrozen()
240244 {
241
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
245
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
242246
243247 return !selectmode && cameracount == 0; // != 0;
244248 }
....@@ -259,9 +263,19 @@
259263 return lightCamera;
260264 }
261265
266
+ public Camera ManipCamera()
267
+ {
268
+ return manipCamera;
269
+ }
270
+
262271 public Camera RenderCamera()
263272 {
264273 return renderCamera;
274
+ }
275
+
276
+ public Camera[] Cameras()
277
+ {
278
+ return cameras;
265279 }
266280
267281 public void PushMaterial(Object3D obj, boolean selected)
....@@ -408,7 +422,7 @@
408422
409423 javax.media.opengl.GL gl = display.GetGL();
410424
411
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
425
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
412426
413427 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
414428 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
....@@ -760,6 +774,291 @@
760774 //// tris.postdraw(this);
761775 }
762776
777
+ static Camera localcamera = new Camera();
778
+ static cVector from = new cVector();
779
+ static cVector to = new cVector();
780
+
781
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
782
+ {
783
+ CameraPane cp = this;
784
+
785
+ Camera keep = cp.RenderCamera();
786
+ cp.renderCamera = localcamera;
787
+
788
+ if (br.trimmed)
789
+ {
790
+ float[] colors = new float[br.positions.length / 3];
791
+
792
+ int i3 = 0;
793
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
794
+ {
795
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
796
+ continue;
797
+
798
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
799
+ to.set(br.positions[i3] + br.normals[i3],
800
+ br.positions[i3 + 1] + br.normals[i3 + 1],
801
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
802
+ LA.xformPos(from, transform, from);
803
+ LA.xformPos(to, transform, to); // RIGID ONLY
804
+ localcamera.setAim(from, to);
805
+
806
+ CameraPane.occlusionbuffer.display();
807
+
808
+ if (CameraPane.DEBUG_OCCLUSION)
809
+ cp.display(); // debug
810
+
811
+ colors[i] = cp.vertexOcclusion.r;
812
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
813
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
814
+
815
+ if ((i % 100) == 0 && i != 0)
816
+ {
817
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
818
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
819
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
820
+ }
821
+ }
822
+
823
+ br.colors = colors;
824
+ }
825
+ else
826
+ {
827
+ for (int i = 0; i < br.VertexCount(); i++)
828
+ {
829
+ Vertex v = br.GetVertex(i);
830
+
831
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
832
+ continue;
833
+
834
+ from.set(v.x, v.y, v.z);
835
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
836
+ LA.xformPos(from, transform, from);
837
+ LA.xformPos(to, transform, to); // RIGID ONLY
838
+ localcamera.setAim(from, to);
839
+
840
+ CameraPane.occlusionbuffer.display();
841
+
842
+ if (CameraPane.DEBUG_OCCLUSION)
843
+ cp.display(); // debug
844
+
845
+ v.AO = cp.vertexOcclusion.r;
846
+
847
+ if ((i % 100) == 0 && i != 0)
848
+ {
849
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
850
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
851
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
852
+ }
853
+ }
854
+ }
855
+
856
+ //System.out.println("done.");
857
+
858
+ cp.renderCamera = keep;
859
+ }
860
+
861
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
862
+ {
863
+ CameraPane display = this;
864
+ pointFlow.CreateHT();
865
+
866
+ float r = display.modelParams0[0];
867
+ float g = display.modelParams0[1];
868
+ float b = display.modelParams0[2];
869
+ float opacity = display.modelParams5[1];
870
+
871
+ //final GL gl = GLU.getCurrentGL();
872
+ GL gl = display.GetGL(); // getGL();
873
+
874
+ int s = pointFlow.points.size();
875
+
876
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
877
+ gl.glEnable(gl.GL_CULL_FACE);
878
+
879
+ for (int i=s; --i>=0;)
880
+ //for (int i=0; i<s; i++)
881
+ {
882
+ cVector v = pointFlow.points.get(i);
883
+
884
+ double mindist = Double.MAX_VALUE;
885
+
886
+ double size = pointFlow.minimumSize;
887
+
888
+ double distancenext = 0;
889
+
890
+ if (i > 0)
891
+ {
892
+ cVector w = pointFlow.points.get(i-1);
893
+
894
+ double dist = w.distance(v);
895
+
896
+ distancenext = dist;
897
+
898
+ if (mindist > dist)
899
+ {
900
+ mindist = dist;
901
+ size = mindist*pointFlow.resizefactor;
902
+ }
903
+ }
904
+
905
+ if (i < s-1)
906
+ {
907
+ cVector w = pointFlow.points.get(i+1);
908
+
909
+ double dist = w.distance(v);
910
+
911
+ if (mindist > dist)
912
+ {
913
+ mindist = dist;
914
+ size = mindist*pointFlow.resizefactor;
915
+ }
916
+ }
917
+
918
+ if (size < pointFlow.minimumSize)
919
+ size = pointFlow.minimumSize;
920
+ if (size > pointFlow.maximumSize)
921
+ size = pointFlow.maximumSize;
922
+
923
+ double tx = v.x;
924
+ double ty = v.y;
925
+ double tz = v.z;
926
+
927
+ // if (tx == 0 && ty == 0 && tz == 0)
928
+ // continue;
929
+
930
+ gl.glMatrixMode(gl.GL_TEXTURE);
931
+ gl.glPushMatrix();
932
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
933
+
934
+ gl.glMultMatrixf(pointFlow.texmat, 0);
935
+
936
+ gl.glMatrixMode(gl.GL_MODELVIEW);
937
+ gl.glPushMatrix();
938
+
939
+ gl.glTranslated(tx,ty,tz);
940
+
941
+ gl.glScaled(size,size,size);
942
+
943
+// float cr = colorBuf.get(index4);
944
+// float cg = colorBuf.get(index4+1);
945
+// float cb = colorBuf.get(index4+2);
946
+// float ca = colorBuf.get(index4+3);
947
+//
948
+// display.modelParams0[0] = r * cr;
949
+// display.modelParams0[1] = g * cg;
950
+// display.modelParams0[2] = b * cb;
951
+//
952
+// display.modelParams5[1] = opacity * ca;
953
+//
954
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
955
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
956
+//
957
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
958
+// RandomNode.globalseed2 = RandomNode.globalseed;
959
+//
960
+//// gl.glColor4f(cr,cg,cb,ca);
961
+// // gl.glScalef(1024/16,1024/16,1024/16);
962
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
963
+
964
+ gl.glPopMatrix();
965
+
966
+ double step = size/4; //
967
+
968
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
969
+ continue;
970
+
971
+ int nbsteps = (int)(distancenext/step);
972
+
973
+ step = distancenext/nbsteps;
974
+
975
+ cVector next = pointFlow.points.get(i-1);
976
+
977
+ tmp.set(next);
978
+ tmp.sub(v);
979
+ tmp.normalize();
980
+ tmp.mul(step);
981
+
982
+ // calculate next size
983
+ mindist = Double.MAX_VALUE;
984
+
985
+ double nextsize = pointFlow.minimumSize;
986
+
987
+ if (i > 1)
988
+ {
989
+ cVector w = pointFlow.points.get(i-2);
990
+
991
+ double dist = w.distance(next);
992
+
993
+ if (mindist > dist)
994
+ {
995
+ mindist = dist;
996
+ nextsize = mindist*pointFlow.resizefactor;
997
+ }
998
+ }
999
+
1000
+ double dist = v.distance(next);
1001
+
1002
+ if (mindist > dist)
1003
+ {
1004
+ mindist = dist;
1005
+ nextsize = mindist*pointFlow.resizefactor;
1006
+ }
1007
+
1008
+ if (nextsize < pointFlow.minimumSize)
1009
+ nextsize = pointFlow.minimumSize;
1010
+ if (nextsize > pointFlow.maximumSize)
1011
+ nextsize = pointFlow.maximumSize;
1012
+ //
1013
+
1014
+ double count = 0;
1015
+
1016
+ while (distancenext > 0.000000001) // step
1017
+ {
1018
+ gl.glPushMatrix();
1019
+
1020
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1021
+
1022
+ double K = count/nbsteps;
1023
+
1024
+ double intersize = K*nextsize + (1-K)*size;
1025
+
1026
+ gl.glScaled(intersize,intersize,intersize);
1027
+
1028
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1029
+
1030
+ count++;
1031
+
1032
+ distancenext -= step;
1033
+
1034
+ gl.glPopMatrix();
1035
+ }
1036
+
1037
+ if (count != nbsteps)
1038
+ assert(count == nbsteps);
1039
+
1040
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1041
+ //gl.glTranslatef(-tx,-ty,-tz);
1042
+
1043
+ gl.glMatrixMode(gl.GL_TEXTURE);
1044
+ gl.glPopMatrix();
1045
+ }
1046
+
1047
+ if (!cf)
1048
+ gl.glDisable(gl.GL_CULL_FACE);
1049
+
1050
+// display.modelParams0[0] = r;
1051
+// display.modelParams0[1] = g;
1052
+// display.modelParams0[2] = b;
1053
+//
1054
+// display.modelParams5[1] = opacity;
1055
+//
1056
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1057
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1058
+
1059
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1060
+ }
1061
+
7631062 /// INTERFACE
7641063
7651064 void SetColor(Object3D obj, Vertex p0)
....@@ -1323,7 +1622,7 @@
13231622
13241623 static int camerachangeframe;
13251624
1326
- boolean SetCamera(Camera cam)
1625
+ public boolean SetCamera(Camera cam)
13271626 {
13281627 // may 2014 if (cam == cameras[0] || cam == cameras[1])
13291628 // return false;
....@@ -1451,12 +1750,27 @@
14511750 mainDL ^= true;
14521751 }
14531752
1454
- void ToggleTexture()
1753
+ void ToggleFullScreen()
1754
+ {
1755
+ FULLSCREEN ^= true;
1756
+ }
1757
+
1758
+ void ToggleCrowd()
1759
+ {
1760
+ Globals.CROWD ^= true;
1761
+ }
1762
+
1763
+ void ToggleLocal()
1764
+ {
1765
+ LOCALTRANSFORM ^= true;
1766
+ }
1767
+
1768
+ public void ToggleTexture()
14551769 {
14561770 textureon ^= true;
14571771 }
14581772
1459
- void ToggleLive()
1773
+ public void ToggleLive()
14601774 {
14611775 Globals.setLIVE(Globals.isLIVE() ^ true);
14621776
....@@ -1468,92 +1782,67 @@
14681782 repaint(); // start loop // may 2013
14691783 }
14701784
1471
- void ToggleSupport()
1785
+ public void ToggleSupport()
14721786 {
14731787 SUPPORT ^= true;
14741788 }
14751789
1476
- void ToggleAbort()
1790
+ public void ToggleAbort()
14771791 {
14781792 ABORTMODE ^= true;
14791793 }
14801794
1481
- void ToggleFullScreen()
1482
- {
1483
- FULLSCREEN ^= true;
1484
- }
1485
-
1486
- void ToggleCrowd()
1487
- {
1488
- Globals.CROWD ^= true;
1489
- }
1490
-
1491
- void ToggleInertia()
1795
+ public void ToggleInertia()
14921796 {
14931797 INERTIA ^= true;
14941798 }
14951799
1496
- void ToggleLocal()
1497
- {
1498
- LOCALTRANSFORM ^= true;
1499
- }
1500
-
1501
- void ToggleFast()
1800
+ public void ToggleFast()
15021801 {
15031802 FAST ^= true;
15041803 }
15051804
1506
- void ToggleSlowPose()
1805
+ public void ToggleSlowPose()
15071806 {
15081807 SLOWPOSE ^= true;
15091808 }
15101809
1511
- void ToggleFootContact()
1512
- {
1513
- FOOTCONTACT ^= true;
1514
- }
1515
-
1516
- void ToggleBoxMode()
1810
+ public void ToggleBoxMode()
15171811 {
15181812 BOXMODE ^= true;
15191813 }
15201814
1521
- void ToggleSmoothFocus()
1815
+ public void ToggleSmoothFocus()
15221816 {
15231817 SMOOTHFOCUS ^= true;
15241818 }
15251819
1526
- void ToggleImageFlip()
1820
+ public void ToggleImageFlip()
15271821 {
15281822 IMAGEFLIP ^= true;
15291823 }
15301824
1531
- void ToggleSpeakerMocap()
1825
+ public void ToggleSpeakerMocap()
15321826 {
15331827 SPEAKERMOCAP ^= true;
15341828 }
15351829
1536
- void ToggleSpeakerCamera()
1830
+ public void ToggleSpeakerCamera()
15371831 {
15381832 SPEAKERCAMERA ^= true;
15391833 }
15401834
1541
- void ToggleSpeakerFocus()
1835
+ public void ToggleSpeakerFocus()
15421836 {
15431837 SPEAKERFOCUS ^= true;
15441838 }
15451839
1546
- void ToggleDebug()
1547
- {
1548
- DEBUG ^= true;
1549
- }
1550
-
1551
- void ToggleFrustum()
1840
+ public void ToggleFrustum()
15521841 {
15531842 FRUSTUM ^= true;
15541843 }
15551844
1556
- void ToggleTrack()
1845
+ public void ToggleTrack()
15571846 {
15581847 TRACK ^= true;
15591848 if (TRACK)
....@@ -1572,25 +1861,35 @@
15721861 repaint();
15731862 }
15741863
1575
- void ToggleTrackOnce()
1864
+ public void ToggleTrackOnce()
15761865 {
15771866 TRACKONCE ^= true;
15781867 }
15791868
1580
- void ToggleShadowTrack()
1869
+ public void ToggleShadowTrack()
15811870 {
15821871 SHADOWTRACK ^= true;
15831872 repaint();
15841873 }
15851874
1586
- void ToggleOeil()
1875
+ public void ToggleOeil()
15871876 {
15881877 OEIL ^= true;
15891878 }
15901879
1591
- void ToggleOeilOnce()
1880
+ public void ToggleOeilOnce()
15921881 {
15931882 OEILONCE ^= true;
1883
+ }
1884
+
1885
+ void ToggleFootContact()
1886
+ {
1887
+ FOOTCONTACT ^= true;
1888
+ }
1889
+
1890
+ void ToggleDebug()
1891
+ {
1892
+ DEBUG ^= true;
15941893 }
15951894
15961895 void ToggleLookAt()
....@@ -7652,7 +7951,7 @@
76527951 return texture!=null?texture.texture:null;
76537952 }
76547953
7655
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
7954
+ public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
76567955 {
76577956 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
76587957
....@@ -10340,7 +10639,7 @@
1034010639 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1034110640 //System.out.println("fragmentMode = " + fragmentMode);
1034210641
10343
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
10642
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1034410643 {
1034510644 /*
1034610645 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10641,7 +10940,7 @@
1064110940 callist = gl.glGenLists(1);
1064210941 }
1064310942
10644
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
10943
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1064510944
1064610945 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1064710946
....@@ -13116,6 +13415,11 @@
1311613415 cVector tmp2 = new cVector();
1311713416 boolean isMoving;
1311813417
13418
+ public cVector TargetLookAt()
13419
+ {
13420
+ return targetLookAt;
13421
+ }
13422
+
1311913423 class PingThread extends Thread
1312013424 {
1312113425 boolean jump;
....@@ -13847,7 +14151,7 @@
1384714151 SetMouseMode(modifiers);
1384814152 }
1384914153
13850
- theRenderer.keyPressed(key);
14154
+ Globals.theRenderer.keyPressed(key);
1385114155 }
1385214156
1385314157 int kompactbit = 4; // power bit
....@@ -13859,7 +14163,7 @@
1385914163 float SATPOW = 1; // 2; // 0.5f;
1386014164 float BRIPOW = 1; // 0.5f; // 0.5f;
1386114165
13862
- void keyPressed(int key)
14166
+ public void keyPressed(int key)
1386314167 {
1386414168 if (key >= '0' && key <= '5')
1386514169 clampbit = (key-'0');
....@@ -14296,6 +14600,7 @@
1429614600 }
1429714601 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1429814602 }
14603
+
1429914604 static double OCCLUSIONBOOST = 1; // 0.5;
1430014605
1430114606 void keyReleased(int key, int modifiers)
....@@ -14307,7 +14612,7 @@
1430714612 }
1430814613 }
1430914614
14310
- protected void processKeyEvent(KeyEvent e)
14615
+ public void processKeyEvent(KeyEvent e)
1431114616 {
1431214617 switch (e.getID())
1431314618 {
....@@ -15966,7 +16271,6 @@
1596616271
1596716272 class AntialiasBuffer implements GLEventListener
1596816273 {
15969
-
1597016274 CameraPane parent = null;
1597116275
1597216276 AntialiasBuffer(CameraPane p)
....@@ -16359,7 +16663,7 @@
1635916663 }
1636016664 }
1636116665
16362
- static void DrawPoints(CameraPane cpane)
16666
+ static void DrawPoints(iCameraPane cpane)
1636316667 {
1636416668 for (int i=0; i<8; i++) // first and last are red
1636516669 {