/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.Console; /* */ import NET.worlds.console.Main; /* */ import java.io.IOException; /* */ import java.io.PrintStream; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class Transform /* */ extends SuperRoot /* */ { /* */ static /* */ { /* 82 */ nativeInit(); /* */ } /* */ /* */ /* */ /* */ /* */ /* 89 */ private static Vector recycled = new Vector(); /* */ private int transformID; /* */ private float xScale; /* */ private float yScale; /* */ private float zScale; /* */ /* */ public static native void nativeInit(); /* */ /* 97 */ public static Transform make() { assert (Main.isMainThread()); /* */ /* 99 */ int last = recycled.size() - 1; /* 100 */ if (last == -1) { /* 101 */ return new Transform(); /* */ } /* 103 */ Transform ret = (Transform)recycled.elementAt(last); /* 104 */ recycled.removeElementAt(last); /* */ /* 106 */ return ret; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void recycle() /* */ { /* 117 */ if (recycled.size() < 100) /* */ { /* */ /* 120 */ makeIdentity(); /* */ /* 122 */ recycled.addElement(this); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ protected Transform() /* */ { /* 131 */ makeIdentity(); /* */ } /* */ /* */ /* */ public native float getX(); /* */ /* */ /* */ public native float getY(); /* */ /* */ /* */ public native float getZ(); /* */ /* */ public Point3Temp getPosition() /* */ { /* 145 */ return Point3Temp.make(getX(), getY(), getZ()); /* */ } /* */ /* */ public void setZ(float z) { /* 149 */ moveTo(getX(), getY(), z); /* */ } /* */ /* */ public float getScaleX() /* */ { /* 154 */ return this.xScale; /* */ } /* */ /* */ public float getScaleY() /* */ { /* 159 */ return this.yScale; /* */ } /* */ /* */ public float getScaleZ() /* */ { /* 164 */ return this.zScale; /* */ } /* */ /* */ public Point3Temp getScale() /* */ { /* 169 */ return Point3Temp.make(getScaleX(), getScaleY(), getScaleZ()); /* */ } /* */ /* */ /* */ /* */ public float getTotalScale() /* */ { /* 176 */ return (getScaleX() + getScaleY() + getScaleZ()) / 3.0F; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public native float getYaw(); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public native float getPitch(); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public native float getSpin(Point3Temp paramPoint3Temp); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ protected void noteTransformChange() {} /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public Transform raise(float z) /* */ { /* 225 */ return moveBy(0.0F, 0.0F, z); /* */ } /* */ /* */ public Transform lower(float z) /* */ { /* 230 */ return moveBy(0.0F, 0.0F, -z); /* */ } /* */ /* */ public Transform yaw(float a) /* */ { /* 235 */ return spin(0.0F, 0.0F, 1.0F, a); /* */ } /* */ /* */ public Transform roll(float a) /* */ { /* 240 */ return spin(0.0F, 1.0F, 0.0F, a); /* */ } /* */ /* */ public Transform pitch(float a) /* */ { /* 245 */ return spin(1.0F, 0.0F, 0.0F, a); /* */ } /* */ /* */ public Transform scale(float s) /* */ { /* 250 */ return scale(s, s, s); /* */ } /* */ /* */ protected void finalize() /* */ { /* 255 */ nativeFinalize(); /* 256 */ super.finalize(); /* */ } /* */ /* */ /* */ /* */ /* */ public native Transform pre(Transform paramTransform); /* */ /* */ /* */ /* */ /* */ public Transform post(Transform t) /* */ { /* 269 */ Point3Temp v = t.getScale(); /* */ /* */ /* 272 */ if (!checkPostScale(v)) { /* 273 */ return this; /* */ } /* */ /* 276 */ this.xScale *= v.x; /* 277 */ this.yScale *= v.y; /* 278 */ this.zScale *= v.z; /* */ /* */ /* 281 */ return postHelper(t); /* */ } /* */ /* */ private boolean checkPostScale(Point3Temp v) /* */ { /* 286 */ if ((getSpin(Point3Temp.make()) == 0.0F) || ((v.x == v.y) && (v.y == v.z))) /* 287 */ return true; /* 288 */ Console.println(Console.message("non-uniform")); /* 289 */ return false; /* */ } /* */ /* */ /* */ /* */ /* */ private native Transform postHelper(Transform paramTransform); /* */ /* */ /* */ /* */ /* */ public native Transform makeIdentity(); /* */ /* */ /* */ /* */ public Transform moveBy(Point3Temp p) /* */ { /* 306 */ return moveBy(p.x, p.y, p.z); /* */ } /* */ /* */ /* */ /* */ public native Transform moveBy(float paramFloat1, float paramFloat2, float paramFloat3); /* */ /* */ /* */ /* */ public Transform moveTo(Point3Temp p) /* */ { /* 317 */ return moveTo(p.x, p.y, p.z); /* */ } /* */ /* */ /* */ /* */ public native Transform moveTo(float paramFloat1, float paramFloat2, float paramFloat3); /* */ /* */ /* */ /* */ public native Transform premoveBy(float paramFloat1, float paramFloat2, float paramFloat3); /* */ /* */ /* */ public native Transform scale(float paramFloat1, float paramFloat2, float paramFloat3); /* */ /* */ /* */ public Transform scale(Point3Temp s) /* */ { /* 334 */ return scale(s.x, s.y, s.z); /* */ } /* */ /* */ public void setScale(float x, float y, float z) /* */ { /* 339 */ scale(x / this.xScale, y / this.yScale, z / this.zScale); /* */ } /* */ /* */ public void setScale(Point3Temp s) /* */ { /* 344 */ setScale(s.x, s.y, s.z); /* */ } /* */ /* */ public Transform postscale(float x, float y, float z) /* */ { /* 349 */ return postscale(Point3Temp.make(x, y, z)); /* */ } /* */ /* */ /* */ public Transform postscale(Point3Temp s) /* */ { /* 355 */ if (!checkPostScale(s)) { /* 356 */ return this; /* */ } /* */ /* 359 */ this.xScale *= s.x; /* 360 */ this.yScale *= s.y; /* 361 */ this.zScale *= s.z; /* */ /* */ /* */ /* 365 */ return postscaleHelper(s.x, s.y, s.z); /* */ } /* */ /* */ /* */ /* */ /* */ private native Transform postscaleHelper(float paramFloat1, float paramFloat2, float paramFloat3); /* */ /* */ /* */ /* */ /* */ public Transform worldScale(float x, float y, float z) /* */ { /* 378 */ return worldScale(Point3Temp.make(x, y, z)); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public Transform worldScale(Point3Temp s) /* */ { /* 387 */ if (!checkPostScale(s)) { /* 388 */ return this; /* */ } /* */ /* */ /* 392 */ return scale(s); /* */ } /* */ /* */ /* */ public native Transform spin(float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4); /* */ /* */ public Transform spin(Point3Temp p, float a) /* */ { /* 400 */ return spin(p.x, p.y, p.z, a); /* */ } /* */ /* */ public Transform postspin(Point3Temp axis, float a) /* */ { /* 405 */ return postspin(axis.x, axis.y, axis.z, a); /* */ } /* */ /* */ /* */ /* */ /* */ public native Transform postspin(float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4); /* */ /* */ /* */ /* */ public Transform worldSpin(float x, float y, float z, float a) /* */ { /* 417 */ return spin(worldVecToObjectVec(Point3Temp.make(x, y, z)), a); /* */ } /* */ /* */ /* */ private native void nativeFinalize(); /* */ /* */ public Transform getTransform() /* */ { /* 425 */ Transform t = make(); /* 426 */ t.setTransform(this); /* 427 */ return t; /* */ } /* */ /* */ /* */ /* */ /* */ public native void setTransform(Transform paramTransform); /* */ /* */ /* */ /* */ public native Transform invert(); /* */ /* */ /* */ /* */ public Transform getObjectToWorldMatrix() /* */ { /* 443 */ return getTransform(); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ private Point3Temp worldVecToObjectVec(Point3Temp worldVec) /* */ { /* 452 */ Transform inv = getObjectToWorldMatrix().invert(); /* 453 */ Point3Temp p = Point3Temp.make(worldVec).vectorTimes(inv) /* 454 */ .times(getScale()); /* 455 */ inv.recycle(); /* 456 */ return p; /* */ } /* */ /* */ /* */ /* */ /* */ public Object properties(int index, int offset, int mode, Object value) /* */ throws NoSuchPropertyException /* */ { /* 465 */ Object ret = null; /* 466 */ switch (index - offset) { /* */ case 0: /* 468 */ if (mode == 0) { /* 469 */ ret = TransformPropertyEditor.make(new Property(this, index, /* 470 */ "Transform")); /* 471 */ } else if (mode == 1) { /* 472 */ ret = getTransform(); /* 473 */ } else if (mode == 2) /* 474 */ setTransform((Transform)value); /* 475 */ break; /* */ default: /* 477 */ ret = super.properties(index, offset + 1, mode, value); /* */ } /* 479 */ return ret; /* */ } /* */ /* 482 */ private static Object classCookie = new Object(); /* */ /* */ /* */ /* */ /* */ public void saveState(Saver s) /* */ throws IOException /* */ { /* 490 */ s.saveVersion(2, classCookie); /* 491 */ super.saveState(s); /* 492 */ s.saveFloat(this.xScale); /* 493 */ s.saveFloat(this.yScale); /* 494 */ s.saveFloat(this.zScale); /* 495 */ float[] guts = getGuts(); /* 496 */ for (int i = 0; i < 16; i++) { /* 497 */ s.saveFloat(guts[i]); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public void restoreState(Restorer r) /* */ throws IOException, TooNewException /* */ { /* 508 */ switch (r.restoreVersion(classCookie)) { /* */ case 2: /* 510 */ super.restoreState(r); /* 511 */ this.xScale = r.restoreFloat(); /* 512 */ this.yScale = r.restoreFloat(); /* 513 */ this.zScale = r.restoreFloat(); /* 514 */ float[] guts = new float[16]; /* 515 */ for (int i = 0; i < 16; i++) /* 516 */ guts[i] = r.restoreFloat(); /* 517 */ setGuts(guts); /* 518 */ break; /* */ /* */ case 1: /* 521 */ super.restoreState(r); /* */ case 0: /* 523 */ this.xScale = (this.yScale = this.zScale = r.restoreFloat()); /* 524 */ float[] guts = new float[16]; /* 525 */ for (int i = 0; i < 16; i++) /* 526 */ guts[i] = r.restoreFloat(); /* 527 */ setGuts(guts); /* 528 */ break; /* */ default: /* 530 */ throw new TooNewException(); /* */ } /* */ /* */ } /* */ /* */ /* */ /* */ /* */ private native float[] getGuts(); /* */ /* */ /* */ /* */ /* */ public native boolean isTransformEqual(Transform paramTransform); /* */ /* */ /* */ /* */ /* */ private native void setGuts(float[] paramArrayOfFloat); /* */ /* */ /* */ /* */ /* */ public String toTransformSubstring() /* */ { /* 555 */ Point3Temp axis = Point3Temp.make(); /* 556 */ float angle = getSpin(axis); /* 557 */ Point3Temp pos = getPosition(); /* 558 */ if ((angle == 0.0F) && (this.xScale == 1.0F) && (this.yScale == 1.0F) && (this.zScale == 1.0F) && /* 559 */ (pos.x == 0.0F) && (pos.y == 0.0F) && (pos.z == 0.0F)) /* 560 */ return "[identity]"; /* 561 */ return /* */ /* */ /* */ /* */ /* 566 */ "[pos (" + pos + "), scale (" + ((this.xScale == this.yScale) && (this.yScale == this.zScale) ? this.xScale : new StringBuilder().append(this.xScale).append(",").append(this.yScale).append(",").append(this.zScale).toString()) + "), rot (" + axis + "@" + angle + ")]"; /* */ } /* */ /* */ public String toString() /* */ { /* 571 */ return getName() + toTransformSubstring(); /* */ } /* */ /* */ public Transform printGuts() /* */ { /* 576 */ float[] arr = getGuts(); /* 577 */ assert (arr.length == 16); /* 578 */ String[] strs = new String[16]; /* 579 */ int maxStr = 0; /* 580 */ for (int i = 0; i < 16; i++) { /* 581 */ strs[i] = Float.toString(arr[i]); /* 582 */ maxStr = Math.max(maxStr, strs[i].length()); /* */ } /* 584 */ for (int j = 0; j < 4; j++) { /* 585 */ for (int k = 0; k < 4; k++) { /* 586 */ String s = strs[(j * 4 + k)]; /* 587 */ int pad = maxStr - s.length() + 1; /* 588 */ System.out.print(s); /* 589 */ while (pad-- != 0) /* 590 */ System.out.print(" "); /* */ } /* 592 */ System.out.println(""); /* */ } /* 594 */ return this; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\Transform.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */