.. | .. |
---|
10 | 10 | |
---|
11 | 11 | boolean IsStatic() |
---|
12 | 12 | { |
---|
13 | | - return !(live && (CameraPane.isLIVE() || CameraPane.waslive)); |
---|
| 13 | + return !(live && (Globals.isLIVE() || CameraPane.waslive)); |
---|
14 | 14 | } |
---|
15 | 15 | |
---|
16 | 16 | void Revert() |
---|
.. | .. |
---|
82 | 82 | |
---|
83 | 83 | // timestep |
---|
84 | 84 | double timestep = 1; |
---|
85 | | - double normalpusH = 0; // 1; |
---|
| 85 | + double normalpush = 0; // 1; |
---|
86 | 86 | static float H0 = 1E1f; // aucune importance... |
---|
87 | 87 | // mass |
---|
88 | 88 | double M = 1; |
---|
.. | .. |
---|
543 | 543 | } |
---|
544 | 544 | |
---|
545 | 545 | // serial lost |
---|
546 | | - void DrawNode0(CameraPane display) |
---|
| 546 | + void DrawNode0(iCameraPane display) |
---|
547 | 547 | { |
---|
548 | 548 | super.DrawNode(display, null, false); |
---|
549 | 549 | } |
---|
550 | 550 | |
---|
551 | 551 | |
---|
552 | | - void DrawNode/*notused*/(CameraPane display, Object3D /*Composite*/ root, boolean selected) |
---|
| 552 | + void DrawNode/*notused*/(iCameraPane display, Object3D /*Composite*/ root, boolean selected) |
---|
553 | 553 | { |
---|
554 | 554 | // assert displaylist == -1; |
---|
555 | 555 | |
---|
.. | .. |
---|
565 | 565 | // } |
---|
566 | 566 | |
---|
567 | 567 | //new Exception().printStackTrace(); |
---|
568 | | - GL gl = display.GetGL(); // getGL(); |
---|
| 568 | + GL gl = display.GetGL0(); // getGL(); |
---|
569 | 569 | |
---|
570 | 570 | //gl.glDisable(GL.GL_LIGHTING); |
---|
571 | 571 | |
---|
572 | | - if (display.drawMode == display.SHADOW) |
---|
| 572 | + if (display.DrawMode() == display.SHADOW) |
---|
573 | 573 | { |
---|
574 | 574 | gl.glDisable(gl.GL_CULL_FACE); |
---|
575 | 575 | } |
---|
.. | .. |
---|
762 | 762 | gl.glEnd(); |
---|
763 | 763 | gl.glEnable(GL.GL_LIGHTING); |
---|
764 | 764 | /**/ |
---|
765 | | - if (display.CULLFACE) |
---|
| 765 | + if (display.BackFaceCullMode()) |
---|
766 | 766 | { |
---|
767 | 767 | gl.glEnable(gl.GL_CULL_FACE); |
---|
768 | 768 | } |
---|
.. | .. |
---|
775 | 775 | // displaylist = 0; // june 2013 -1; |
---|
776 | 776 | |
---|
777 | 777 | //System.out.println("DRAW " + display.drawMode); |
---|
778 | | - if (live && display.isLIVE() && display.drawMode == display.DEFAULT) |
---|
| 778 | + if (live && Globals.isLIVE() && display.DrawMode() == display.DEFAULT) |
---|
779 | 779 | { |
---|
780 | 780 | //System.out.println("UPDATE"); |
---|
781 | 781 | Phys.update(); |
---|
.. | .. |
---|
967 | 967 | for (int i = 0; i < allNodes.size(); i++) |
---|
968 | 968 | { |
---|
969 | 969 | DynamicNode dn = allNodes.get(i); |
---|
| 970 | + dn.linked = false; |
---|
970 | 971 | dn.closestpoint = null; |
---|
971 | 972 | } |
---|
972 | 973 | } |
---|
.. | .. |
---|
1207 | 1208 | } |
---|
1208 | 1209 | |
---|
1209 | 1210 | if (edges.size()%2 != 0) |
---|
| 1211 | + { |
---|
| 1212 | + new Exception().printStackTrace(); |
---|
1210 | 1213 | System.exit(0); |
---|
| 1214 | + } |
---|
1211 | 1215 | } |
---|
1212 | 1216 | |
---|
1213 | 1217 | // if (clearsprings) |
---|
.. | .. |
---|
1416 | 1420 | //transient double rotangle; // Z of axis |
---|
1417 | 1421 | transient boolean reverse = false; |
---|
1418 | 1422 | |
---|
| 1423 | + transient boolean linked = false; |
---|
1419 | 1424 | transient Vertex closestpoint = null; |
---|
1420 | 1425 | |
---|
1421 | 1426 | //Point3D lastForce = new Point3D(); |
---|
.. | .. |
---|
1492 | 1497 | } |
---|
1493 | 1498 | } |
---|
1494 | 1499 | } |
---|
| 1500 | + |
---|
| 1501 | + if (Double.isNaN(springForce.y)) |
---|
| 1502 | + { |
---|
| 1503 | + springForce.x = springForce.y = springForce.z = 0; |
---|
| 1504 | + } |
---|
1495 | 1505 | } |
---|
1496 | 1506 | |
---|
1497 | 1507 | void DetectBoundary() |
---|
.. | .. |
---|
1509 | 1519 | second = springs.get((i+1)%springs.size()); |
---|
1510 | 1520 | |
---|
1511 | 1521 | if (first == second) |
---|
| 1522 | + { |
---|
| 1523 | + new Exception().printStackTrace(); |
---|
1512 | 1524 | System.exit(0); |
---|
| 1525 | + } |
---|
1513 | 1526 | |
---|
1514 | 1527 | temp.set(first.GetOther(this).position); |
---|
1515 | 1528 | temp.sub(position); |
---|
.. | .. |
---|
1639 | 1652 | Spring second = springs.get((i+1)%springs.size()); |
---|
1640 | 1653 | |
---|
1641 | 1654 | if (first == second) |
---|
| 1655 | + { |
---|
| 1656 | + new Exception().printStackTrace(); |
---|
1642 | 1657 | System.exit(0); |
---|
| 1658 | + } |
---|
1643 | 1659 | |
---|
1644 | 1660 | temp.set(first.GetOther(this).position); |
---|
1645 | 1661 | temp.sub(position); |
---|
.. | .. |
---|
1708 | 1724 | |
---|
1709 | 1725 | // Phys.matrix.Transform(normal); |
---|
1710 | 1726 | |
---|
1711 | | - if (position instanceof Vertex) |
---|
| 1727 | + if (position instanceof Vertex && ((Vertex)position).norm != null) |
---|
1712 | 1728 | ((Vertex)position).norm.set(normal.x,normal.y,normal.z); |
---|
1713 | 1729 | } |
---|
1714 | 1730 | |
---|
.. | .. |
---|
2339 | 2355 | return this; |
---|
2340 | 2356 | } |
---|
2341 | 2357 | |
---|
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; |
---|
2364 | 2359 | |
---|
2365 | 2360 | void ResetGlobalTransform() |
---|
2366 | 2361 | { |
---|
.. | .. |
---|
2372 | 2367 | |
---|
2373 | 2368 | transient double[][] toRoot; // = new double[4][4]; |
---|
2374 | 2369 | |
---|
2375 | | - //Vector<Vertex> sortedcollider; |
---|
2376 | | - Object3D avoider; |
---|
2377 | | - Vector<Double> parameters = new Vector<Double>(); // serial issue |
---|
2378 | | - |
---|
2379 | 2370 | Vertex ClosestPoint(Vector<Vertex> collider, DynamicNode N, int startindex, int endindex, int sortaxis) |
---|
2380 | 2371 | { |
---|
2381 | 2372 | if (startindex == endindex) |
---|
.. | .. |
---|
2469 | 2460 | |
---|
2470 | 2461 | for (int i=collider.size(); --i>=0;) |
---|
2471 | 2462 | { |
---|
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) |
---|
2473 | 2465 | continue; |
---|
2474 | 2466 | |
---|
2475 | 2467 | temp.set(N.position); |
---|
.. | .. |
---|
2487 | 2479 | } |
---|
2488 | 2480 | } |
---|
2489 | 2481 | |
---|
2490 | | - return cp; |
---|
| 2482 | + return mindist2 < 1 ? cp : null; |
---|
2491 | 2483 | } |
---|
2492 | 2484 | |
---|
2493 | | - Point3D forceOn(DynamicNode N) |
---|
| 2485 | + class Avoider extends Force |
---|
| 2486 | + { |
---|
| 2487 | + static final long serialVersionUID = -8657094699711594990L; |
---|
| 2488 | + |
---|
| 2489 | + Avoider() |
---|
2494 | 2490 | { |
---|
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 | + { |
---|
2527 | 2500 | temp.set(N.position); |
---|
2528 | 2501 | if (avoider != This()) |
---|
2529 | 2502 | { |
---|
.. | .. |
---|
2531 | 2504 | temp2.mul(0.001); |
---|
2532 | 2505 | temp.sub(temp2); // push outside because of mesh artifacts |
---|
2533 | 2506 | } |
---|
2534 | | - |
---|
| 2507 | + |
---|
2535 | 2508 | vect1.set(N.closestpoint); |
---|
2536 | | - |
---|
| 2509 | + |
---|
2537 | 2510 | LA.xformPos(vect1,toRoot,vect1); |
---|
2538 | 2511 | //avoider.TransformToWorld(vect1, vect1); |
---|
2539 | | - |
---|
| 2512 | + |
---|
2540 | 2513 | temp.sub(vect1); |
---|
2541 | | - |
---|
| 2514 | + |
---|
2542 | 2515 | double distance = Math.sqrt(temp.length2()); |
---|
2543 | | - |
---|
| 2516 | + |
---|
2544 | 2517 | if (distance < 0.01) |
---|
2545 | 2518 | { |
---|
2546 | 2519 | temp2.set(N.closestpoint.norm); |
---|
.. | .. |
---|
2554 | 2527 | if (IsAutoFreeze()) |
---|
2555 | 2528 | dot = -dot; |
---|
2556 | 2529 | |
---|
2557 | | - temp.mul(normalpusH/*/distance*/*-dot/Math.sqrt(distance)); |
---|
| 2530 | + temp.mul(normalpush/*/distance*/*-dot/Math.sqrt(distance)); |
---|
2558 | 2531 | force.add(temp); |
---|
2559 | 2532 | } |
---|
| 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); |
---|
2560 | 2622 | } |
---|
2561 | 2623 | |
---|
2562 | 2624 | if (parameters.size() > 0) |
---|
.. | .. |
---|
2590 | 2652 | totalforce = new Point3D(); |
---|
2591 | 2653 | |
---|
2592 | 2654 | totalforce.set(0,0,0); |
---|
| 2655 | + |
---|
2593 | 2656 | if (forces.size() == 0) |
---|
2594 | 2657 | totalforce.set(super.forceOn(N)); |
---|
2595 | 2658 | |
---|
.. | .. |
---|
2660 | 2723 | force.y = 0; |
---|
2661 | 2724 | force.z = 0; |
---|
2662 | 2725 | |
---|
2663 | | - if (normalpusH != 0) // speed == 0) // Now normal force |
---|
| 2726 | + if (normalpush != 0) // speed == 0) // Now normal force |
---|
2664 | 2727 | { |
---|
2665 | 2728 | // temp.set(N.position); |
---|
2666 | 2729 | // temp.sub(Phys.reference); |
---|
.. | .. |
---|
2668 | 2731 | |
---|
2669 | 2732 | // normal pushing |
---|
2670 | 2733 | temp.set(N.normal); |
---|
2671 | | - temp.mul(normalpusH/distance); |
---|
| 2734 | + temp.mul(normalpush/distance); |
---|
2672 | 2735 | force.add(temp); |
---|
2673 | 2736 | } |
---|
2674 | 2737 | |
---|
.. | .. |
---|
2900 | 2963 | return force; |
---|
2901 | 2964 | } |
---|
2902 | 2965 | } |
---|
| 2966 | + |
---|
2903 | 2967 | static int TABLESAC = 1024; |
---|
2904 | 2968 | static double[] tablesac = new double[TABLESAC]; |
---|
2905 | 2969 | |
---|
.. | .. |
---|
2993 | 3057 | // mass = M; |
---|
2994 | 3058 | } // ??? |
---|
2995 | 3059 | |
---|
| 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 | + |
---|
2996 | 3094 | force.x = 0; |
---|
2997 | 3095 | force.y = (float) (-acceleration * mass); |
---|
2998 | 3096 | force.z = 0; // -acceleration * mass * 1000 * Math.cos(time/234.0 + framecount*100); // (Math.random()*2 - 1); // |
---|
.. | .. |
---|
3189 | 3287 | } |
---|
3190 | 3288 | if (false) // isHandle) |
---|
3191 | 3289 | { |
---|
3192 | | - double K = Math.exp(-displacement*normalpusH); |
---|
| 3290 | + double K = Math.exp(-displacement*normalpush); |
---|
3193 | 3291 | magnitude /= (displacement*(1-K) + K); |
---|
3194 | 3292 | } |
---|
3195 | 3293 | |
---|
.. | .. |
---|
3200 | 3298 | |
---|
3201 | 3299 | if (N2.mass == Float.MAX_VALUE) |
---|
3202 | 3300 | { |
---|
| 3301 | + new Exception().printStackTrace(); |
---|
3203 | 3302 | System.exit(0); |
---|
3204 | 3303 | magnitude *= solidity; // * K; |
---|
3205 | 3304 | |
---|