Normand Briere
2019-08-28 547c9203ab5d8e4bee36d1cbb453dfa36bbec4ef
cSpring.java
....@@ -10,7 +10,7 @@
1010
1111 boolean IsStatic()
1212 {
13
- return !(live && (CameraPane.isLIVE() || CameraPane.waslive));
13
+ return !(live && (Globals.isLIVE() || CameraPane.waslive));
1414 }
1515
1616 void Revert()
....@@ -82,7 +82,7 @@
8282
8383 // timestep
8484 double timestep = 1;
85
- double normalpusH = 0; // 1;
85
+ double normalpush = 0; // 1;
8686 static float H0 = 1E1f; // aucune importance...
8787 // mass
8888 double M = 1;
....@@ -543,13 +543,13 @@
543543 }
544544
545545 // serial lost
546
- void DrawNode0(CameraPane display)
546
+ void DrawNode0(iCameraPane display)
547547 {
548548 super.DrawNode(display, null, false);
549549 }
550550
551551
552
- void DrawNode/*notused*/(CameraPane display, Object3D /*Composite*/ root, boolean selected)
552
+ void DrawNode/*notused*/(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
553553 {
554554 // assert displaylist == -1;
555555
....@@ -565,11 +565,11 @@
565565 // }
566566
567567 //new Exception().printStackTrace();
568
- GL gl = display.GetGL(); // getGL();
568
+ GL gl = display.GetGL0(); // getGL();
569569
570570 //gl.glDisable(GL.GL_LIGHTING);
571571
572
- if (display.drawMode == display.SHADOW)
572
+ if (display.DrawMode() == display.SHADOW)
573573 {
574574 gl.glDisable(gl.GL_CULL_FACE);
575575 }
....@@ -762,7 +762,7 @@
762762 gl.glEnd();
763763 gl.glEnable(GL.GL_LIGHTING);
764764 /**/
765
- if (display.CULLFACE)
765
+ if (display.BackFaceCullMode())
766766 {
767767 gl.glEnable(gl.GL_CULL_FACE);
768768 }
....@@ -775,7 +775,7 @@
775775 // displaylist = 0; // june 2013 -1;
776776
777777 //System.out.println("DRAW " + display.drawMode);
778
- if (live && display.isLIVE() && display.drawMode == display.DEFAULT)
778
+ if (live && Globals.isLIVE() && display.DrawMode() == display.DEFAULT)
779779 {
780780 //System.out.println("UPDATE");
781781 Phys.update();
....@@ -967,6 +967,7 @@
967967 for (int i = 0; i < allNodes.size(); i++)
968968 {
969969 DynamicNode dn = allNodes.get(i);
970
+ dn.linked = false;
970971 dn.closestpoint = null;
971972 }
972973 }
....@@ -1207,7 +1208,10 @@
12071208 }
12081209
12091210 if (edges.size()%2 != 0)
1211
+ {
1212
+ new Exception().printStackTrace();
12101213 System.exit(0);
1214
+ }
12111215 }
12121216
12131217 // if (clearsprings)
....@@ -1416,6 +1420,7 @@
14161420 //transient double rotangle; // Z of axis
14171421 transient boolean reverse = false;
14181422
1423
+ transient boolean linked = false;
14191424 transient Vertex closestpoint = null;
14201425
14211426 //Point3D lastForce = new Point3D();
....@@ -1492,6 +1497,11 @@
14921497 }
14931498 }
14941499 }
1500
+
1501
+ if (Double.isNaN(springForce.y))
1502
+ {
1503
+ springForce.x = springForce.y = springForce.z = 0;
1504
+ }
14951505 }
14961506
14971507 void DetectBoundary()
....@@ -1509,7 +1519,10 @@
15091519 second = springs.get((i+1)%springs.size());
15101520
15111521 if (first == second)
1522
+ {
1523
+ new Exception().printStackTrace();
15121524 System.exit(0);
1525
+ }
15131526
15141527 temp.set(first.GetOther(this).position);
15151528 temp.sub(position);
....@@ -1639,7 +1652,10 @@
16391652 Spring second = springs.get((i+1)%springs.size());
16401653
16411654 if (first == second)
1655
+ {
1656
+ new Exception().printStackTrace();
16421657 System.exit(0);
1658
+ }
16431659
16441660 temp.set(first.GetOther(this).position);
16451661 temp.sub(position);
....@@ -1708,7 +1724,7 @@
17081724
17091725 // Phys.matrix.Transform(normal);
17101726
1711
- if (position instanceof Vertex)
1727
+ if (position instanceof Vertex && ((Vertex)position).norm != null)
17121728 ((Vertex)position).norm.set(normal.x,normal.y,normal.z);
17131729 }
17141730
....@@ -2339,28 +2355,7 @@
23392355 return this;
23402356 }
23412357
2342
- class Avoider extends Force
2343
- {
2344
- static final long serialVersionUID = -8657094699711594990L;
2345
-
2346
- Avoider()
2347
- {
2348
- }
2349
-
2350
- Avoider(Object3D col)
2351
- {
2352
- SetAvoider(col);
2353
- }
2354
-
2355
- void SetParameter(int index, double value)
2356
- {
2357
- parameters.setElementAt(new Double(value), index);
2358
- }
2359
-
2360
- void SetAvoider(Object3D col)
2361
- {
2362
- avoider = col;
2363
- }
2358
+ Object3D avoider;
23642359
23652360 void ResetGlobalTransform()
23662361 {
....@@ -2372,10 +2367,6 @@
23722367
23732368 transient double[][] toRoot; // = new double[4][4];
23742369
2375
- //Vector<Vertex> sortedcollider;
2376
- Object3D avoider;
2377
- Vector<Double> parameters = new Vector<Double>(); // serial issue
2378
-
23792370 Vertex ClosestPoint(Vector<Vertex> collider, DynamicNode N, int startindex, int endindex, int sortaxis)
23802371 {
23812372 if (startindex == endindex)
....@@ -2469,7 +2460,8 @@
24692460
24702461 for (int i=collider.size(); --i>=0;)
24712462 {
2472
- if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0)
2463
+ // Why? 3 dec 2018
2464
+ if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0.5)
24732465 continue;
24742466
24752467 temp.set(N.position);
....@@ -2487,43 +2479,24 @@
24872479 }
24882480 }
24892481
2490
- return cp;
2482
+ return mindist2 < 1 ? cp : null;
24912483 }
24922484
2493
- Point3D forceOn(DynamicNode N)
2485
+ class Avoider extends Force
2486
+ {
2487
+ static final long serialVersionUID = -8657094699711594990L;
2488
+
2489
+ Avoider()
24942490 {
2495
- force.x = 0;
2496
- force.y = 0;
2497
- force.z = 0;
2498
-
2499
- if (avoider.transientrep == null)
2500
- avoider.Revert();
2501
-
2502
- if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed)
2503
- return force;
2504
-
2505
- ResetGlobalTransform();
2506
- if (N.closestpoint == null)
2507
- {
2508
- //avoider.bRep.GetVertex(0); // "sort"
2509
-
2510
- ResetGlobalTransform();
2511
-
2512
- N.closestpoint = ClosestPoint(avoider.transientrep./*sortedV*/vertices, N, 0,avoider.transientrep./*sortedV*/vertices.size(), 0);
2513
-
2514
- if (N.closestpoint == null) // ????
2515
- return force;
2516
- }
2517
-
2518
- if (avoider == This())
2519
- {
2520
- // good but must freeze the order first... not really...
2521
- // if (cp.index < ((Vertex)N.position).index)
2522
- // return force;
2523
- }
2524
-
2525
- if (normalpusH != 0) // && cp == null /*???*/) // speed == 0)
2526
- {
2491
+ }
2492
+
2493
+ Avoider(Object3D col)
2494
+ {
2495
+ SetAvoider(col);
2496
+ }
2497
+
2498
+ void Avoidance(DynamicNode N)
2499
+ {
25272500 temp.set(N.position);
25282501 if (avoider != This())
25292502 {
....@@ -2531,16 +2504,16 @@
25312504 temp2.mul(0.001);
25322505 temp.sub(temp2); // push outside because of mesh artifacts
25332506 }
2534
-
2507
+
25352508 vect1.set(N.closestpoint);
2536
-
2509
+
25372510 LA.xformPos(vect1,toRoot,vect1);
25382511 //avoider.TransformToWorld(vect1, vect1);
2539
-
2512
+
25402513 temp.sub(vect1);
2541
-
2514
+
25422515 double distance = Math.sqrt(temp.length2());
2543
-
2516
+
25442517 if (distance < 0.01)
25452518 {
25462519 temp2.set(N.closestpoint.norm);
....@@ -2554,9 +2527,98 @@
25542527 if (IsAutoFreeze())
25552528 dot = -dot;
25562529
2557
- temp.mul(normalpusH/*/distance*/*-dot/Math.sqrt(distance));
2530
+ temp.mul(normalpush/*/distance*/*-dot/Math.sqrt(distance));
25582531 force.add(temp);
25592532 }
2533
+ }
2534
+
2535
+ void Attraction(DynamicNode N)
2536
+ {
2537
+ temp.set(N.position);
2538
+ if (avoider != This())
2539
+ {
2540
+ temp2.set(N.closestpoint.norm);
2541
+ temp2.mul(0.001);
2542
+ temp.sub(temp2); // push outside because of mesh artifacts
2543
+ }
2544
+
2545
+ vect1.set(N.closestpoint);
2546
+
2547
+ LA.xformPos(vect1,toRoot,vect1);
2548
+ //avoider.TransformToWorld(vect1, vect1);
2549
+
2550
+ temp.sub(vect1);
2551
+
2552
+ double distance = Math.sqrt(temp.length2());
2553
+
2554
+ //if (distance < 0.01)
2555
+ {
2556
+ temp2.set(N.closestpoint.norm);
2557
+ double dot = temp2.dot(temp);
2558
+
2559
+// if (dot > 0)
2560
+// dot = 0;
2561
+
2562
+ // normal pushing
2563
+ temp.set(N.closestpoint.norm);
2564
+// if (IsAutoFreeze())
2565
+// dot = -dot;
2566
+
2567
+ temp.mul(normalpush/*/distance*/ * -dot * distance);
2568
+ force.add(temp);
2569
+ }
2570
+ }
2571
+
2572
+ void SetParameter(int index, double value)
2573
+ {
2574
+ parameters.setElementAt(new Double(value), index);
2575
+ }
2576
+
2577
+ void SetAvoider(Object3D col)
2578
+ {
2579
+ avoider = col;
2580
+ }
2581
+
2582
+ //Vector<Vertex> sortedcollider;
2583
+ Vector<Double> parameters = new Vector<Double>(); // serial issue
2584
+
2585
+ Point3D forceOn(DynamicNode N)
2586
+ {
2587
+ force.x = 0;
2588
+ force.y = 0;
2589
+ force.z = 0;
2590
+
2591
+ if (avoider.transientrep == null)
2592
+ avoider.Revert();
2593
+
2594
+ if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed)
2595
+ return force;
2596
+
2597
+ ResetGlobalTransform();
2598
+ if (!N.linked)
2599
+ {
2600
+ //avoider.bRep.GetVertex(0); // "sort"
2601
+
2602
+ ResetGlobalTransform();
2603
+
2604
+ N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0);
2605
+ N.linked = true;
2606
+ }
2607
+
2608
+ if (avoider == This())
2609
+ {
2610
+ // good but must freeze the order first... not really...
2611
+ // if (cp.index < ((Vertex)N.position).index)
2612
+ // return force;
2613
+ }
2614
+
2615
+ if (normalpush != 0) // && cp == null /*???*/) // speed == 0)
2616
+ {
2617
+ if (N.closestpoint == null)
2618
+ return force;
2619
+
2620
+ //Avoidance(N);
2621
+ Attraction(N);
25602622 }
25612623
25622624 if (parameters.size() > 0)
....@@ -2590,6 +2652,7 @@
25902652 totalforce = new Point3D();
25912653
25922654 totalforce.set(0,0,0);
2655
+
25932656 if (forces.size() == 0)
25942657 totalforce.set(super.forceOn(N));
25952658
....@@ -2660,7 +2723,7 @@
26602723 force.y = 0;
26612724 force.z = 0;
26622725
2663
- if (normalpusH != 0) // speed == 0) // Now normal force
2726
+ if (normalpush != 0) // speed == 0) // Now normal force
26642727 {
26652728 // temp.set(N.position);
26662729 // temp.sub(Phys.reference);
....@@ -2668,7 +2731,7 @@
26682731
26692732 // normal pushing
26702733 temp.set(N.normal);
2671
- temp.mul(normalpusH/distance);
2734
+ temp.mul(normalpush/distance);
26722735 force.add(temp);
26732736 }
26742737
....@@ -2900,6 +2963,7 @@
29002963 return force;
29012964 }
29022965 }
2966
+
29032967 static int TABLESAC = 1024;
29042968 static double[] tablesac = new double[TABLESAC];
29052969
....@@ -2993,6 +3057,40 @@
29933057 // mass = M;
29943058 } // ???
29953059
3060
+ if (avoider != null)
3061
+ {
3062
+ if (avoider.transientrep == null)
3063
+ avoider.Revert();
3064
+
3065
+ if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed)
3066
+ return force;
3067
+
3068
+ ResetGlobalTransform();
3069
+ if (!N.linked)
3070
+ {
3071
+ //avoider.bRep.GetVertex(0); // "sort"
3072
+
3073
+ //ResetGlobalTransform();
3074
+
3075
+ N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0);
3076
+ N.linked = true;
3077
+ }
3078
+
3079
+ if (N.closestpoint != null)
3080
+ {
3081
+ temp.set(N.position);
3082
+ vect1.set(N.closestpoint);
3083
+ LA.xformPos(vect1,toRoot,vect1);
3084
+ temp.sub(vect1);
3085
+
3086
+ temp2.set(N.closestpoint.norm);
3087
+ double dot = temp2.dot(temp);
3088
+
3089
+ if (dot < 0)
3090
+ mass = Float.NaN;
3091
+ }
3092
+ }
3093
+
29963094 force.x = 0;
29973095 force.y = (float) (-acceleration * mass);
29983096 force.z = 0; // -acceleration * mass * 1000 * Math.cos(time/234.0 + framecount*100); // (Math.random()*2 - 1); //
....@@ -3189,7 +3287,7 @@
31893287 }
31903288 if (false) // isHandle)
31913289 {
3192
- double K = Math.exp(-displacement*normalpusH);
3290
+ double K = Math.exp(-displacement*normalpush);
31933291 magnitude /= (displacement*(1-K) + K);
31943292 }
31953293
....@@ -3200,6 +3298,7 @@
32003298
32013299 if (N2.mass == Float.MAX_VALUE)
32023300 {
3301
+ new Exception().printStackTrace();
32033302 System.exit(0);
32043303 magnitude *= solidity; // * K;
32053304