/* */ package NET.worlds.scape; /* */ /* */ import java.io.PrintStream; /* */ /* */ /* */ /* */ /* */ public class HandsOffDriver /* */ extends SwitchableBehavior /* */ implements FrameHandler, AnimatedActionHandler, KeyDownHandler, KeyUpHandler /* */ { /* */ Point2 _destPoint; /* */ float _destYaw; /* */ float _velocity; /* 15 */ int _lastFrameTime = 0; /* */ AnimatedActionHandlerImp handler; /* 17 */ int _state = 0; /* 18 */ Transform target = null; /* 19 */ float cameraPan = 0.0F; /* 20 */ float cameraZoom = 0.0F; /* 21 */ int cameraPanning = 0; /* 22 */ int cameraZooming = 0; /* */ /* */ static final float cameraPanRate = 45.0F; /* */ /* */ static final float cameraZoomRate = 100.0F; /* */ /* */ static final int noState = 0; /* */ static final int turnToDestination = 1; /* */ static final int moveToDestination = 2; /* */ static final int faceDestination = 3; /* */ /* */ public HandsOffDriver() /* */ { /* 35 */ this.handler = new AnimatedActionHandlerImp(); /* */ } /* */ /* 38 */ public float getCameraPan() { return this.cameraPan; } /* 39 */ public float getCameraZoom() { return this.cameraZoom; } /* */ /* */ /* */ public void setTarget(Transform t) /* */ { /* 44 */ this.target = t; /* */ } /* */ /* */ public void addCallback(AnimatedActionCallback c) /* */ { /* 49 */ this.handler.addCallback(c); /* */ } /* */ /* */ public void removeCallback(AnimatedActionCallback c) /* */ { /* 54 */ this.handler.removeCallback(c); /* */ } /* */ /* */ public void notifyCallbacks(int completionCode) /* */ { /* 59 */ this.handler.notifyCallbacks(completionCode); /* */ } /* */ /* */ /* */ public void setDestPos(Point2 point, float yaw, float velocity) /* */ { /* 65 */ if (point == null) { /* 66 */ System.out.println("Point is null"); /* */ } /* 68 */ this._destPoint = point; /* 69 */ this._destYaw = yaw; /* 70 */ this._velocity = velocity; /* 71 */ this._state = 1; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public boolean handle(FrameEvent e) /* */ { /* 80 */ int now = e.time; /* 81 */ float dt = (now - this._lastFrameTime) / 1000.0F; /* 82 */ this._lastFrameTime = now; /* */ /* 84 */ this.cameraZoom += dt * 100.0F * this.cameraZooming; /* 85 */ this.cameraPan += dt * 45.0F * this.cameraPanning; /* */ /* */ Transform tgt; /* */ Transform tgt; /* 89 */ if (this.target == null) /* */ { /* 91 */ if (!(e.receiver instanceof Pilot)) /* */ { /* 93 */ System.out.println("Receiver not pilot..."); /* 94 */ return true; /* */ } /* */ /* 97 */ Pilot pilot = (Pilot)e.receiver; /* 98 */ if (!pilot.isActive()) /* */ { /* 100 */ System.out.println("Pilot not active..."); /* 101 */ return true; /* */ } /* 103 */ tgt = pilot; /* */ } /* */ else /* */ { /* 107 */ tgt = this.target; /* */ } /* */ /* 110 */ if (dt <= 0.0F) /* */ { /* 112 */ System.out.println("Negative dt"); /* 113 */ return true; /* */ } /* */ /* 116 */ if (dt > 0.33F) { dt = 0.33F; /* */ } /* 118 */ moveObject(tgt, dt); /* */ /* 120 */ return true; /* */ } /* */ /* */ private void yawLevel(Transform pilot, float theta) /* */ { /* 125 */ float currentYaw = pilot.getYaw(); /* 126 */ Point3Temp currentSpinAxis = Point3Temp.make(); /* 127 */ float currentSpin = pilot.getSpin(currentSpinAxis); /* 128 */ Point3Temp currentPosition = pilot.getPosition(); /* */ /* 130 */ pilot.makeIdentity() /* 131 */ .moveTo(currentPosition) /* 132 */ .yaw(-theta); /* */ /* 134 */ pilot.yaw(currentYaw); /* 135 */ pilot.spin(currentSpinAxis, currentSpin); /* */ } /* */ /* */ private void moveObject(Transform pilot, float dt) /* */ { /* 140 */ if ((pilot == null) || (this._destPoint == null)) /* */ { /* */ /* 143 */ return; /* */ } /* */ /* 146 */ switch (this._state) /* */ { /* */ /* */ case 1: /* 150 */ Point3Temp dest = Point3Temp.make(this._destPoint.x, /* 151 */ this._destPoint.y, pilot.getZ()); /* 152 */ Point3Temp src = pilot.getPosition(); /* */ /* 154 */ double destYaw = Math.atan2(dest.y - src.y, dest.x - src.x); /* */ /* */ /* */ /* 158 */ destYaw = 1.5707963267948966D - destYaw; /* */ /* 160 */ destYaw *= 57.29577951308232D; /* */ /* 162 */ yawLevel(pilot, (float)destYaw); /* */ /* 164 */ this._state = 2; /* */ /* 166 */ break; /* */ /* */ /* */ /* */ case 2: /* 171 */ Point3Temp dest = Point3Temp.make(this._destPoint.x, /* 172 */ this._destPoint.y, pilot.getZ()); /* */ /* */ /* */ /* */ /* */ /* 178 */ float cm = dt * this._velocity; /* */ /* 180 */ Point3Temp dP = Point3Temp.make(dest); /* 181 */ dP.minus(pilot.getPosition()); /* */ /* 183 */ if (dP.length() <= cm) /* */ { /* */ /* 186 */ pilot.moveTo(dest); /* 187 */ this._state = 3; /* */ } /* */ else /* */ { /* 191 */ dP.normalize(); /* */ /* 193 */ pilot.moveBy(dP.times(cm)); /* */ } /* 195 */ break; /* */ /* */ /* */ /* */ case 3: /* 200 */ yawLevel(pilot, this._destYaw); /* 201 */ this._state = 0; /* 202 */ notifyCallbacks(0); /* */ } /* */ /* */ } /* */ /* */ /* */ public boolean handle(KeyDownEvent e) /* */ { /* 210 */ if (e.key == 58150) /* */ { /* 212 */ this.cameraZooming = -1; /* */ } /* 214 */ else if (e.key == 58152) /* */ { /* 216 */ this.cameraZooming = 1; /* */ } /* 218 */ else if (e.key == 58149) /* */ { /* 220 */ this.cameraPanning = -1; /* */ } /* 222 */ else if (e.key == 58151) /* */ { /* 224 */ this.cameraPanning = 1; /* */ } /* 226 */ return true; /* */ } /* */ /* */ public boolean handle(KeyUpEvent e) /* */ { /* 231 */ if ((e.key == 58150) || (e.key == 58152)) /* */ { /* 233 */ this.cameraZooming = 0; /* */ } /* 235 */ else if ((e.key == 58149) || (e.key == 58151)) /* */ { /* 237 */ this.cameraPanning = 0; /* */ } /* 239 */ else if (e.key == 58139) /* */ { /* 241 */ notifyCallbacks(0); /* */ } /* 243 */ return true; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\HandsOffDriver.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */