/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.Console; /* */ import NET.worlds.console.Cursor; /* */ import NET.worlds.console.Gamma; /* */ import NET.worlds.console.RenderCanvas; /* */ import NET.worlds.console.Window; /* */ import NET.worlds.network.URL; /* */ import java.io.IOException; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class Camera /* */ extends WObject /* */ implements MouseButtonHandler, MouseEnterHandler, MouseExitHandler, MouseMoveHandler, IncrementalRestorer, URLSelf /* */ { /* */ private RenderCanvas canvas; /* */ static final int CAMERA_SIZE = 20; /* */ /* */ public Camera() /* */ { /* 122 */ setVisible(false); /* */ } /* */ /* */ /* */ /* */ static /* */ { /* 129 */ cameraNativeInit(); /* */ } /* */ /* */ public Window getWindow() { /* 133 */ if (this.canvas == null) { /* 134 */ return null; /* */ } /* 136 */ return this.canvas.getWindow(); /* */ } /* */ /* */ /* */ /* */ public BoundBoxTemp getBoundBox() /* */ { /* 143 */ Transform t = getObjectToWorldMatrix(); /* 144 */ Point3Temp p = t.getPosition(); /* 145 */ t.recycle(); /* */ /* 147 */ Point3Temp q = Point3Temp.make(p).minus(20.0F); /* 148 */ return BoundBoxTemp.make(q, p.plus(20.0F)); /* */ } /* */ /* */ /* 152 */ private boolean mouseIsOverClickable = false; /* 153 */ private boolean validMouseCoordinates = false; /* 154 */ private float validMouseX = -1.0F; /* 155 */ private float validMouseY = -1.0F; /* */ /* */ /* 158 */ private static WObject cachedWObject = null; /* 159 */ private static float cachedMouseX = -1.0F; /* 160 */ private static float cachedMouseY = -1.0F; /* */ private int cameraID; /* */ private int cameraMode; /* */ private boolean alwaysClearBackground; /* */ /* 165 */ public static WObject getMousePickWObject() { return cachedWObject; } /* */ /* */ /* */ public static float getMousePickX() /* */ { /* 170 */ return cachedMouseX; /* */ } /* */ /* */ public static float getMousePickY() /* */ { /* 175 */ return cachedMouseY; /* */ } /* */ /* */ /* */ /* */ protected WObject updateView(Window w, int mode) /* */ { /* 182 */ Room r = getRoom(); /* */ /* */ /* 185 */ if ((!hasClump()) && (r != null)) { /* 186 */ r.aboutToDraw(); /* */ } /* 188 */ Transform t = null; /* 189 */ SuperRoot o = getOwner(); /* */ /* */ /* 192 */ Pilot pilot = null; /* */ /* 194 */ if (((o instanceof Pilot)) && (o.getOwner() == r)) { /* 195 */ pilot = (Pilot)o; /* */ /* 197 */ if (r != null) { /* 198 */ pilot.aboutToDraw(); /* */ /* */ /* */ /* */ /* */ /* 204 */ detach(); /* 205 */ r.add(this); /* */ /* 207 */ t = getTransform(); /* */ /* */ /* */ /* */ /* 212 */ Point3Temp motion = t.getPosition().times(pilot) /* 213 */ .minus(pilot.getPosition()); /* 214 */ post(pilot); /* */ /* 216 */ if (motion.squaredLength() > 1.0F) { /* 217 */ moveBy(Point3Temp.make().minus(motion)); /* */ /* 219 */ boolean pBumpable = pilot.getBumpable(); /* 220 */ pilot.setBumpable(false); /* 221 */ moveThrough(motion); /* 222 */ pilot.setBumpable(pBumpable); /* */ /* */ /* */ /* 226 */ Room r2 = getRoom(); /* 227 */ if ((!hasClump()) && (r2 != null) && (r2 != r)) { /* 228 */ r2.aboutToDraw(); /* */ } /* */ } /* */ } /* */ } /* 233 */ WObject result = renderScene(w.getHwnd(), w.fullWidth(), /* 234 */ w.fullHeight(), mode, pilot); /* */ /* 236 */ if (t != null) { /* 237 */ detach(); /* 238 */ pilot.add(this); /* 239 */ setTransform(t); /* 240 */ t.recycle(); /* */ } /* 242 */ return result; /* */ } /* */ /* */ /* */ public void renderToCanvas() /* */ { /* 248 */ assert (this.cameraID == 0); /* */ /* 250 */ if (!isActive()) { /* 251 */ return; /* */ } /* 253 */ Window w = getWindow(); /* 254 */ if (w == null) { /* 255 */ return; /* */ } /* 257 */ if (this.validMouseCoordinates) /* */ { /* 259 */ this.xPick = this.validMouseX; /* 260 */ this.yPick = this.validMouseY; /* */ /* 262 */ WObject obj = updateView(w, /* 263 */ 7); /* */ /* 265 */ boolean toggleMouseCursor = false; /* */ /* 267 */ cachedWObject = obj; /* 268 */ cachedMouseX = this.validMouseX; /* 269 */ cachedMouseY = this.validMouseY; /* */ /* 271 */ if ((obj != null) && (obj.acceptsLeftClicks())) /* */ { /* 273 */ if (!this.mouseIsOverClickable) /* */ { /* 275 */ this.mouseIsOverClickable = true; /* 276 */ toggleMouseCursor = true; /* */ } /* */ /* */ /* */ } /* 281 */ else if (this.mouseIsOverClickable) /* */ { /* 283 */ this.mouseIsOverClickable = false; /* 284 */ toggleMouseCursor = true; /* */ } /* */ /* */ /* 288 */ if (toggleMouseCursor) /* */ { /* 290 */ URL newURL = null; /* */ /* 292 */ if (this.mouseIsOverClickable) /* */ { /* 294 */ newURL = URL.make("home:HAND-M.CUR"); /* */ } /* */ else /* */ { /* 298 */ newURL = URL.make("system:DEFAULT_CURSOR"); /* */ } /* */ /* 301 */ Console.getActive().getCursor().setURL(newURL); /* */ } /* */ } /* */ else /* */ { /* 306 */ updateView(w, 6); /* */ } /* */ } /* */ /* */ /* */ public RenderCanvas getCanvas() /* */ { /* 313 */ return this.canvas; /* */ } /* */ /* 316 */ public void setCanvas(RenderCanvas c) { this.canvas = c; } /* */ /* */ /* */ private float xPick; /* */ /* */ private float yPick; /* */ /* */ private Point3Temp unpickSpot; /* */ /* */ private WObject pickedObj; /* */ /* */ public void setAlwaysClearBackground(boolean in) /* */ { /* 329 */ this.alwaysClearBackground = in; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public Point3Temp lastPickSpot() /* */ { /* 338 */ return this.unpickSpot; /* */ } /* */ /* */ /* */ /* */ /* 344 */ public Transform lookAround = Transform.make(); /* */ private static final int isBotMode = 0; /* */ private static final int isPickingMode = 1; /* */ /* */ public void transferFrom(Camera target) { /* 349 */ this.lookAround.setTransform(target.lookAround); /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private static final int isDrawingMode = 2; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ private static final int isThroughMode = 4; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public WObject getObjectAt(float x, float y, boolean pickingThrough, Point3Temp pt) /* */ { /* 382 */ Window w = getWindow(); /* 383 */ if (w == null) { /* 384 */ return null; /* */ } /* 386 */ this.xPick = x; /* 387 */ this.yPick = y; /* 388 */ this.unpickSpot = null; /* 389 */ WObject obj = updateView(w, 1 + ( /* 390 */ pickingThrough ? 4 : 0)); /* 391 */ if ((pt != null) && (this.unpickSpot != null)) /* 392 */ pt.copy(this.unpickSpot); /* 393 */ return obj; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ private void sendClick(WObject obj, MouseButtonEvent e) /* */ { /* 402 */ WObject oldTarget = e.target; /* 403 */ e.target = obj; /* 404 */ obj.deliver(e); /* 405 */ e.target = oldTarget; /* */ } /* */ /* 408 */ static WObject[] downWentTo = new WObject[3]; /* 409 */ static Point3 downAt = new Point3(); /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public boolean handle(MouseButtonEvent e) /* */ { /* 420 */ WObject obj = null; /* */ /* 422 */ int which = 3; /* 423 */ if (e.key == 58113) { /* 424 */ which = 0; /* 425 */ } else if (e.key == 58114) { /* 426 */ which = 1; /* 427 */ } else if (e.key == 58116) { /* 428 */ which = 2; /* */ } /* 430 */ assert (which != 3); /* */ /* 432 */ if ((e instanceof MouseUpEvent)) /* */ { /* */ /* 435 */ obj = downWentTo[which]; /* 436 */ downWentTo[which] = null; /* */ } /* */ else /* */ { /* 440 */ Window w = getWindow(); /* 441 */ if ((w != null) && (!w.getDeltaMode())) /* */ { /* */ /* */ /* 445 */ if ((which == 1) && (Gamma.getShaper() != null)) /* */ { /* 447 */ obj = getObjectAt(e.x, e.y, false, null); /* */ /* 449 */ if (obj != null) /* */ { /* 451 */ obj.rightMenu(); /* */ } /* */ /* */ } /* */ else /* */ { /* 457 */ obj = getObjectAt(e.x, e.y, true, downAt); /* */ } /* */ /* 460 */ downWentTo[which] = obj; /* */ } /* */ } /* */ /* 464 */ if (obj != null) /* */ { /* 466 */ if ((which == 0) && ((e instanceof MouseUpEvent))) /* 467 */ obj.doAction(Console.getActive().getDefaultAction(), e); /* 468 */ sendClick(obj, e); /* */ } /* */ /* */ /* */ /* 473 */ return false; /* */ } /* */ /* */ public boolean handle(MouseEnterEvent e) /* */ { /* 478 */ if (e != null) /* */ { /* 480 */ URL defaultCursor = URL.make("system:DEFAULT_CURSOR"); /* 481 */ Console.getActive().getCursor().setURL(defaultCursor); /* */ /* 483 */ this.mouseIsOverClickable = false; /* 484 */ this.validMouseCoordinates = true; /* 485 */ this.validMouseX = e.x; /* 486 */ this.validMouseY = e.y; /* */ /* 488 */ cachedWObject = null; /* 489 */ cachedMouseX = -1.0F; /* 490 */ cachedMouseY = -1.0F; /* */ } /* */ /* 493 */ return false; /* */ } /* */ /* */ public boolean handle(MouseExitEvent e) /* */ { /* 498 */ if (e != null) /* */ { /* 500 */ URL defaultCursor = URL.make("system:DEFAULT_CURSOR"); /* 501 */ Console.getActive().getCursor().setURL(defaultCursor); /* */ /* 503 */ this.mouseIsOverClickable = false; /* 504 */ this.validMouseCoordinates = false; /* 505 */ this.validMouseX = -1.0F; /* 506 */ this.validMouseY = -1.0F; /* */ /* 508 */ cachedWObject = null; /* 509 */ cachedMouseX = -1.0F; /* 510 */ cachedMouseY = -1.0F; /* */ } /* */ /* 513 */ return false; /* */ } /* */ /* */ public boolean handle(MouseMoveEvent e) /* */ { /* 518 */ if (e != null) /* */ { /* 520 */ this.validMouseX = e.x; /* 521 */ this.validMouseY = e.y; /* */ } /* */ /* 524 */ return false; /* */ } /* */ /* */ /* */ /* */ public Object properties(int index, int offset, int mode, Object value) /* */ throws NoSuchPropertyException /* */ { /* 532 */ Object ret = null; /* 533 */ (index - offset); /* */ /* 535 */ ret = super.properties(index, offset + 0, mode, value); /* */ /* 537 */ return ret; /* */ } /* */ /* 540 */ private static Object classCookie = new Object(); /* */ public float xForRoomPreAndPostRender; /* */ /* 543 */ public void saveState(Saver s) throws IOException { s.saveVersion(2, classCookie); /* 544 */ super.saveState(s); /* */ } /* */ /* */ /* */ public float yForRoomPreAndPostRender; /* */ /* */ public void restoreState(Restorer r) /* */ throws IOException, TooNewException /* */ { /* 553 */ switch (r.restoreVersion(classCookie)) { /* */ case 1: /* 555 */ super.restoreState(r); /* 556 */ r.restoreFloat(); /* 557 */ r.restore(); /* 558 */ r.restore(); /* 559 */ break; /* */ /* */ case 0: /* */ case 2: /* 563 */ super.restoreState(r); /* 564 */ break; /* */ /* */ default: /* 567 */ throw new TooNewException(); /* */ } /* */ /* */ } /* */ /* */ /* */ /* */ /* */ public int incRestore(int state, Restorer r, URLSelfLoader p) /* */ throws Exception /* */ { /* 578 */ if (state == 0) { /* 579 */ restoreState(r); /* */ } /* 581 */ if (r.version() != 3) { /* 582 */ return -1; /* */ } /* */ /* 585 */ if (state == 0) { /* 586 */ p.otemp1 = r.restore(false); /* */ } /* 588 */ World w = (World)p.otemp1; /* 589 */ if (state == 0) /* 590 */ w.setSourceURL(getSourceURL()); /* 591 */ return w.incRestore(state, r, p); /* */ } /* */ /* */ /* */ public float zForRoomPreAndPostRender; /* */ /* */ public float dForRoomPreAndPostRender; /* */ /* */ public void incRef() /* */ { /* 601 */ if (!$assertionsDisabled) throw new AssertionError(); } /* 602 */ public void decRef() { if (!$assertionsDisabled) throw new AssertionError(); /* */ } /* */ /* */ public static native void cameraNativeInit(); /* */ /* */ public native void nDrawText(String paramString, int paramInt1, int paramInt2, int paramInt3, int paramInt4); /* */ /* */ synchronized native WObject renderScene(int paramInt1, int paramInt2, int paramInt3, int paramInt4, Pilot paramPilot); /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\Camera.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */