From 547c9203ab5d8e4bee36d1cbb453dfa36bbec4ef Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Tue, 27 Aug 2019 23:45:18 -0400 Subject: [PATCH] Test has big data. --- cSpring.java | 257 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 178 insertions(+), 79 deletions(-) diff --git a/cSpring.java b/cSpring.java index 2986693..b5d339c 100644 --- a/cSpring.java +++ b/cSpring.java @@ -10,7 +10,7 @@ boolean IsStatic() { - return !(live && (CameraPane.isLIVE() || CameraPane.waslive)); + return !(live && (Globals.isLIVE() || CameraPane.waslive)); } void Revert() @@ -82,7 +82,7 @@ // timestep double timestep = 1; - double normalpusH = 0; // 1; + double normalpush = 0; // 1; static float H0 = 1E1f; // aucune importance... // mass double M = 1; @@ -543,13 +543,13 @@ } // serial lost - void DrawNode0(CameraPane display) + void DrawNode0(iCameraPane display) { super.DrawNode(display, null, false); } - void DrawNode/*notused*/(CameraPane display, Object3D /*Composite*/ root, boolean selected) + void DrawNode/*notused*/(iCameraPane display, Object3D /*Composite*/ root, boolean selected) { // assert displaylist == -1; @@ -565,11 +565,11 @@ // } //new Exception().printStackTrace(); - GL gl = display.GetGL(); // getGL(); + GL gl = display.GetGL0(); // getGL(); //gl.glDisable(GL.GL_LIGHTING); - if (display.drawMode == display.SHADOW) + if (display.DrawMode() == display.SHADOW) { gl.glDisable(gl.GL_CULL_FACE); } @@ -762,7 +762,7 @@ gl.glEnd(); gl.glEnable(GL.GL_LIGHTING); /**/ - if (display.CULLFACE) + if (display.BackFaceCullMode()) { gl.glEnable(gl.GL_CULL_FACE); } @@ -775,7 +775,7 @@ // displaylist = 0; // june 2013 -1; //System.out.println("DRAW " + display.drawMode); - if (live && display.isLIVE() && display.drawMode == display.DEFAULT) + if (live && Globals.isLIVE() && display.DrawMode() == display.DEFAULT) { //System.out.println("UPDATE"); Phys.update(); @@ -967,6 +967,7 @@ for (int i = 0; i < allNodes.size(); i++) { DynamicNode dn = allNodes.get(i); + dn.linked = false; dn.closestpoint = null; } } @@ -1207,7 +1208,10 @@ } if (edges.size()%2 != 0) + { + new Exception().printStackTrace(); System.exit(0); + } } // if (clearsprings) @@ -1416,6 +1420,7 @@ //transient double rotangle; // Z of axis transient boolean reverse = false; + transient boolean linked = false; transient Vertex closestpoint = null; //Point3D lastForce = new Point3D(); @@ -1492,6 +1497,11 @@ } } } + + if (Double.isNaN(springForce.y)) + { + springForce.x = springForce.y = springForce.z = 0; + } } void DetectBoundary() @@ -1509,7 +1519,10 @@ second = springs.get((i+1)%springs.size()); if (first == second) + { + new Exception().printStackTrace(); System.exit(0); + } temp.set(first.GetOther(this).position); temp.sub(position); @@ -1639,7 +1652,10 @@ Spring second = springs.get((i+1)%springs.size()); if (first == second) + { + new Exception().printStackTrace(); System.exit(0); + } temp.set(first.GetOther(this).position); temp.sub(position); @@ -1708,7 +1724,7 @@ // Phys.matrix.Transform(normal); - if (position instanceof Vertex) + if (position instanceof Vertex && ((Vertex)position).norm != null) ((Vertex)position).norm.set(normal.x,normal.y,normal.z); } @@ -2339,28 +2355,7 @@ return this; } - class Avoider extends Force - { - static final long serialVersionUID = -8657094699711594990L; - - Avoider() - { - } - - Avoider(Object3D col) - { - SetAvoider(col); - } - - void SetParameter(int index, double value) - { - parameters.setElementAt(new Double(value), index); - } - - void SetAvoider(Object3D col) - { - avoider = col; - } + Object3D avoider; void ResetGlobalTransform() { @@ -2372,10 +2367,6 @@ transient double[][] toRoot; // = new double[4][4]; - //Vector<Vertex> sortedcollider; - Object3D avoider; - Vector<Double> parameters = new Vector<Double>(); // serial issue - Vertex ClosestPoint(Vector<Vertex> collider, DynamicNode N, int startindex, int endindex, int sortaxis) { if (startindex == endindex) @@ -2469,7 +2460,8 @@ for (int i=collider.size(); --i>=0;) { - if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0) + // Why? 3 dec 2018 + if (collider.get(i).norm.dot(((Vertex)N.position).norm) < 0.5) continue; temp.set(N.position); @@ -2487,43 +2479,24 @@ } } - return cp; + return mindist2 < 1 ? cp : null; } - Point3D forceOn(DynamicNode N) + class Avoider extends Force + { + static final long serialVersionUID = -8657094699711594990L; + + Avoider() { - force.x = 0; - force.y = 0; - force.z = 0; - - if (avoider.transientrep == null) - avoider.Revert(); - - if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed) - return force; - - ResetGlobalTransform(); - if (N.closestpoint == null) - { - //avoider.bRep.GetVertex(0); // "sort" - - ResetGlobalTransform(); - - N.closestpoint = ClosestPoint(avoider.transientrep./*sortedV*/vertices, N, 0,avoider.transientrep./*sortedV*/vertices.size(), 0); - - if (N.closestpoint == null) // ???? - return force; - } - - if (avoider == This()) - { - // good but must freeze the order first... not really... - // if (cp.index < ((Vertex)N.position).index) - // return force; - } - - if (normalpusH != 0) // && cp == null /*???*/) // speed == 0) - { + } + + Avoider(Object3D col) + { + SetAvoider(col); + } + + void Avoidance(DynamicNode N) + { temp.set(N.position); if (avoider != This()) { @@ -2531,16 +2504,16 @@ temp2.mul(0.001); temp.sub(temp2); // push outside because of mesh artifacts } - + vect1.set(N.closestpoint); - + LA.xformPos(vect1,toRoot,vect1); //avoider.TransformToWorld(vect1, vect1); - + temp.sub(vect1); - + double distance = Math.sqrt(temp.length2()); - + if (distance < 0.01) { temp2.set(N.closestpoint.norm); @@ -2554,9 +2527,98 @@ if (IsAutoFreeze()) dot = -dot; - temp.mul(normalpusH/*/distance*/*-dot/Math.sqrt(distance)); + temp.mul(normalpush/*/distance*/*-dot/Math.sqrt(distance)); force.add(temp); } + } + + void Attraction(DynamicNode N) + { + temp.set(N.position); + if (avoider != This()) + { + temp2.set(N.closestpoint.norm); + temp2.mul(0.001); + temp.sub(temp2); // push outside because of mesh artifacts + } + + vect1.set(N.closestpoint); + + LA.xformPos(vect1,toRoot,vect1); + //avoider.TransformToWorld(vect1, vect1); + + temp.sub(vect1); + + double distance = Math.sqrt(temp.length2()); + + //if (distance < 0.01) + { + temp2.set(N.closestpoint.norm); + double dot = temp2.dot(temp); + +// if (dot > 0) +// dot = 0; + + // normal pushing + temp.set(N.closestpoint.norm); +// if (IsAutoFreeze()) +// dot = -dot; + + temp.mul(normalpush/*/distance*/ * -dot * distance); + force.add(temp); + } + } + + void SetParameter(int index, double value) + { + parameters.setElementAt(new Double(value), index); + } + + void SetAvoider(Object3D col) + { + avoider = col; + } + + //Vector<Vertex> sortedcollider; + Vector<Double> parameters = new Vector<Double>(); // serial issue + + Point3D forceOn(DynamicNode N) + { + force.x = 0; + force.y = 0; + force.z = 0; + + if (avoider.transientrep == null) + avoider.Revert(); + + if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed) + return force; + + ResetGlobalTransform(); + if (!N.linked) + { + //avoider.bRep.GetVertex(0); // "sort" + + ResetGlobalTransform(); + + N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0); + N.linked = true; + } + + if (avoider == This()) + { + // good but must freeze the order first... not really... + // if (cp.index < ((Vertex)N.position).index) + // return force; + } + + if (normalpush != 0) // && cp == null /*???*/) // speed == 0) + { + if (N.closestpoint == null) + return force; + + //Avoidance(N); + Attraction(N); } if (parameters.size() > 0) @@ -2590,6 +2652,7 @@ totalforce = new Point3D(); totalforce.set(0,0,0); + if (forces.size() == 0) totalforce.set(super.forceOn(N)); @@ -2660,7 +2723,7 @@ force.y = 0; force.z = 0; - if (normalpusH != 0) // speed == 0) // Now normal force + if (normalpush != 0) // speed == 0) // Now normal force { // temp.set(N.position); // temp.sub(Phys.reference); @@ -2668,7 +2731,7 @@ // normal pushing temp.set(N.normal); - temp.mul(normalpusH/distance); + temp.mul(normalpush/distance); force.add(temp); } @@ -2900,6 +2963,7 @@ return force; } } + static int TABLESAC = 1024; static double[] tablesac = new double[TABLESAC]; @@ -2993,6 +3057,40 @@ // mass = M; } // ??? + if (avoider != null) + { + if (avoider.transientrep == null) + avoider.Revert(); + + if (avoider.transientrep == null || avoider.transientrep.VertexCount() == 0 || avoider.transientrep.trimmed) + return force; + + ResetGlobalTransform(); + if (!N.linked) + { + //avoider.bRep.GetVertex(0); // "sort" + + //ResetGlobalTransform(); + + N.closestpoint = ClosestPoint(avoider.transientrep.vertices, N, 0,avoider.transientrep.vertices.size(), 0); + N.linked = true; + } + + if (N.closestpoint != null) + { + temp.set(N.position); + vect1.set(N.closestpoint); + LA.xformPos(vect1,toRoot,vect1); + temp.sub(vect1); + + temp2.set(N.closestpoint.norm); + double dot = temp2.dot(temp); + + if (dot < 0) + mass = Float.NaN; + } + } + force.x = 0; force.y = (float) (-acceleration * mass); force.z = 0; // -acceleration * mass * 1000 * Math.cos(time/234.0 + framecount*100); // (Math.random()*2 - 1); // @@ -3189,7 +3287,7 @@ } if (false) // isHandle) { - double K = Math.exp(-displacement*normalpusH); + double K = Math.exp(-displacement*normalpush); magnitude /= (displacement*(1-K) + K); } @@ -3200,6 +3298,7 @@ if (N2.mass == Float.MAX_VALUE) { + new Exception().printStackTrace(); System.exit(0); magnitude *= solidity; // * K; -- Gitblit v1.6.2