1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import NET.worlds.console.Main;
import java.io.IOException;
import java.util.Vector;
public class Transform extends SuperRoot {
private static Vector<Transform> recycled = new Vector<Transform>();
private int transformID;
private float xScale;
private float yScale;
private float zScale;
private static Object classCookie = new Object();
static {
nativeInit();
}
public static native void nativeInit();
public static Transform make() {
assert Main.isMainThread();
int last = recycled.size() - 1;
if (last == -1) {
return new Transform();
} else {
Transform ret = recycled.elementAt(last);
recycled.removeElementAt(last);
return ret;
}
}
public void recycle() {
if (recycled.size() < 100) {
this.makeIdentity();
recycled.addElement(this);
}
}
protected Transform() {
this.makeIdentity();
}
public native float getX();
public native float getY();
public native float getZ();
public Point3Temp getPosition() {
return Point3Temp.make(this.getX(), this.getY(), this.getZ());
}
public void setZ(float z) {
this.moveTo(this.getX(), this.getY(), z);
}
public float getScaleX() {
return this.xScale;
}
public float getScaleY() {
return this.yScale;
}
public float getScaleZ() {
return this.zScale;
}
public Point3Temp getScale() {
return Point3Temp.make(this.getScaleX(), this.getScaleY(), this.getScaleZ());
}
public float getTotalScale() {
return (this.getScaleX() + this.getScaleY() + this.getScaleZ()) / 3.0F;
}
public native float getYaw();
public native float getPitch();
public native float getSpin(Point3Temp var1);
protected void noteTransformChange() {
}
public Transform raise(float z) {
return this.moveBy(0.0F, 0.0F, z);
}
public Transform lower(float z) {
return this.moveBy(0.0F, 0.0F, -z);
}
public Transform yaw(float a) {
return this.spin(0.0F, 0.0F, 1.0F, a);
}
public Transform roll(float a) {
return this.spin(0.0F, 1.0F, 0.0F, a);
}
public Transform pitch(float a) {
return this.spin(1.0F, 0.0F, 0.0F, a);
}
public Transform scale(float s) {
return this.scale(s, s, s);
}
@Override
protected void finalize() {
this.nativeFinalize();
super.finalize();
}
public native Transform pre(Transform var1);
public Transform post(Transform t) {
Point3Temp v = t.getScale();
if (!this.checkPostScale(v)) {
return this;
} else {
this.xScale = this.xScale * v.x;
this.yScale = this.yScale * v.y;
this.zScale = this.zScale * v.z;
return this.postHelper(t);
}
}
private boolean checkPostScale(Point3Temp v) {
if (this.getSpin(Point3Temp.make()) != 0.0F && (v.x != v.y || v.y != v.z)) {
Console.println(Console.message("non-uniform"));
return false;
} else {
return true;
}
}
private native Transform postHelper(Transform var1);
public native Transform makeIdentity();
public Transform moveBy(Point3Temp p) {
return this.moveBy(p.x, p.y, p.z);
}
public native Transform moveBy(float var1, float var2, float var3);
public Transform moveTo(Point3Temp p) {
return this.moveTo(p.x, p.y, p.z);
}
public native Transform moveTo(float var1, float var2, float var3);
public native Transform premoveBy(float var1, float var2, float var3);
public native Transform scale(float var1, float var2, float var3);
public Transform scale(Point3Temp s) {
return this.scale(s.x, s.y, s.z);
}
public void setScale(float x, float y, float z) {
this.scale(x / this.xScale, y / this.yScale, z / this.zScale);
}
public void setScale(Point3Temp s) {
this.setScale(s.x, s.y, s.z);
}
public Transform postscale(float x, float y, float z) {
return this.postscale(Point3Temp.make(x, y, z));
}
public Transform postscale(Point3Temp s) {
if (!this.checkPostScale(s)) {
return this;
} else {
this.xScale = this.xScale * s.x;
this.yScale = this.yScale * s.y;
this.zScale = this.zScale * s.z;
return this.postscaleHelper(s.x, s.y, s.z);
}
}
private native Transform postscaleHelper(float var1, float var2, float var3);
public Transform worldScale(float x, float y, float z) {
return this.worldScale(Point3Temp.make(x, y, z));
}
public Transform worldScale(Point3Temp s) {
return !this.checkPostScale(s) ? this : this.scale(s);
}
public native Transform spin(float var1, float var2, float var3, float var4);
public Transform spin(Point3Temp p, float a) {
return this.spin(p.x, p.y, p.z, a);
}
public Transform postspin(Point3Temp axis, float a) {
return this.postspin(axis.x, axis.y, axis.z, a);
}
public native Transform postspin(float var1, float var2, float var3, float var4);
public Transform worldSpin(float x, float y, float z, float a) {
return this.spin(this.worldVecToObjectVec(Point3Temp.make(x, y, z)), a);
}
private native void nativeFinalize();
public Transform getTransform() {
Transform t = make();
t.setTransform(this);
return t;
}
public native void setTransform(Transform var1);
public native Transform invert();
public Transform getObjectToWorldMatrix() {
return this.getTransform();
}
private Point3Temp worldVecToObjectVec(Point3Temp worldVec) {
Transform inv = this.getObjectToWorldMatrix().invert();
Point3Temp p = Point3Temp.make(worldVec).vectorTimes(inv).times(this.getScale());
inv.recycle();
return p;
}
@Override
public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
Object ret = null;
switch (index - offset) {
case 0:
if (mode == 0) {
ret = TransformPropertyEditor.make(new Property(this, index, "Transform"));
} else if (mode == 1) {
ret = this.getTransform();
} else if (mode == 2) {
this.setTransform((Transform)value);
}
break;
default:
ret = super.properties(index, offset + 1, mode, value);
}
return ret;
}
@Override
public void saveState(Saver s) throws IOException {
s.saveVersion(2, classCookie);
super.saveState(s);
s.saveFloat(this.xScale);
s.saveFloat(this.yScale);
s.saveFloat(this.zScale);
float[] guts = this.getGuts();
for (int i = 0; i < 16; i++) {
s.saveFloat(guts[i]);
}
}
@Override
public void restoreState(Restorer r) throws IOException, TooNewException {
switch (r.restoreVersion(classCookie)) {
case 1:
super.restoreState(r);
case 0:
this.xScale = this.yScale = this.zScale = r.restoreFloat();
float[] guts = new float[16];
for (int i = 0; i < 16; i++) {
guts[i] = r.restoreFloat();
}
this.setGuts(guts);
break;
case 2:
super.restoreState(r);
this.xScale = r.restoreFloat();
this.yScale = r.restoreFloat();
this.zScale = r.restoreFloat();
float[] guts = new float[16];
for (int i = 0; i < 16; i++) {
guts[i] = r.restoreFloat();
}
this.setGuts(guts);
break;
default:
throw new TooNewException();
}
}
private native float[] getGuts();
public native boolean isTransformEqual(Transform var1);
private native void setGuts(float[] var1);
public String toTransformSubstring() {
Point3Temp axis = Point3Temp.make();
float angle = this.getSpin(axis);
Point3Temp pos = this.getPosition();
return angle == 0.0F && this.xScale == 1.0F && this.yScale == 1.0F && this.zScale == 1.0F && pos.x == 0.0F && pos.y == 0.0F && pos.z == 0.0F
? "[identity]"
: "[pos ("
+ pos
+ "), scale ("
+ (this.xScale == this.yScale && this.yScale == this.zScale ? "" + this.xScale : this.xScale + "," + this.yScale + "," + this.zScale)
+ "), rot ("
+ axis
+ "@"
+ angle
+ ")]";
}
@Override
public String toString() {
return this.getName() + this.toTransformSubstring();
}
public Transform printGuts() {
float[] arr = this.getGuts();
assert arr.length == 16;
String[] strs = new String[16];
int maxStr = 0;
for (int i = 0; i < 16; i++) {
strs[i] = Float.toString(arr[i]);
maxStr = Math.max(maxStr, strs[i].length());
}
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
String s = strs[j * 4 + k];
int pad = maxStr - s.length() + 1;
System.out.print(s);
while (pad-- != 0) {
System.out.print(" ");
}
}
System.out.println("");
}
return this;
}
}
|