1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
/* */ 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
*/
|