/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.Console; /* */ import NET.worlds.console.DefaultConsole; /* */ import NET.worlds.console.RenderCanvas; /* */ import java.io.IOException; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class Rect /* */ extends Surface /* */ implements MouseDownHandler, FrameHandler, Prerenderable /* */ { /* */ public Rect(float w, float h, Material material) /* */ { /* 76 */ super(material); /* */ /* */ /* 79 */ scale(w, h, h); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public Rect(float x, float y, float z, Material material) /* */ { /* 88 */ super(material); /* 89 */ setFarCorner(Point3Temp.make(x, y, z)); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public Rect(float llx, float lly, float llz, float urx, float ury, float urz, Material material) /* */ { /* 98 */ super(material); /* 99 */ moveBy(llx, lly, llz); /* 100 */ setFarCorner(Point3Temp.make(urx, ury, urz)); /* */ } /* */ /* */ /* */ /* */ /* */ public Rect(Point3Temp llc, Point3Temp urc, Material material) /* */ { /* 108 */ this(llc.x, llc.y, llc.z, urc.x, urc.y, urc.z, material); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public static boolean setFarCornerHelper(Transform t, Point3Temp newCorner) /* */ { /* 149 */ t.scale(1.0F / t.getScaleX(), 1.0F / t.getScaleY(), 1.0F / t.getScaleZ()); /* */ /* */ /* */ /* 153 */ Point3Temp lookRight = Point3Temp.make(1.0F, 0.0F, 0.0F).vectorTimes(t); /* 154 */ Point3Temp lookOut = Point3Temp.make(0.0F, 1.0F, 0.0F).vectorTimes(t); /* 155 */ Point3Temp lookUp = Point3Temp.make(0.0F, 0.0F, 1.0F).vectorTimes(t); /* */ /* */ /* */ /* */ /* */ /* 161 */ Point3Temp newEndOffset = Point3Temp.make(newCorner).minus( /* 162 */ t.getPosition()); /* 163 */ float x = newEndOffset.dot(lookRight); /* 164 */ float y = newEndOffset.dot(lookOut); /* 165 */ float z = newEndOffset.dot(lookUp); /* */ /* */ /* */ /* */ /* */ /* 171 */ if (z >= 0.0F) /* */ { /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 180 */ if ((x != 0.0F) || (y != 0.0F)) { /* 181 */ t.spin(0.0F, 0.0F, 1.0F, (float)(Math.atan2(y, x) * 180.0D / 3.141592653589793D)); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 192 */ t.scale((float)Math.sqrt(x * x + y * y), z, z); /* 193 */ return true; /* */ } /* 195 */ return false; /* */ } /* */ /* */ /* */ /* */ /* */ public boolean setFarCorner(Point3Temp newCorner) /* */ { /* 203 */ Transform t = getTransform(); /* 204 */ if (setFarCornerHelper(t, newCorner)) { /* 205 */ setTransform(t); /* 206 */ t.recycle(); /* 207 */ return true; /* */ } /* 209 */ t.recycle(); /* 210 */ Console.println(Console.message("cant-rot-rect")); /* 211 */ return false; /* */ } /* */ /* */ /* */ public Point3Temp getFarCorner() /* */ { /* 217 */ Point3Temp ret = Point3Temp.make(1.0F, 0.0F, 1.0F); /* */ /* 219 */ if (hasClump()) { /* 220 */ Transform t = getObjectToWorldMatrix(); /* 221 */ ret.times(t); /* 222 */ t.recycle(); /* */ } else { /* 224 */ ret.times(this); /* */ } /* 226 */ return ret; /* */ } /* */ /* */ /* */ public Point3Temp getFarCornerLocal() /* */ { /* 232 */ Point3Temp ret = Point3Temp.make(1.0F, 0.0F, 1.0F); /* */ /* 234 */ if (hasClump()) { /* 235 */ Transform t = getTransform(); /* 236 */ ret.times(t); /* 237 */ t.recycle(); /* */ } else { /* 239 */ ret.times(this); /* */ } /* 241 */ return ret; /* */ } /* */ /* */ /* */ /* */ /* */ public void setNearCorner(Point3Temp from) /* */ { /* 249 */ Point3Temp oldEnd = getFarCornerLocal(); /* 250 */ Point3Temp oldStart = getPosition(); /* 251 */ moveTo(from); /* 252 */ if (!setFarCorner(oldEnd)) { /* 253 */ moveTo(oldStart); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ public Point3Temp getPlaneExtent() /* */ { /* 262 */ return Point3Temp.make(1.0F, 0.0F, 1.0F); /* */ } /* */ /* 265 */ static BumpCalc standardPlaneBumpCalc = new PlaneBumpCalc(); /* */ /* */ static { /* 268 */ standardPlaneBumpCalc.setName("defaultPlaneBumpCalc"); /* */ } /* */ /* */ /* */ /* */ public BumpCalc getBumpCalc(BumpEventTemp b) /* */ { /* 275 */ if (this.bumpCalc == null) /* 276 */ return standardPlaneBumpCalc; /* 277 */ return this.bumpCalc; /* */ } /* */ /* */ /* */ /* */ /* */ public Point2 getTileSize() /* */ { /* 285 */ return new Point2(this.u != 1.0F ? getScaleX() / this.u : 0.0F, this.v != 1.0F ? getScaleZ() / /* 286 */ this.v : 0.0F); /* */ } /* */ /* */ void setUV(float u, float v) /* */ { /* 291 */ setTileSize(getScaleX() / u, getScaleZ() / v); /* */ } /* */ /* */ /* */ /* */ /* */ public Rect setTileSize(float tx, float ty) /* */ { /* 299 */ this.u = (tx == 0.0F ? 1.0F : getScaleX() / tx); /* 300 */ this.v = (ty == 0.0F ? 1.0F : getScaleZ() / ty); /* */ /* 302 */ reclump(); /* */ /* 304 */ return this; /* */ } /* */ /* */ /* */ /* */ /* */ public void setTileOffset(Point2 p) /* */ { /* 312 */ this.uOff = (getScaleX() == 0.0F ? 0.0F : p.x / getScaleX()); /* 313 */ this.vOff = (getScaleZ() == 0.0F ? 0.0F : p.y / getScaleZ()); /* 314 */ reclump(); /* */ } /* */ /* */ public Point2 getTileOffset() { /* 318 */ return new Point2(this.uOff * getScaleX(), this.vOff * getScaleZ()); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public static Rect floor(float x, float y, Material m) /* */ { /* 331 */ return (Rect)new Rect(x, y, m).setBumpable(false).postspin(1.0F, 0.0F, 0.0F, /* 332 */ -90.0F); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public static Rect floor(float llx, float lly, float z, float urx, float ury, Material m) /* */ { /* 341 */ return (Rect)floor(urx - llx, ury - lly, m).moveBy(llx, lly, z); /* */ } /* */ /* */ /* */ /* */ /* */ public static Rect ceiling(float x, float y, Material m) /* */ { /* 349 */ return (Rect)new Rect(x, y, m).setBumpable(false) /* 350 */ .postspin(1.0F, 0.0F, 0.0F, 90.0F).moveBy(0.0F, y, 0.0F); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public static Rect ceiling(float llx, float lly, float z, float urx, float ury, Material m) /* */ { /* 359 */ return (Rect)ceiling(urx - llx, ury - lly, m).moveBy(llx, lly, z); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public Rect hang(float pllx, float pllz, float purx, float purz, Material pic) /* */ { /* 377 */ Rect r = (Rect)new Rect((purx - pllx) / getScaleX(), (purz - pllz) / /* 378 */ getScaleZ(), pic).moveBy(pllx / getScaleX(), 0.0F, /* 379 */ pllz / getScaleZ()).post(this); /* */ /* */ /* */ /* 383 */ return (Rect)r.premoveBy(0.0F, -1.0F / r.getScale().length(), 0.0F); /* */ } /* */ /* 386 */ Billboard _billboardAttribute = null; /* 387 */ VideoTexture _videoAttribute = null; /* */ /* */ public VideoTexture getVideoAttribute() { /* 390 */ return this._videoAttribute; /* */ } /* */ /* */ public Billboard getBillboardAttribute() { /* 394 */ return this._billboardAttribute; /* */ } /* */ /* 397 */ boolean visible = false; /* */ /* */ public boolean handle(MouseDownEvent event) /* */ { /* 401 */ if ((this._billboardAttribute != null) && /* 402 */ ((event.key & 0x1) == '\001')) { /* 403 */ Point2 pt = deproject(); /* 404 */ this._billboardAttribute.billboardClicked(pt); /* */ } /* */ /* */ /* 408 */ return false; /* */ } /* */ /* */ public boolean handle(FrameEvent f) { /* 412 */ if ((this._billboardAttribute != null) && (getVisible()) && /* 413 */ (this.visible)) { /* 414 */ this._billboardAttribute.billboardFrame(f); /* */ } /* */ /* */ /* 418 */ if ((this._videoAttribute != null) && (getVisible()) && /* 419 */ (this.visible)) { /* 420 */ this._videoAttribute.videoFrame(f); /* */ } /* */ /* */ /* 424 */ this.visible = false; /* */ /* 426 */ return false; /* */ } /* */ /* */ public void prerender(Camera cam) { /* 430 */ if ((this._billboardAttribute != null) || (this._videoAttribute != null)) { /* 431 */ Point3Temp p = inCamSpace(cam); /* */ /* */ /* */ /* 435 */ boolean v = (p != null) && (p.z > 1.0F) && (p.x < p.z) && (-p.x < p.z); /* */ /* 437 */ if (v) { /* 438 */ this.visible = true; /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ protected Point2 deproject() /* */ { /* 448 */ Console c = Console.getActive(); /* */ /* */ Point3Temp worldClick; /* 451 */ if ((c instanceof DefaultConsole)) { /* 452 */ DefaultConsole dc = (DefaultConsole)c; /* 453 */ worldClick = dc.getRender().getCamera().lastPickSpot(); /* */ } else { /* 455 */ return new Point2(-1.0F, -1.0F); /* */ } /* */ /* */ Point3Temp worldClick; /* 459 */ Point3Temp vWorld = Point3Temp.make(worldClick); /* 460 */ vWorld.minus(getObjectToWorldMatrix().getPosition()); /* */ /* */ /* 463 */ Transform inv = getObjectToWorldMatrix().invert(); /* 464 */ Point3Temp vObj = Point3Temp.make(vWorld).vectorTimes(inv); /* 465 */ inv.recycle(); /* */ /* */ /* 468 */ Point2 rectPt = new Point2(); /* */ /* */ /* 471 */ rectPt.set(vObj.x, vObj.z); /* */ /* 473 */ return rectPt; /* */ } /* */ /* */ /* */ /* 478 */ protected float u = 1.0F; protected float v = 1.0F; /* */ /* */ protected float uOff; /* */ protected float vOff; /* */ /* */ protected void addRwChildren(WObject container) /* */ { /* 485 */ addNewRwChild(container); /* */ /* */ /* 488 */ float uo = this.uOff; /* 489 */ if (uo != 0.0F) { /* 490 */ uo *= this.u; /* 491 */ uo = (float)(uo - 2.0D * Math.floor(uo / 2.0F)); /* */ } /* */ /* 494 */ float vo = this.vOff; /* 495 */ if (vo != 0.0F) { /* 496 */ vo *= this.v; /* 497 */ vo = (float)(vo - 2.0D * Math.floor(vo / 2.0F)); /* */ } /* */ /* 500 */ addVertex(0.0F, 0.0F, 0.0F, uo, this.v + vo); /* 501 */ addVertex(1.0F, 0.0F, 0.0F, this.u + uo, this.v + vo); /* 502 */ addVertex(1.0F, 0.0F, 1.0F, this.u + uo, vo); /* 503 */ addVertex(0.0F, 0.0F, 1.0F, uo, vo); /* */ /* 505 */ doneWithEditing(); /* */ /* 507 */ if (!(this instanceof Portal)) /* 508 */ getRoom().addPrerenderHandler(this); /* */ } /* */ /* */ protected void markVoid() { /* 512 */ if (!(this instanceof Portal)) /* 513 */ getRoom().removePrerenderHandler(this); /* 514 */ super.markVoid(); /* */ } /* */ /* */ /* */ /* */ public Object properties(int index, int offset, int mode, Object value) /* */ throws NoSuchPropertyException /* */ { /* 522 */ Object ret = null; /* 523 */ switch (index - offset) { /* */ case 0: /* 525 */ if (mode == 0) { /* 526 */ ret = Point2PropertyEditor.make(new Property(this, index, /* 527 */ "Tile Size")); /* 528 */ } else if (mode == 1) { /* 529 */ ret = getTileSize(); /* 530 */ } else if (mode == 2) { /* 531 */ Point2 p = (Point2)value; /* 532 */ if ((p.x < 0.0F) || (p.y < 0.0F)) { /* 533 */ Console.println(Console.message("Tile-size")); /* */ } else { /* 535 */ setTileSize(p.x, p.y); /* */ } /* */ } /* 538 */ break; /* */ case 1: /* 540 */ if (mode == 0) { /* 541 */ ret = Point2PropertyEditor.make(new Property(this, index, /* 542 */ "Tile Origin")); /* 543 */ } else if (mode == 1) { /* 544 */ ret = getTileOffset(); /* 545 */ } else if (mode == 2) /* 546 */ setTileOffset((Point2)value); /* 547 */ break; /* */ case 2: /* 549 */ if (mode == 0) { /* 550 */ ret = Point3PropertyEditor.make(new Property(this, index, /* 551 */ "From")); /* 552 */ } else if (mode == 1) { /* 553 */ ret = new Point3(getPosition()); /* 554 */ } else if (mode == 2) /* 555 */ setNearCorner((Point3)value); /* 556 */ break; /* */ case 3: /* 558 */ if (mode == 0) { /* 559 */ ret = /* 560 */ Point3PropertyEditor.make(new Property(this, index, "To")); /* 561 */ } else if (mode == 1) { /* 562 */ ret = new Point3(getFarCornerLocal()); /* 563 */ } else if (mode == 2) /* 564 */ setFarCorner((Point3)value); /* 565 */ break; /* */ case 4: /* 567 */ if (mode == 0) { /* 568 */ ret = Point2PropertyEditor.make(new Property(this, index, /* 569 */ "Extent")); /* 570 */ } else if (mode == 1) { /* 571 */ ret = new Point2(getScaleX(), getScaleZ()); /* 572 */ } else if (mode == 2) { /* 573 */ float zScale = ((Point2)value).y / getScaleZ(); /* 574 */ scale(((Point2)value).x / getScaleX(), zScale, zScale); /* */ } /* 576 */ break; /* */ case 5: /* 578 */ if (mode == 0) { /* 579 */ ret = BooleanPropertyEditor.make(new Property(this, index, /* 580 */ "Flip Alternate U"), "No", "Yes"); /* 581 */ } else if (mode == 1) { /* 582 */ ret = new Boolean(getUFlip()); /* 583 */ } else if (mode == 2) { /* 584 */ setUFlip(((Boolean)value).booleanValue()); /* 585 */ reclump(); /* */ } /* 587 */ break; /* */ case 6: /* 589 */ if (mode == 0) { /* 590 */ ret = BooleanPropertyEditor.make(new Property(this, index, /* 591 */ "Flip Alternate V"), "No", "Yes"); /* 592 */ } else if (mode == 1) { /* 593 */ ret = new Boolean(getVFlip()); /* 594 */ } else if (mode == 2) { /* 595 */ setVFlip(((Boolean)value).booleanValue()); /* 596 */ reclump(); /* */ } /* 598 */ break; /* */ case 7: /* 600 */ if (mode == 0) { /* 601 */ ret = BooleanPropertyEditor.make(new Property(this, index, /* 602 */ "Unused"), "No", "Yes"); /* 603 */ } else if (mode == 1) { /* 604 */ ret = new Boolean(getMouseOver()); /* 605 */ } else if (mode == 2) { /* 606 */ setMouseOver(((Boolean)value).booleanValue()); /* */ } /* 608 */ break; /* */ default: /* 610 */ ret = super.properties(index, offset + 8, mode, value); /* */ } /* 612 */ return ret; /* */ } /* */ /* 615 */ private static Object classCookie = new Object(); /* */ /* */ public void saveState(Saver s) throws IOException { /* 618 */ s.saveVersion(4, classCookie); /* 619 */ super.saveState(s); /* 620 */ s.saveFloat(this.u); /* 621 */ s.saveFloat(this.v); /* 622 */ s.saveFloat(this.uOff); /* 623 */ s.saveFloat(this.vOff); /* 624 */ s.saveBoolean(false); /* */ } /* */ /* */ public void restoreState(Restorer r) throws IOException, TooNewException { /* 628 */ int vers = r.restoreVersion(classCookie); /* 629 */ switch (vers) { /* */ case 4: /* 631 */ super.restoreState(r); /* 632 */ this.u = r.restoreFloat(); /* 633 */ this.v = r.restoreFloat(); /* 634 */ this.uOff = r.restoreFloat(); /* 635 */ this.vOff = r.restoreFloat(); /* 636 */ r.restoreBoolean(); /* 637 */ break; /* */ case 3: /* 639 */ super.restoreState(r); /* 640 */ this.u = r.restoreFloat(); /* 641 */ this.v = r.restoreFloat(); /* 642 */ this.uOff = r.restoreFloat(); /* 643 */ this.vOff = r.restoreFloat(); /* 644 */ break; /* */ case 2: /* 646 */ super.restoreState(r); /* 647 */ this.u = r.restoreFloat(); /* 648 */ this.v = r.restoreFloat(); /* 649 */ break; /* */ case 0: /* */ case 1: /* 652 */ super.restoreState(r); /* 653 */ float x = r.restoreFloat(); /* 654 */ float y = r.restoreFloat(); /* 655 */ float z = r.restoreFloat(); /* 656 */ r.restoreFloat(); /* 657 */ r.restoreFloat(); /* 658 */ r.restoreFloat(); /* 659 */ this.u = r.restoreFloat(); /* 660 */ this.v = r.restoreFloat(); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* 669 */ spin(0.0F, 0.0F, 1.0F, (float)(Math.atan2(y, x) * 180.0D / 3.141592653589793D)); /* 670 */ scale((float)Math.sqrt(x * x + y * y), z, z); /* 671 */ break; /* */ default: /* 673 */ throw new TooNewException(); /* */ } /* */ } /* */ /* */ public String toString() { /* 678 */ return /* 679 */ super.toString() + "[" + getPosition() + "->" + getFarCornerLocal() + "]"; /* */ } /* */ /* */ /* */ /* */ public boolean acceptsLeftClicks() /* */ { /* 686 */ if ((this._billboardAttribute != null) && /* 687 */ (this._billboardAttribute.getIsAdBanner())) { /* 688 */ return true; /* */ } /* */ /* */ /* */ /* 693 */ return getMouseOver(); /* */ } /* */ /* */ Rect() {} /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\Rect.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */