diff options
Diffstat (limited to 'NET/worlds/scape/RectPatch.java')
| -rw-r--r-- | NET/worlds/scape/RectPatch.java | 534 |
1 files changed, 534 insertions, 0 deletions
diff --git a/NET/worlds/scape/RectPatch.java b/NET/worlds/scape/RectPatch.java new file mode 100644 index 0000000..9c880c5 --- /dev/null +++ b/NET/worlds/scape/RectPatch.java @@ -0,0 +1,534 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import java.awt.Color; +/* */ import java.io.IOException; +/* */ import java.io.PrintStream; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class RectPatch +/* */ extends WObject +/* */ implements FloorPatch +/* */ { +/* */ public float xDim; +/* */ public float yDim; +/* 47 */ public float[] z = { 0.0F, 0.0F, 0.0F, 0.0F }; +/* */ +/* */ public Material mat; +/* */ +/* 51 */ public float xTile = 1.0F; +/* 52 */ public float xTileOffset = 0.0F; +/* 53 */ public float yTile = 1.0F; +/* 54 */ public float yTileOffset = 0.0F; +/* 55 */ public Polygon[] t = new Polygon[4]; +/* */ +/* */ +/* */ +/* */ +/* */ public RectPatch(float x, float y) +/* */ { +/* 62 */ setVisible(true); +/* 63 */ setBumpable(false); +/* 64 */ this.xDim = x; +/* 65 */ this.yDim = y; +/* 66 */ setMaterial(new Material(Color.gray)); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public RectPatch() +/* */ { +/* 76 */ this.xDim = 1.0F; +/* 77 */ this.yDim = 1.0F; +/* 78 */ setMaterial(new Material(Color.gray)); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected void addRwChildren(WObject parent) +/* */ { +/* 92 */ if (this.t[0] == null) +/* 93 */ createAppearance(); +/* 94 */ super.addRwChildren(parent); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setVisible(boolean v) +/* */ { +/* 103 */ super.setVisible(v); +/* 104 */ createAppearance(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setMaterial(Material m) +/* */ { +/* 113 */ if (this.mat != null) +/* 114 */ this.mat.detach(); +/* 115 */ add(m); +/* 116 */ this.mat = m; +/* 117 */ createAppearance(); +/* */ } +/* */ +/* */ public Material getMaterial() { +/* 121 */ return this.mat; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean inPatch(float x, float y) +/* */ { +/* 130 */ Transform inverse = getObjectToWorldMatrix().invert(); +/* 131 */ Point3Temp p = Point3Temp.make(x, y, 0.0F).times(inverse); +/* 132 */ inverse.recycle(); +/* 133 */ x = p.x; +/* 134 */ y = p.y; +/* */ +/* */ +/* 137 */ if ((x < 0.0F) || (x > this.xDim) || (y < 0.0F) || (y > this.yDim)) +/* 138 */ return false; +/* 139 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public float floorHeight(float x, float y) +/* */ { +/* 149 */ Transform inverse = getObjectToWorldMatrix().invert(); +/* 150 */ Point3Temp p = Point3Temp.make(x, y, 0.0F).times(inverse); +/* 151 */ inverse.recycle(); +/* 152 */ x = p.x; +/* 153 */ y = p.y; +/* */ +/* */ +/* 156 */ float nx = x / this.xDim; +/* 157 */ float ny = y / this.yDim; +/* 158 */ float fx = 1.0F - nx; +/* 159 */ float fy = 1.0F - ny; +/* 160 */ return this.z[0] * fy * fx + this.z[1] * ny * fx + this.z[2] * ny * nx + this.z[3] * fy * nx; +/* */ } +/* */ +/* */ +/* */ public Point3 surfaceNormal(float x, float y) +/* */ { +/* 166 */ Point3 A = new Point3(this.xDim, 0.0F, this.z[1] - this.z[0]); +/* 167 */ Point3Temp B = Point3Temp.make(0.0F, this.yDim, this.z[3] - this.z[0]); +/* 168 */ A.cross(B); +/* 169 */ A.normalize(); +/* */ +/* */ +/* 172 */ A.times(getObjectToWorldMatrix()); +/* 173 */ return A; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void removeAppearance() +/* */ { +/* 185 */ for (int i = 0; i < 4; i++) { +/* 186 */ if (this.t[i] != null) { +/* 187 */ this.t[i].detach(); +/* 188 */ this.t[i] = null; +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public void createAppearance() +/* */ { +/* 198 */ removeAppearance(); +/* */ +/* */ +/* 201 */ if (!getVisible()) { +/* 202 */ return; +/* */ } +/* */ +/* 205 */ if ((this.xDim <= 0.0F) || (this.yDim <= 0.0F)) +/* 206 */ return; +/* 207 */ if (this.xTile <= 0.0F) +/* 208 */ this.xTile = 1.0F; +/* 209 */ if (this.xTile > 31.0F) +/* 210 */ this.xTile = 31.0F; +/* 211 */ if (this.yTile <= 0.0F) +/* 212 */ this.yTile = 1.0F; +/* 213 */ if (this.yTile > 31.0F) +/* 214 */ this.yTile = 31.0F; +/* 215 */ if (this.xTileOffset < 0.0F) +/* 216 */ this.xTileOffset = (1.0F - (float)Math.floor(this.xTileOffset) + this.xTileOffset); +/* 217 */ if (this.yTileOffset < 0.0F) { +/* 218 */ this.yTileOffset = (1.0F - (float)Math.floor(this.yTileOffset) + this.yTileOffset); +/* */ } +/* */ +/* 221 */ float cx = this.xDim / 2.0F; +/* 222 */ float cy = this.yDim / 2.0F; +/* 223 */ float cz = (this.z[0] + this.z[1] + this.z[2] + this.z[3]) / 4.0F; +/* 224 */ float cU = this.xTileOffset + this.xTile / 2.0F; +/* 225 */ float cV = this.yTileOffset + this.yTile / 2.0F; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 232 */ this.t[0] = new Polygon(3, this.mat); +/* 233 */ this.t[0].setVertex(0, 0.0F, 0.0F, this.z[0], this.xTileOffset, this.yTileOffset); +/* 234 */ this.t[0].setVertex(1, cx, cy, cz, cU, cV); +/* 235 */ this.t[0].setVertex(2, 0.0F, this.yDim, this.z[1], this.xTileOffset, this.yTileOffset + this.yTile); +/* 236 */ add(this.t[0]); +/* */ +/* 238 */ this.t[1] = new Polygon(3, this.mat); +/* 239 */ this.t[1].setVertex(0, 0.0F, this.yDim, this.z[1], this.xTileOffset, this.yTileOffset + this.yTile); +/* 240 */ this.t[1].setVertex(1, cx, cy, cz, cU, cV); +/* 241 */ this.t[1].setVertex(2, this.xDim, this.yDim, this.z[2], this.xTileOffset + this.xTile, this.yTileOffset + this.yTile); +/* 242 */ add(this.t[1]); +/* */ +/* 244 */ this.t[2] = new Polygon(3, this.mat); +/* 245 */ this.t[2].setVertex(0, this.xDim, this.yDim, this.z[2], this.xTileOffset + this.xTile, this.yTileOffset + this.yTile); +/* 246 */ this.t[2].setVertex(1, cx, cy, cz, cU, cV); +/* 247 */ this.t[2].setVertex(2, this.xDim, 0.0F, this.z[3], this.xTileOffset + this.xTile, this.yTileOffset); +/* 248 */ add(this.t[2]); +/* */ +/* 250 */ this.t[3] = new Polygon(3, this.mat); +/* 251 */ this.t[3].setVertex(0, this.xDim, 0.0F, this.z[3], this.xTileOffset + this.xTile, this.yTileOffset); +/* 252 */ this.t[3].setVertex(1, cx, cy, cz, cU, cV); +/* 253 */ this.t[3].setVertex(2, 0.0F, 0.0F, this.z[0], this.xTileOffset, this.yTileOffset); +/* 254 */ add(this.t[3]); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setCornerHeight(int corner, float height) +/* */ { +/* 268 */ this.z[corner] = height; +/* 269 */ createAppearance(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setWidth(float v) +/* */ { +/* 278 */ this.xDim = v; +/* 279 */ createAppearance(); +/* */ } +/* */ +/* */ public void setLength(float v) +/* */ { +/* 284 */ this.yDim = v; +/* 285 */ createAppearance(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Transform spin(float x, float y, float z, float a) +/* */ { +/* 297 */ if ((x != 0.0F) || (y != 0.0F)) { +/* 298 */ System.out.println( +/* 299 */ "ERROR: cannot spin floor patch out of horizontal!"); +/* 300 */ return this; +/* */ } +/* 302 */ return super.spin(x, y, z, a); +/* */ } +/* */ +/* */ public Transform postspin(float x, float y, float z, float a) { +/* 306 */ if ((x != 0.0F) || (y != 0.0F)) { +/* 307 */ System.out.println( +/* 308 */ "ERROR: cannot spin floor patch out of horizontal!"); +/* 309 */ return this; +/* */ } +/* 311 */ return super.spin(x, y, z, a); +/* */ } +/* */ +/* */ public Transform worldSpin(float x, float y, float z, float a) { +/* 315 */ if ((x != 0.0F) || (y != 0.0F)) { +/* 316 */ System.out.println( +/* 317 */ "ERROR: cannot spin floor patch out of horizontal!"); +/* 318 */ return this; +/* */ } +/* 320 */ return super.spin(x, y, z, a); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Object properties(int index, int offset, int mode, Object value) +/* */ throws NoSuchPropertyException +/* */ { +/* 330 */ Object ret = null; +/* 331 */ switch (index - offset) { +/* */ case 0: +/* 333 */ if (mode == 0) { +/* 334 */ ret = FloatPropertyEditor.make( +/* 335 */ new Property(this, index, "Length (y)")); +/* 336 */ } else if (mode == 1) { +/* 337 */ ret = new Float(this.yDim); +/* 338 */ } else if (mode == 2) +/* 339 */ setLength(((Float)value).floatValue()); +/* 340 */ break; +/* */ case 1: +/* 342 */ if (mode == 0) { +/* 343 */ ret = FloatPropertyEditor.make( +/* 344 */ new Property(this, index, "Width (x)")); +/* 345 */ } else if (mode == 1) { +/* 346 */ ret = new Float(this.xDim); +/* 347 */ } else if (mode == 2) +/* 348 */ setWidth(((Float)value).floatValue()); +/* 349 */ break; +/* */ case 2: +/* 351 */ if (mode == 0) { +/* 352 */ ret = FloatPropertyEditor.make( +/* 353 */ new Property(this, index, "0,0 corner")); +/* 354 */ } else if (mode == 1) { +/* 355 */ ret = new Float(this.z[0]); +/* 356 */ } else if (mode == 2) +/* 357 */ setCornerHeight(0, ((Float)value).floatValue()); +/* 358 */ break; +/* */ case 3: +/* 360 */ if (mode == 0) { +/* 361 */ ret = FloatPropertyEditor.make( +/* 362 */ new Property(this, index, "0,y corner")); +/* 363 */ } else if (mode == 1) { +/* 364 */ ret = new Float(this.z[1]); +/* 365 */ } else if (mode == 2) +/* 366 */ setCornerHeight(1, ((Float)value).floatValue()); +/* 367 */ break; +/* */ case 4: +/* 369 */ if (mode == 0) { +/* 370 */ ret = FloatPropertyEditor.make( +/* 371 */ new Property(this, index, "x,y corner")); +/* 372 */ } else if (mode == 1) { +/* 373 */ ret = new Float(this.z[2]); +/* 374 */ } else if (mode == 2) +/* 375 */ setCornerHeight(2, ((Float)value).floatValue()); +/* 376 */ break; +/* */ case 5: +/* 378 */ if (mode == 0) { +/* 379 */ ret = FloatPropertyEditor.make( +/* 380 */ new Property(this, index, "x,0 corner")); +/* 381 */ } else if (mode == 1) { +/* 382 */ ret = new Float(this.z[3]); +/* 383 */ } else if (mode == 2) +/* 384 */ setCornerHeight(3, ((Float)value).floatValue()); +/* 385 */ break; +/* */ case 6: +/* 387 */ if (mode == 0) { +/* 388 */ ret = FloatPropertyEditor.make( +/* 389 */ new Property(this, index, "# Tiles (x)")); +/* 390 */ } else if (mode == 1) { +/* 391 */ ret = new Float(this.xTile); +/* 392 */ } else if (mode == 2) { +/* 393 */ this.xTile = ((Float)value).floatValue(); +/* 394 */ createAppearance(); +/* */ } +/* 396 */ break; +/* */ case 7: +/* 398 */ if (mode == 0) { +/* 399 */ ret = FloatPropertyEditor.make( +/* 400 */ new Property(this, index, "# Tiles (y)")); +/* 401 */ } else if (mode == 1) { +/* 402 */ ret = new Float(this.yTile); +/* 403 */ } else if (mode == 2) { +/* 404 */ this.yTile = ((Float)value).floatValue(); +/* 405 */ createAppearance(); +/* */ } +/* 407 */ break; +/* */ case 8: +/* 409 */ if (mode == 0) { +/* 410 */ ret = FloatPropertyEditor.make( +/* 411 */ new Property(this, index, "Tile Offset (x)")); +/* 412 */ } else if (mode == 1) { +/* 413 */ ret = new Float(this.xTileOffset); +/* 414 */ } else if (mode == 2) { +/* 415 */ this.xTileOffset = ((Float)value).floatValue(); +/* 416 */ createAppearance(); +/* */ } +/* 418 */ break; +/* */ case 9: +/* 420 */ if (mode == 0) { +/* 421 */ ret = FloatPropertyEditor.make( +/* 422 */ new Property(this, index, "Tile Offset (y)")); +/* 423 */ } else if (mode == 1) { +/* 424 */ ret = new Float(this.yTileOffset); +/* 425 */ } else if (mode == 2) { +/* 426 */ this.yTileOffset = ((Float)value).floatValue(); +/* 427 */ createAppearance(); +/* */ } +/* 429 */ break; +/* */ case 10: +/* 431 */ if (mode == 0) { +/* 432 */ ret = new Property(this, index, "Material"); +/* 433 */ } else if (mode == 1) { +/* 434 */ ret = this.mat; +/* */ } +/* 436 */ break; +/* */ default: +/* 438 */ ret = super.properties(index, offset + 11, mode, value); +/* */ } +/* */ +/* 441 */ return ret; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* 448 */ private static Object classCookie = new Object(); +/* */ +/* */ public void saveState(Saver s) throws IOException +/* */ { +/* 452 */ s.saveVersion(2, classCookie); +/* 453 */ removeAppearance(); +/* 454 */ super.saveState(s); +/* 455 */ s.saveFloat(this.xDim); +/* 456 */ s.saveFloat(this.yDim); +/* 457 */ for (int i = 0; i < 4; i++) +/* 458 */ s.saveFloat(this.z[i]); +/* 459 */ s.saveFloat(this.xTile); +/* 460 */ s.saveFloat(this.xTileOffset); +/* 461 */ s.saveFloat(this.yTile); +/* 462 */ s.saveFloat(this.yTileOffset); +/* 463 */ s.saveMaybeNull(this.mat); +/* 464 */ createAppearance(); +/* */ } +/* */ +/* */ public void restoreState(Restorer r) throws IOException, TooNewException +/* */ { +/* 469 */ restoreStateRectPatchHelper(r, classCookie); +/* */ } +/* */ +/* */ public void restoreStateRectPatchHelper(Restorer r, Object cookie) +/* */ throws IOException, TooNewException +/* */ { +/* 475 */ switch (r.restoreVersion(cookie)) { +/* */ case 2: +/* 477 */ super.restoreState(r); +/* 478 */ this.xDim = r.restoreFloat(); +/* 479 */ this.yDim = r.restoreFloat(); +/* 480 */ for (int i = 0; i < 4; i++) +/* 481 */ this.z[i] = r.restoreFloat(); +/* 482 */ this.xTile = r.restoreFloat(); +/* 483 */ this.xTileOffset = r.restoreFloat(); +/* 484 */ this.yTile = r.restoreFloat(); +/* 485 */ this.yTileOffset = r.restoreFloat(); +/* 486 */ setMaterial(Material.restore(r)); +/* 487 */ break; +/* */ case 1: +/* 489 */ r.setOldFlag(); +/* 490 */ super.restoreState(r); +/* 491 */ this.xDim = r.restoreFloat(); +/* 492 */ this.yDim = r.restoreFloat(); +/* 493 */ for (int i = 0; i < 4; i++) +/* 494 */ this.z[i] = r.restoreFloat(); +/* 495 */ this.xTile = r.restoreFloat(); +/* 496 */ this.xTileOffset = r.restoreFloat(); +/* 497 */ this.yTile = r.restoreFloat(); +/* 498 */ this.yTileOffset = r.restoreFloat(); +/* 499 */ setMaterial(Material.restore(r)); +/* 500 */ r.restoreMaybeNull(); +/* 501 */ r.restoreMaybeNull(); +/* 502 */ r.restoreMaybeNull(); +/* 503 */ r.restoreMaybeNull(); +/* 504 */ break; +/* */ case 0: +/* 506 */ r.setOldFlag(); +/* 507 */ super.restoreState(r); +/* 508 */ this.xDim = r.restoreFloat(); +/* 509 */ this.yDim = r.restoreFloat(); +/* 510 */ for (int i = 0; i < 4; i++) +/* 511 */ this.z[i] = r.restoreFloat(); +/* 512 */ setVisible(false); +/* */ +/* 514 */ break; +/* */ default: +/* 516 */ throw new TooNewException(); +/* */ } +/* */ +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public String toString() +/* */ { +/* 526 */ return super.toString() + "[" + this.xDim + "," + this.yDim + "]"; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\RectPatch.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |