Normand Briere
2019-08-06 b3ae4e889872ca0b9ca76f1d17b2f0b961226729
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();
....@@ -61,16 +63,25 @@
6163 if (v == 1)
6264 v = 0;
6365
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;
66
+ double uAng = u * 2 * Math.PI;
67
+ double vAng = -v * 2 * Math.PI;
68
+ double cosua = Math.cos(uAng);
69
+ double sinua = Math.sin(uAng);
70
+ double cosva = Math.cos(vAng);
71
+ double sinva = Math.sin(vAng);
72
+
73
+ double radius = (major + cosva * minor);
74
+ double x = cosua * radius;
75
+ double y = sinva * minor;
6876 if (Math.abs(y) < 1E-10)
6977 y = 0; // hashtable issue
70
- double z = (double)Math.sin(uAng) * (major + (double)Math.cos(vAng) * minor);
78
+
79
+ double z = sinua * radius;
7180 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;
81
+
82
+ double xx = cosua * cosva * minor;
83
+ double zz = sinua * cosva * minor;
84
+
7485 cVector tNorm = LA.newVector(xx, y, zz);
7586 Vertex temp = new Vertex(tPos);
7687 //temp.pos = tPos; // useless new
....@@ -107,55 +118,59 @@
107118 return rad2 <= minor * minor;
108119 }
109120
110
- void drawEditHandles(ClickInfo info, int level)
121
+ void drawEditHandles(//ClickInfo info,
122
+ int level)
111123 {
112124 if (level == 0)
113125 {
114126 return;
115127 } else
116128 {
117
- super.drawEditHandles(info, level);
129
+ super.drawEditHandles(//info,
130
+ level);
118131 cVector temp = LA.newVector(0, 0, minor);
119132 LA.xformPos(temp, toParent, temp);
120
- Rectangle majorSpot = calcHotSpot(temp, info);
133
+ Rectangle majorSpot = calcHotSpot(temp); //, info);
121134 majorSpot.translate(4, 4);
122135 temp.x = major;
123136 temp.y = temp.z = 0;
124137 LA.xformPos(temp, toParent, temp);
125
- Rectangle minorSpot = calcHotSpot(temp, info);
138
+ Rectangle minorSpot = calcHotSpot(temp); //, info);
126139 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);
140
+ clickInfo.g.setColor(Color.green);
141
+ clickInfo.g.fillRect(majorSpot.x, majorSpot.y, majorSpot.width, majorSpot.height);
142
+ clickInfo.g.fillRect(minorSpot.x, minorSpot.y, minorSpot.width, minorSpot.height);
130143 return;
131144 }
132145 }
133146
134
- boolean doEditClick(ClickInfo info, int level)
147
+ boolean doEditClick(//ClickInfo info,
148
+ int level)
135149 {
136150 if (level == 0)
137151 return false;
138152 hitSomething = 0;
139
- if (super.doEditClick(info, level))
153
+ if (super.doEditClick(//info,
154
+ level))
140155 {
141156 hitSomething = 1;
142157 return true;
143158 }
144159 cVector temp = LA.newVector(0, 0, minor);
145160 LA.xformPos(temp, toParent, temp);
146
- Rectangle majorSpot = calcHotSpot(temp, info);
161
+ Rectangle majorSpot = calcHotSpot(temp); //, info);
147162 majorSpot.translate(4, 4);
148163 temp.x = major;
149164 temp.y = temp.z = 0;
150165 LA.xformPos(temp, toParent, temp);
151
- Rectangle minorSpot = calcHotSpot(temp, info);
166
+ Rectangle minorSpot = calcHotSpot(temp); //, info);
152167 minorSpot.translate(4, 4);
153
- if (majorSpot.contains(info.x, info.y))
168
+ if (majorSpot.contains(clickInfo.x, clickInfo.y))
154169 {
155170 hitSomething = 2;
156171 startRad = major;
157172 } else
158
- if (minorSpot.contains(info.x, info.y))
173
+ if (minorSpot.contains(clickInfo.x, clickInfo.y))
159174 {
160175 hitSomething = 3;
161176 startRad = minor;
....@@ -163,23 +178,25 @@
163178 {
164179 return false;
165180 }
166
- startX = info.x;
181
+ startX = clickInfo.x;
167182 return true;
168183 }
169184
170
- void doEditDrag(ClickInfo info)
185
+ void doEditDrag(//ClickInfo info,
186
+ boolean opposite)
171187 {
172188 if (hitSomething == 0)
173189 return;
174190 if (hitSomething == 1)
175191 {
176
- super.doEditDrag(info);
192
+ super.doEditDrag(//info,
193
+ opposite);
177194 return;
178195 }
179
- double deltaR = info.x - startX;
196
+ double deltaR = clickInfo.x - startX;
180197 //cVector delta = LA.newVector(info.x - startX, 0, 0);
181198 //LA.xformDir(delta, info.camera.fromScreen, delta);
182
- deltaR /= 100 * info.camera.SCALE / info.camera.Distance();
199
+ deltaR /= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
183200 double newRad = startRad + deltaR;
184201 if (newRad < 0)
185202 newRad = 0;
....@@ -188,7 +205,7 @@
188205 else
189206 minor = newRad;
190207 recalculate();
191
- info.pane.repaint();
208
+ clickInfo.pane.repaint();
192209 }
193210
194211 double major;