Normand Briere
2019-08-16 64e20f390e4b8e58bd0006dde8fa10fba1dac1d5
Torus.java
....@@ -2,6 +2,8 @@
22
33 class Torus extends Biparam implements java.io.Serializable
44 {
5
+ static final long serialVersionUID = -7637054329820073252L; // Old
6
+
57 Torus()
68 {
79 inPnt = new cVector();
....@@ -54,6 +56,11 @@
5456 buffer.append("}\n");
5557 }
5658
59
+ double uStretch()
60
+ {
61
+ return 6; // Actually 6.28 (I think)
62
+ }
63
+
5764 Vertex biparamFunction(double u, double v)
5865 {
5966 if (u == 1)
....@@ -61,21 +68,33 @@
6168 if (v == 1)
6269 v = 0;
6370
64
- double uAng = LA.toRadians((1-u) * 360);
65
- double vAng = LA.toRadians(v * 360);
66
- double x = (double)Math.cos(uAng) * (major + (double)Math.cos(vAng) * minor);
67
- double y = (double)Math.sin(vAng) * minor;
71
+ double uAng = u * 2 * Math.PI;
72
+ double vAng = -v * 2 * Math.PI;
73
+ double cosua = Math.cos(uAng);
74
+ double sinua = Math.sin(uAng);
75
+ double cosva = Math.cos(vAng);
76
+ double sinva = Math.sin(vAng);
77
+
78
+ double radius = (major + cosva * minor);
79
+ double x = cosua * radius;
80
+ double y = sinva * minor;
6881 if (Math.abs(y) < 1E-10)
6982 y = 0; // hashtable issue
70
- double z = (double)Math.sin(uAng) * (major + (double)Math.cos(vAng) * minor);
83
+
84
+ double z = sinua * radius;
7185 cVector tPos = LA.newVector(x, y, z);
72
- double xx = (double)(Math.cos(uAng) * Math.cos(vAng)) * minor;
73
- double zz = (double)(Math.sin(uAng) * Math.cos(vAng)) * minor;
86
+
87
+ double xx = cosua * cosva * minor;
88
+ double zz = sinua * cosva * minor;
89
+
7490 cVector tNorm = LA.newVector(xx, y, zz);
7591 Vertex temp = new Vertex(tPos);
7692 //temp.pos = tPos; // useless new
7793 temp.norm = tNorm;
7894 LA.vecNormalize(temp.norm);
95
+
96
+ temp.y += minor;
97
+
7998 return temp;
8099 }
81100
....@@ -107,55 +126,59 @@
107126 return rad2 <= minor * minor;
108127 }
109128
110
- void drawEditHandles(ClickInfo info, int level)
129
+ void drawEditHandles(//ClickInfo info,
130
+ int level)
111131 {
112132 if (level == 0)
113133 {
114134 return;
115135 } else
116136 {
117
- super.drawEditHandles(info, level);
137
+ super.drawEditHandles(//info,
138
+ level);
118139 cVector temp = LA.newVector(0, 0, minor);
119140 LA.xformPos(temp, toParent, temp);
120
- Rectangle majorSpot = calcHotSpot(temp, info);
141
+ Rectangle majorSpot = calcHotSpot(temp); //, info);
121142 majorSpot.translate(4, 4);
122143 temp.x = major;
123144 temp.y = temp.z = 0;
124145 LA.xformPos(temp, toParent, temp);
125
- Rectangle minorSpot = calcHotSpot(temp, info);
146
+ Rectangle minorSpot = calcHotSpot(temp); //, info);
126147 minorSpot.translate(4, 4);
127
- info.g.setColor(Color.green);
128
- info.g.fillRect(majorSpot.x, majorSpot.y, majorSpot.width, majorSpot.height);
129
- info.g.fillRect(minorSpot.x, minorSpot.y, minorSpot.width, minorSpot.height);
148
+ clickInfo.g.setColor(Color.green);
149
+ clickInfo.g.fillRect(majorSpot.x, majorSpot.y, majorSpot.width, majorSpot.height);
150
+ clickInfo.g.fillRect(minorSpot.x, minorSpot.y, minorSpot.width, minorSpot.height);
130151 return;
131152 }
132153 }
133154
134
- boolean doEditClick(ClickInfo info, int level)
155
+ boolean doEditClick(//ClickInfo info,
156
+ int level)
135157 {
136158 if (level == 0)
137159 return false;
138160 hitSomething = 0;
139
- if (super.doEditClick(info, level))
161
+ if (super.doEditClick(//info,
162
+ level))
140163 {
141164 hitSomething = 1;
142165 return true;
143166 }
144167 cVector temp = LA.newVector(0, 0, minor);
145168 LA.xformPos(temp, toParent, temp);
146
- Rectangle majorSpot = calcHotSpot(temp, info);
169
+ Rectangle majorSpot = calcHotSpot(temp); //, info);
147170 majorSpot.translate(4, 4);
148171 temp.x = major;
149172 temp.y = temp.z = 0;
150173 LA.xformPos(temp, toParent, temp);
151
- Rectangle minorSpot = calcHotSpot(temp, info);
174
+ Rectangle minorSpot = calcHotSpot(temp); //, info);
152175 minorSpot.translate(4, 4);
153
- if (majorSpot.contains(info.x, info.y))
176
+ if (majorSpot.contains(clickInfo.x, clickInfo.y))
154177 {
155178 hitSomething = 2;
156179 startRad = major;
157180 } else
158
- if (minorSpot.contains(info.x, info.y))
181
+ if (minorSpot.contains(clickInfo.x, clickInfo.y))
159182 {
160183 hitSomething = 3;
161184 startRad = minor;
....@@ -163,23 +186,25 @@
163186 {
164187 return false;
165188 }
166
- startX = info.x;
189
+ startX = clickInfo.x;
167190 return true;
168191 }
169192
170
- void doEditDrag(ClickInfo info)
193
+ void doEditDrag(//ClickInfo info,
194
+ boolean opposite)
171195 {
172196 if (hitSomething == 0)
173197 return;
174198 if (hitSomething == 1)
175199 {
176
- super.doEditDrag(info);
200
+ super.doEditDrag(//info,
201
+ opposite);
177202 return;
178203 }
179
- double deltaR = info.x - startX;
204
+ double deltaR = clickInfo.x - startX;
180205 //cVector delta = LA.newVector(info.x - startX, 0, 0);
181206 //LA.xformDir(delta, info.camera.fromScreen, delta);
182
- deltaR /= 100 * info.camera.SCALE / info.camera.Distance();
207
+ deltaR /= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
183208 double newRad = startRad + deltaR;
184209 if (newRad < 0)
185210 newRad = 0;
....@@ -188,7 +213,7 @@
188213 else
189214 minor = newRad;
190215 recalculate();
191
- info.pane.repaint();
216
+ clickInfo.pane.repaint();
192217 }
193218
194219 double major;