From b3ae4e889872ca0b9ca76f1d17b2f0b961226729 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Mon, 05 Aug 2019 21:48:55 -0400 Subject: [PATCH] Fix physics UI --- Torus.java | 69 +++++++++++++++++++++------------- 1 files changed, 43 insertions(+), 26 deletions(-) diff --git a/Torus.java b/Torus.java index 8f85353..4573395 100644 --- a/Torus.java +++ b/Torus.java @@ -2,6 +2,8 @@ class Torus extends Biparam implements java.io.Serializable { + static final long serialVersionUID = -7637054329820073252L; // Old + Torus() { inPnt = new cVector(); @@ -61,16 +63,25 @@ if (v == 1) v = 0; - double uAng = LA.toRadians((1-u) * 360); - double vAng = LA.toRadians(v * 360); - double x = (double)Math.cos(uAng) * (major + (double)Math.cos(vAng) * minor); - double y = (double)Math.sin(vAng) * minor; + double uAng = u * 2 * Math.PI; + double vAng = -v * 2 * Math.PI; + double cosua = Math.cos(uAng); + double sinua = Math.sin(uAng); + double cosva = Math.cos(vAng); + double sinva = Math.sin(vAng); + + double radius = (major + cosva * minor); + double x = cosua * radius; + double y = sinva * minor; if (Math.abs(y) < 1E-10) y = 0; // hashtable issue - double z = (double)Math.sin(uAng) * (major + (double)Math.cos(vAng) * minor); + + double z = sinua * radius; cVector tPos = LA.newVector(x, y, z); - double xx = (double)(Math.cos(uAng) * Math.cos(vAng)) * minor; - double zz = (double)(Math.sin(uAng) * Math.cos(vAng)) * minor; + + double xx = cosua * cosva * minor; + double zz = sinua * cosva * minor; + cVector tNorm = LA.newVector(xx, y, zz); Vertex temp = new Vertex(tPos); //temp.pos = tPos; // useless new @@ -107,55 +118,59 @@ return rad2 <= minor * minor; } - void drawEditHandles(ClickInfo info, int level) + void drawEditHandles(//ClickInfo info, + int level) { if (level == 0) { return; } else { - super.drawEditHandles(info, level); + super.drawEditHandles(//info, + level); cVector temp = LA.newVector(0, 0, minor); LA.xformPos(temp, toParent, temp); - Rectangle majorSpot = calcHotSpot(temp, info); + Rectangle majorSpot = calcHotSpot(temp); //, info); majorSpot.translate(4, 4); temp.x = major; temp.y = temp.z = 0; LA.xformPos(temp, toParent, temp); - Rectangle minorSpot = calcHotSpot(temp, info); + Rectangle minorSpot = calcHotSpot(temp); //, info); minorSpot.translate(4, 4); - info.g.setColor(Color.green); - info.g.fillRect(majorSpot.x, majorSpot.y, majorSpot.width, majorSpot.height); - info.g.fillRect(minorSpot.x, minorSpot.y, minorSpot.width, minorSpot.height); + clickInfo.g.setColor(Color.green); + clickInfo.g.fillRect(majorSpot.x, majorSpot.y, majorSpot.width, majorSpot.height); + clickInfo.g.fillRect(minorSpot.x, minorSpot.y, minorSpot.width, minorSpot.height); return; } } - boolean doEditClick(ClickInfo info, int level) + boolean doEditClick(//ClickInfo info, + int level) { if (level == 0) return false; hitSomething = 0; - if (super.doEditClick(info, level)) + if (super.doEditClick(//info, + level)) { hitSomething = 1; return true; } cVector temp = LA.newVector(0, 0, minor); LA.xformPos(temp, toParent, temp); - Rectangle majorSpot = calcHotSpot(temp, info); + Rectangle majorSpot = calcHotSpot(temp); //, info); majorSpot.translate(4, 4); temp.x = major; temp.y = temp.z = 0; LA.xformPos(temp, toParent, temp); - Rectangle minorSpot = calcHotSpot(temp, info); + Rectangle minorSpot = calcHotSpot(temp); //, info); minorSpot.translate(4, 4); - if (majorSpot.contains(info.x, info.y)) + if (majorSpot.contains(clickInfo.x, clickInfo.y)) { hitSomething = 2; startRad = major; } else - if (minorSpot.contains(info.x, info.y)) + if (minorSpot.contains(clickInfo.x, clickInfo.y)) { hitSomething = 3; startRad = minor; @@ -163,23 +178,25 @@ { return false; } - startX = info.x; + startX = clickInfo.x; return true; } - void doEditDrag(ClickInfo info) + void doEditDrag(//ClickInfo info, + boolean opposite) { if (hitSomething == 0) return; if (hitSomething == 1) { - super.doEditDrag(info); + super.doEditDrag(//info, + opposite); return; } - double deltaR = info.x - startX; + double deltaR = clickInfo.x - startX; //cVector delta = LA.newVector(info.x - startX, 0, 0); //LA.xformDir(delta, info.camera.fromScreen, delta); - deltaR /= 100 * info.camera.SCALE / info.camera.Distance(); + deltaR /= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance(); double newRad = startRad + deltaR; if (newRad < 0) newRad = 0; @@ -188,7 +205,7 @@ else minor = newRad; recalculate(); - info.pane.repaint(); + clickInfo.pane.repaint(); } double major; -- Gitblit v1.6.2