Normand Briere
2019-04-22 3c4c16e0a4ca3949a7a37a24607df7f89abfe7ea
CameraPane.java
....@@ -149,8 +149,9 @@
149149 defaultcaps.setAccumBlueBits(16);
150150 defaultcaps.setAccumAlphaBits(16);
151151 }
152
+
152153 static CameraPane theRenderer;
153
-
154
+
154155 void SetAsGLRenderer(boolean b)
155156 {
156157 isRenderer = b;
....@@ -236,9 +237,14 @@
236237 return this.ambientOcclusion;
237238 }
238239
240
+ public boolean IsDebugSelection()
241
+ {
242
+ return DEBUG_SELECTION;
243
+ }
244
+
239245 public boolean IsFrozen()
240246 {
241
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
247
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
242248
243249 return !selectmode && cameracount == 0; // != 0;
244250 }
....@@ -259,9 +265,19 @@
259265 return lightCamera;
260266 }
261267
268
+ public Camera ManipCamera()
269
+ {
270
+ return manipCamera;
271
+ }
272
+
262273 public Camera RenderCamera()
263274 {
264275 return renderCamera;
276
+ }
277
+
278
+ public Camera[] Cameras()
279
+ {
280
+ return cameras;
265281 }
266282
267283 public void PushMaterial(Object3D obj, boolean selected)
....@@ -408,7 +424,7 @@
408424
409425 javax.media.opengl.GL gl = display.GetGL();
410426
411
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
427
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
412428
413429 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
414430 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
....@@ -760,6 +776,291 @@
760776 //// tris.postdraw(this);
761777 }
762778
779
+ static Camera localcamera = new Camera();
780
+ static cVector from = new cVector();
781
+ static cVector to = new cVector();
782
+
783
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
784
+ {
785
+ CameraPane cp = this;
786
+
787
+ Camera keep = cp.RenderCamera();
788
+ cp.renderCamera = localcamera;
789
+
790
+ if (br.trimmed)
791
+ {
792
+ float[] colors = new float[br.positions.length / 3];
793
+
794
+ int i3 = 0;
795
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
796
+ {
797
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
798
+ continue;
799
+
800
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
801
+ to.set(br.positions[i3] + br.normals[i3],
802
+ br.positions[i3 + 1] + br.normals[i3 + 1],
803
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
804
+ LA.xformPos(from, transform, from);
805
+ LA.xformPos(to, transform, to); // RIGID ONLY
806
+ localcamera.setAim(from, to);
807
+
808
+ CameraPane.occlusionbuffer.display();
809
+
810
+ if (CameraPane.DEBUG_OCCLUSION)
811
+ cp.display(); // debug
812
+
813
+ colors[i] = cp.vertexOcclusion.r;
814
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
815
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
816
+
817
+ if ((i % 100) == 0 && i != 0)
818
+ {
819
+ CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
820
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
821
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
822
+ }
823
+ }
824
+
825
+ br.colors = colors;
826
+ }
827
+ else
828
+ {
829
+ for (int i = 0; i < br.VertexCount(); i++)
830
+ {
831
+ Vertex v = br.GetVertex(i);
832
+
833
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
834
+ continue;
835
+
836
+ from.set(v.x, v.y, v.z);
837
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
838
+ LA.xformPos(from, transform, from);
839
+ LA.xformPos(to, transform, to); // RIGID ONLY
840
+ localcamera.setAim(from, to);
841
+
842
+ CameraPane.occlusionbuffer.display();
843
+
844
+ if (CameraPane.DEBUG_OCCLUSION)
845
+ cp.display(); // debug
846
+
847
+ v.AO = cp.vertexOcclusion.r;
848
+
849
+ if ((i % 100) == 0 && i != 0)
850
+ {
851
+ CameraPane.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
852
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
853
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
854
+ }
855
+ }
856
+ }
857
+
858
+ //System.out.println("done.");
859
+
860
+ cp.renderCamera = keep;
861
+ }
862
+
863
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
864
+ {
865
+ CameraPane display = this;
866
+ pointFlow.CreateHT();
867
+
868
+ float r = display.modelParams0[0];
869
+ float g = display.modelParams0[1];
870
+ float b = display.modelParams0[2];
871
+ float opacity = display.modelParams5[1];
872
+
873
+ //final GL gl = GLU.getCurrentGL();
874
+ GL gl = display.GetGL(); // getGL();
875
+
876
+ int s = pointFlow.points.size();
877
+
878
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
879
+ gl.glEnable(gl.GL_CULL_FACE);
880
+
881
+ for (int i=s; --i>=0;)
882
+ //for (int i=0; i<s; i++)
883
+ {
884
+ cVector v = pointFlow.points.get(i);
885
+
886
+ double mindist = Double.MAX_VALUE;
887
+
888
+ double size = pointFlow.minimumSize;
889
+
890
+ double distancenext = 0;
891
+
892
+ if (i > 0)
893
+ {
894
+ cVector w = pointFlow.points.get(i-1);
895
+
896
+ double dist = w.distance(v);
897
+
898
+ distancenext = dist;
899
+
900
+ if (mindist > dist)
901
+ {
902
+ mindist = dist;
903
+ size = mindist*pointFlow.resizefactor;
904
+ }
905
+ }
906
+
907
+ if (i < s-1)
908
+ {
909
+ cVector w = pointFlow.points.get(i+1);
910
+
911
+ double dist = w.distance(v);
912
+
913
+ if (mindist > dist)
914
+ {
915
+ mindist = dist;
916
+ size = mindist*pointFlow.resizefactor;
917
+ }
918
+ }
919
+
920
+ if (size < pointFlow.minimumSize)
921
+ size = pointFlow.minimumSize;
922
+ if (size > pointFlow.maximumSize)
923
+ size = pointFlow.maximumSize;
924
+
925
+ double tx = v.x;
926
+ double ty = v.y;
927
+ double tz = v.z;
928
+
929
+ // if (tx == 0 && ty == 0 && tz == 0)
930
+ // continue;
931
+
932
+ gl.glMatrixMode(gl.GL_TEXTURE);
933
+ gl.glPushMatrix();
934
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
935
+
936
+ gl.glMultMatrixf(pointFlow.texmat, 0);
937
+
938
+ gl.glMatrixMode(gl.GL_MODELVIEW);
939
+ gl.glPushMatrix();
940
+
941
+ gl.glTranslated(tx,ty,tz);
942
+
943
+ gl.glScaled(size,size,size);
944
+
945
+// float cr = colorBuf.get(index4);
946
+// float cg = colorBuf.get(index4+1);
947
+// float cb = colorBuf.get(index4+2);
948
+// float ca = colorBuf.get(index4+3);
949
+//
950
+// display.modelParams0[0] = r * cr;
951
+// display.modelParams0[1] = g * cg;
952
+// display.modelParams0[2] = b * cb;
953
+//
954
+// display.modelParams5[1] = opacity * ca;
955
+//
956
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
957
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
958
+//
959
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
960
+// RandomNode.globalseed2 = RandomNode.globalseed;
961
+//
962
+//// gl.glColor4f(cr,cg,cb,ca);
963
+// // gl.glScalef(1024/16,1024/16,1024/16);
964
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
965
+
966
+ gl.glPopMatrix();
967
+
968
+ double step = size/4; //
969
+
970
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
971
+ continue;
972
+
973
+ int nbsteps = (int)(distancenext/step);
974
+
975
+ step = distancenext/nbsteps;
976
+
977
+ cVector next = pointFlow.points.get(i-1);
978
+
979
+ tmp.set(next);
980
+ tmp.sub(v);
981
+ tmp.normalize();
982
+ tmp.mul(step);
983
+
984
+ // calculate next size
985
+ mindist = Double.MAX_VALUE;
986
+
987
+ double nextsize = pointFlow.minimumSize;
988
+
989
+ if (i > 1)
990
+ {
991
+ cVector w = pointFlow.points.get(i-2);
992
+
993
+ double dist = w.distance(next);
994
+
995
+ if (mindist > dist)
996
+ {
997
+ mindist = dist;
998
+ nextsize = mindist*pointFlow.resizefactor;
999
+ }
1000
+ }
1001
+
1002
+ double dist = v.distance(next);
1003
+
1004
+ if (mindist > dist)
1005
+ {
1006
+ mindist = dist;
1007
+ nextsize = mindist*pointFlow.resizefactor;
1008
+ }
1009
+
1010
+ if (nextsize < pointFlow.minimumSize)
1011
+ nextsize = pointFlow.minimumSize;
1012
+ if (nextsize > pointFlow.maximumSize)
1013
+ nextsize = pointFlow.maximumSize;
1014
+ //
1015
+
1016
+ double count = 0;
1017
+
1018
+ while (distancenext > 0.000000001) // step
1019
+ {
1020
+ gl.glPushMatrix();
1021
+
1022
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1023
+
1024
+ double K = count/nbsteps;
1025
+
1026
+ double intersize = K*nextsize + (1-K)*size;
1027
+
1028
+ gl.glScaled(intersize,intersize,intersize);
1029
+
1030
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1031
+
1032
+ count++;
1033
+
1034
+ distancenext -= step;
1035
+
1036
+ gl.glPopMatrix();
1037
+ }
1038
+
1039
+ if (count != nbsteps)
1040
+ assert(count == nbsteps);
1041
+
1042
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1043
+ //gl.glTranslatef(-tx,-ty,-tz);
1044
+
1045
+ gl.glMatrixMode(gl.GL_TEXTURE);
1046
+ gl.glPopMatrix();
1047
+ }
1048
+
1049
+ if (!cf)
1050
+ gl.glDisable(gl.GL_CULL_FACE);
1051
+
1052
+// display.modelParams0[0] = r;
1053
+// display.modelParams0[1] = g;
1054
+// display.modelParams0[2] = b;
1055
+//
1056
+// display.modelParams5[1] = opacity;
1057
+//
1058
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1059
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1060
+
1061
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1062
+ }
1063
+
7631064 /// INTERFACE
7641065
7651066 void SetColor(Object3D obj, Vertex p0)
....@@ -10340,7 +10641,7 @@
1034010641 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1034110642 //System.out.println("fragmentMode = " + fragmentMode);
1034210643
10343
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
10644
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1034410645 {
1034510646 /*
1034610647 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10641,7 +10942,7 @@
1064110942 callist = gl.glGenLists(1);
1064210943 }
1064310944
10644
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
10945
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1064510946
1064610947 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1064710948
....@@ -13115,6 +13416,11 @@
1311513416 cVector tmp = new cVector();
1311613417 cVector tmp2 = new cVector();
1311713418 boolean isMoving;
13419
+
13420
+ public cVector TargetLookAt()
13421
+ {
13422
+ return targetLookAt;
13423
+ }
1311813424
1311913425 class PingThread extends Thread
1312013426 {
....@@ -15966,7 +16272,6 @@
1596616272
1596716273 class AntialiasBuffer implements GLEventListener
1596816274 {
15969
-
1597016275 CameraPane parent = null;
1597116276
1597216277 AntialiasBuffer(CameraPane p)
....@@ -16359,7 +16664,7 @@
1635916664 }
1636016665 }
1636116666
16362
- static void DrawPoints(CameraPane cpane)
16667
+ static void DrawPoints(iCameraPane cpane)
1636316668 {
1636416669 for (int i=0; i<8; i++) // first and last are red
1636516670 {