.. | .. |
---|
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; |
---|
.. | .. |
---|
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 | } |
---|
.. | .. |
---|
1057 | 1058 | vect1.set(v); |
---|
1058 | 1059 | LA.xformPos(vect1,toRoot,vect1); |
---|
1059 | 1060 | |
---|
1060 | | - handles.get(usedrep.VertexCount()-1-i).set(vect1); |
---|
| 1061 | + handles.get(i).set(vect1); |
---|
1061 | 1062 | } |
---|
1062 | 1063 | } |
---|
1063 | 1064 | |
---|
.. | .. |
---|
1416 | 1417 | //transient double rotangle; // Z of axis |
---|
1417 | 1418 | transient boolean reverse = false; |
---|
1418 | 1419 | |
---|
| 1420 | + transient boolean linked = false; |
---|
1419 | 1421 | transient Vertex closestpoint = null; |
---|
1420 | 1422 | |
---|
1421 | 1423 | //Point3D lastForce = new Point3D(); |
---|
.. | .. |
---|
1491 | 1493 | otherForce.add(f.forceOn(this)); |
---|
1492 | 1494 | } |
---|
1493 | 1495 | } |
---|
| 1496 | + } |
---|
| 1497 | + |
---|
| 1498 | + if (Double.isNaN(springForce.y)) |
---|
| 1499 | + { |
---|
| 1500 | + springForce.x = springForce.y = springForce.z = 0; |
---|
1494 | 1501 | } |
---|
1495 | 1502 | } |
---|
1496 | 1503 | |
---|
.. | .. |
---|
2325 | 2332 | |
---|
2326 | 2333 | abstract Point3D forceOn(DynamicNode N); |
---|
2327 | 2334 | } |
---|
| 2335 | + |
---|
2328 | 2336 | Point3D force = new Point3D(); |
---|
2329 | 2337 | Point3D dir = new Point3D(); |
---|
2330 | 2338 | |
---|
.. | .. |
---|
2338 | 2346 | return this; |
---|
2339 | 2347 | } |
---|
2340 | 2348 | |
---|
2341 | | - class Avoider extends Force |
---|
2342 | | - { |
---|
2343 | | - static final long serialVersionUID = -8657094699711594990L; |
---|
2344 | | - |
---|
2345 | | - Avoider() |
---|
2346 | | - { |
---|
2347 | | - } |
---|
2348 | | - |
---|
2349 | | - Avoider(Object3D col) |
---|
2350 | | - { |
---|
2351 | | - SetAvoider(col); |
---|
2352 | | - } |
---|
2353 | | - |
---|
2354 | | - void SetParameter(int index, double value) |
---|
2355 | | - { |
---|
2356 | | - parameters.setElementAt(new Double(value), index); |
---|
2357 | | - } |
---|
2358 | | - |
---|
2359 | | - void SetAvoider(Object3D col) |
---|
2360 | | - { |
---|
2361 | | - avoider = col; |
---|
2362 | | - } |
---|
| 2349 | + Object3D avoider; |
---|
2363 | 2350 | |
---|
2364 | 2351 | void ResetGlobalTransform() |
---|
2365 | 2352 | { |
---|
.. | .. |
---|
2371 | 2358 | |
---|
2372 | 2359 | transient double[][] toRoot; // = new double[4][4]; |
---|
2373 | 2360 | |
---|
2374 | | - //Vector<Vertex> sortedcollider; |
---|
2375 | | - Object3D avoider; |
---|
2376 | | - Vector<Double> parameters = new Vector<Double>(); // serial issue |
---|
2377 | | - |
---|
2378 | 2361 | Vertex ClosestPoint(Vector<Vertex> collider, DynamicNode N, int startindex, int endindex, int sortaxis) |
---|
2379 | 2362 | { |
---|
2380 | 2363 | if (startindex == endindex) |
---|
.. | .. |
---|
2468 | 2451 | |
---|
2469 | 2452 | for (int i=collider.size(); --i>=0;) |
---|
2470 | 2453 | { |
---|
2471 | | - if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0) |
---|
| 2454 | + // Why? 3 dec 2018 |
---|
| 2455 | + if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0.5) |
---|
2472 | 2456 | continue; |
---|
2473 | 2457 | |
---|
2474 | 2458 | temp.set(N.position); |
---|
.. | .. |
---|
2486 | 2470 | } |
---|
2487 | 2471 | } |
---|
2488 | 2472 | |
---|
2489 | | - return cp; |
---|
| 2473 | + return mindist2 < 1 ? cp : null; |
---|
2490 | 2474 | } |
---|
2491 | 2475 | |
---|
2492 | | - Point3D forceOn(DynamicNode N) |
---|
| 2476 | + class Avoider extends Force |
---|
| 2477 | + { |
---|
| 2478 | + static final long serialVersionUID = -8657094699711594990L; |
---|
| 2479 | + |
---|
| 2480 | + Avoider() |
---|
2493 | 2481 | { |
---|
2494 | | - force.x = 0; |
---|
2495 | | - force.y = 0; |
---|
2496 | | - force.z = 0; |
---|
2497 | | - |
---|
2498 | | - if (avoider.transientrep == null) |
---|
2499 | | - avoider.Revert(); |
---|
2500 | | - |
---|
2501 | | - if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed) |
---|
2502 | | - return force; |
---|
2503 | | - |
---|
2504 | | - ResetGlobalTransform(); |
---|
2505 | | - if (N.closestpoint == null) |
---|
2506 | | - { |
---|
2507 | | - //avoider.bRep.GetVertex(0); // "sort" |
---|
2508 | | - |
---|
2509 | | - ResetGlobalTransform(); |
---|
2510 | | - |
---|
2511 | | - N.closestpoint = ClosestPoint(avoider.transientrep./*sortedV*/vertices, N, 0,avoider.transientrep./*sortedV*/vertices.size(), 0); |
---|
2512 | | - |
---|
2513 | | - if (N.closestpoint == null) // ???? |
---|
2514 | | - return force; |
---|
2515 | | - } |
---|
2516 | | - |
---|
2517 | | - if (avoider == This()) |
---|
2518 | | - { |
---|
2519 | | - // good but must freeze the order first... not really... |
---|
2520 | | - // if (cp.index < ((Vertex)N.position).index) |
---|
2521 | | - // return force; |
---|
2522 | | - } |
---|
2523 | | - |
---|
2524 | | - if (normalpusH != 0) // && cp == null /*???*/) // speed == 0) |
---|
2525 | | - { |
---|
| 2482 | + } |
---|
| 2483 | + |
---|
| 2484 | + Avoider(Object3D col) |
---|
| 2485 | + { |
---|
| 2486 | + SetAvoider(col); |
---|
| 2487 | + } |
---|
| 2488 | + |
---|
| 2489 | + void Avoidance(DynamicNode N) |
---|
| 2490 | + { |
---|
2526 | 2491 | temp.set(N.position); |
---|
2527 | 2492 | if (avoider != This()) |
---|
2528 | 2493 | { |
---|
.. | .. |
---|
2530 | 2495 | temp2.mul(0.001); |
---|
2531 | 2496 | temp.sub(temp2); // push outside because of mesh artifacts |
---|
2532 | 2497 | } |
---|
2533 | | - |
---|
| 2498 | + |
---|
2534 | 2499 | vect1.set(N.closestpoint); |
---|
2535 | | - |
---|
| 2500 | + |
---|
2536 | 2501 | LA.xformPos(vect1,toRoot,vect1); |
---|
2537 | 2502 | //avoider.TransformToWorld(vect1, vect1); |
---|
2538 | | - |
---|
| 2503 | + |
---|
2539 | 2504 | temp.sub(vect1); |
---|
2540 | | - |
---|
| 2505 | + |
---|
2541 | 2506 | double distance = Math.sqrt(temp.length2()); |
---|
2542 | | - |
---|
| 2507 | + |
---|
2543 | 2508 | if (distance < 0.01) |
---|
2544 | 2509 | { |
---|
2545 | 2510 | temp2.set(N.closestpoint.norm); |
---|
.. | .. |
---|
2553 | 2518 | if (IsAutoFreeze()) |
---|
2554 | 2519 | dot = -dot; |
---|
2555 | 2520 | |
---|
2556 | | - temp.mul(normalpusH/*/distance*/*-dot/Math.sqrt(distance)); |
---|
| 2521 | + temp.mul(normalpush/*/distance*/*-dot/Math.sqrt(distance)); |
---|
2557 | 2522 | force.add(temp); |
---|
2558 | 2523 | } |
---|
| 2524 | + } |
---|
| 2525 | + |
---|
| 2526 | + void Attraction(DynamicNode N) |
---|
| 2527 | + { |
---|
| 2528 | + temp.set(N.position); |
---|
| 2529 | + if (avoider != This()) |
---|
| 2530 | + { |
---|
| 2531 | + temp2.set(N.closestpoint.norm); |
---|
| 2532 | + temp2.mul(0.001); |
---|
| 2533 | + temp.sub(temp2); // push outside because of mesh artifacts |
---|
| 2534 | + } |
---|
| 2535 | + |
---|
| 2536 | + vect1.set(N.closestpoint); |
---|
| 2537 | + |
---|
| 2538 | + LA.xformPos(vect1,toRoot,vect1); |
---|
| 2539 | + //avoider.TransformToWorld(vect1, vect1); |
---|
| 2540 | + |
---|
| 2541 | + temp.sub(vect1); |
---|
| 2542 | + |
---|
| 2543 | + double distance = Math.sqrt(temp.length2()); |
---|
| 2544 | + |
---|
| 2545 | + //if (distance < 0.01) |
---|
| 2546 | + { |
---|
| 2547 | + temp2.set(N.closestpoint.norm); |
---|
| 2548 | + double dot = temp2.dot(temp); |
---|
| 2549 | + |
---|
| 2550 | +// if (dot > 0) |
---|
| 2551 | +// dot = 0; |
---|
| 2552 | + |
---|
| 2553 | + // normal pushing |
---|
| 2554 | + temp.set(N.closestpoint.norm); |
---|
| 2555 | +// if (IsAutoFreeze()) |
---|
| 2556 | +// dot = -dot; |
---|
| 2557 | + |
---|
| 2558 | + temp.mul(normalpush/*/distance*/ * -dot * distance); |
---|
| 2559 | + force.add(temp); |
---|
| 2560 | + } |
---|
| 2561 | + } |
---|
| 2562 | + |
---|
| 2563 | + void SetParameter(int index, double value) |
---|
| 2564 | + { |
---|
| 2565 | + parameters.setElementAt(new Double(value), index); |
---|
| 2566 | + } |
---|
| 2567 | + |
---|
| 2568 | + void SetAvoider(Object3D col) |
---|
| 2569 | + { |
---|
| 2570 | + avoider = col; |
---|
| 2571 | + } |
---|
| 2572 | + |
---|
| 2573 | + //Vector<Vertex> sortedcollider; |
---|
| 2574 | + Vector<Double> parameters = new Vector<Double>(); // serial issue |
---|
| 2575 | + |
---|
| 2576 | + Point3D forceOn(DynamicNode N) |
---|
| 2577 | + { |
---|
| 2578 | + force.x = 0; |
---|
| 2579 | + force.y = 0; |
---|
| 2580 | + force.z = 0; |
---|
| 2581 | + |
---|
| 2582 | + if (avoider.transientrep == null) |
---|
| 2583 | + avoider.Revert(); |
---|
| 2584 | + |
---|
| 2585 | + if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed) |
---|
| 2586 | + return force; |
---|
| 2587 | + |
---|
| 2588 | + ResetGlobalTransform(); |
---|
| 2589 | + if (!N.linked) |
---|
| 2590 | + { |
---|
| 2591 | + //avoider.bRep.GetVertex(0); // "sort" |
---|
| 2592 | + |
---|
| 2593 | + ResetGlobalTransform(); |
---|
| 2594 | + |
---|
| 2595 | + N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0); |
---|
| 2596 | + N.linked = true; |
---|
| 2597 | + } |
---|
| 2598 | + |
---|
| 2599 | + if (avoider == This()) |
---|
| 2600 | + { |
---|
| 2601 | + // good but must freeze the order first... not really... |
---|
| 2602 | + // if (cp.index < ((Vertex)N.position).index) |
---|
| 2603 | + // return force; |
---|
| 2604 | + } |
---|
| 2605 | + |
---|
| 2606 | + if (normalpush != 0) // && cp == null /*???*/) // speed == 0) |
---|
| 2607 | + { |
---|
| 2608 | + if (N.closestpoint == null) |
---|
| 2609 | + return force; |
---|
| 2610 | + |
---|
| 2611 | + //Avoidance(N); |
---|
| 2612 | + Attraction(N); |
---|
2559 | 2613 | } |
---|
2560 | 2614 | |
---|
2561 | 2615 | if (parameters.size() > 0) |
---|
.. | .. |
---|
2589 | 2643 | totalforce = new Point3D(); |
---|
2590 | 2644 | |
---|
2591 | 2645 | totalforce.set(0,0,0); |
---|
| 2646 | + |
---|
2592 | 2647 | if (forces.size() == 0) |
---|
2593 | 2648 | totalforce.set(super.forceOn(N)); |
---|
2594 | 2649 | |
---|
.. | .. |
---|
2659 | 2714 | force.y = 0; |
---|
2660 | 2715 | force.z = 0; |
---|
2661 | 2716 | |
---|
2662 | | - if (normalpusH != 0) // speed == 0) // Now normal force |
---|
| 2717 | + if (normalpush != 0) // speed == 0) // Now normal force |
---|
2663 | 2718 | { |
---|
2664 | 2719 | // temp.set(N.position); |
---|
2665 | 2720 | // temp.sub(Phys.reference); |
---|
.. | .. |
---|
2667 | 2722 | |
---|
2668 | 2723 | // normal pushing |
---|
2669 | 2724 | temp.set(N.normal); |
---|
2670 | | - temp.mul(normalpusH/distance); |
---|
| 2725 | + temp.mul(normalpush/distance); |
---|
2671 | 2726 | force.add(temp); |
---|
2672 | 2727 | } |
---|
2673 | 2728 | |
---|
.. | .. |
---|
2899 | 2954 | return force; |
---|
2900 | 2955 | } |
---|
2901 | 2956 | } |
---|
| 2957 | + |
---|
2902 | 2958 | static int TABLESAC = 1024; |
---|
2903 | 2959 | static double[] tablesac = new double[TABLESAC]; |
---|
2904 | 2960 | |
---|
.. | .. |
---|
2992 | 3048 | // mass = M; |
---|
2993 | 3049 | } // ??? |
---|
2994 | 3050 | |
---|
| 3051 | + if (avoider != null) |
---|
| 3052 | + { |
---|
| 3053 | + if (avoider.transientrep == null) |
---|
| 3054 | + avoider.Revert(); |
---|
| 3055 | + |
---|
| 3056 | + if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed) |
---|
| 3057 | + return force; |
---|
| 3058 | + |
---|
| 3059 | + ResetGlobalTransform(); |
---|
| 3060 | + if (!N.linked) |
---|
| 3061 | + { |
---|
| 3062 | + //avoider.bRep.GetVertex(0); // "sort" |
---|
| 3063 | + |
---|
| 3064 | + //ResetGlobalTransform(); |
---|
| 3065 | + |
---|
| 3066 | + N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0); |
---|
| 3067 | + N.linked = true; |
---|
| 3068 | + } |
---|
| 3069 | + |
---|
| 3070 | + if (N.closestpoint != null) |
---|
| 3071 | + { |
---|
| 3072 | + temp.set(N.position); |
---|
| 3073 | + vect1.set(N.closestpoint); |
---|
| 3074 | + LA.xformPos(vect1,toRoot,vect1); |
---|
| 3075 | + temp.sub(vect1); |
---|
| 3076 | + |
---|
| 3077 | + temp2.set(N.closestpoint.norm); |
---|
| 3078 | + double dot = temp2.dot(temp); |
---|
| 3079 | + |
---|
| 3080 | + if (dot < 0) |
---|
| 3081 | + mass = Float.NaN; |
---|
| 3082 | + } |
---|
| 3083 | + } |
---|
| 3084 | + |
---|
2995 | 3085 | force.x = 0; |
---|
2996 | 3086 | force.y = (float) (-acceleration * mass); |
---|
2997 | 3087 | force.z = 0; // -acceleration * mass * 1000 * Math.cos(time/234.0 + framecount*100); // (Math.random()*2 - 1); // |
---|
.. | .. |
---|
3188 | 3278 | } |
---|
3189 | 3279 | if (false) // isHandle) |
---|
3190 | 3280 | { |
---|
3191 | | - double K = Math.exp(-displacement*normalpusH); |
---|
| 3281 | + double K = Math.exp(-displacement*normalpush); |
---|
3192 | 3282 | magnitude /= (displacement*(1-K) + K); |
---|
3193 | 3283 | } |
---|
3194 | 3284 | |
---|