diff options
Diffstat (limited to 'NET/worlds/scape/SmoothDriver.java')
| -rw-r--r-- | NET/worlds/scape/SmoothDriver.java | 684 |
1 files changed, 684 insertions, 0 deletions
diff --git a/NET/worlds/scape/SmoothDriver.java b/NET/worlds/scape/SmoothDriver.java new file mode 100644 index 0000000..ef9d50d --- /dev/null +++ b/NET/worlds/scape/SmoothDriver.java @@ -0,0 +1,684 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.console.Window; +/* */ import java.io.IOException; +/* */ import java.util.Enumeration; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class SmoothDriver +/* */ extends SwitchableBehavior +/* */ implements MouseDeltaHandler, KeyUpHandler, KeyDownHandler, FrameHandler, MouseDownHandler, MouseUpHandler, MomentumBehavior +/* */ { +/* */ protected float FB_force; +/* */ protected boolean FB_forceFromMouse; +/* */ protected float FB_vel; +/* */ protected float LR_force; +/* */ protected float LR_vel; +/* */ protected int lastTime; +/* */ +/* */ public boolean handle(MouseDeltaEvent e) +/* */ { +/* 68 */ if (UniverseHandler.handle(e)) { +/* 69 */ return true; +/* */ } +/* 71 */ if ((e.dx != 0) || (e.dy != 0)) +/* */ { +/* 73 */ applyFrameForce(e); +/* */ +/* 75 */ float dx2 = e.dx * e.dx; +/* 76 */ float dy2 = e.dy * e.dy; +/* 77 */ double arrrr = Math.sqrt(dx2 + dy2); +/* */ +/* 79 */ if (e.dy < 0) +/* 80 */ dy2 = -dy2; +/* 81 */ this.FB_vel -= (float)(1.1D * dy2 / arrrr); +/* */ +/* 83 */ if (e.dx < 0) +/* 84 */ dx2 = -dx2; +/* 85 */ this.LR_vel -= (float)(0.5D * dx2 / arrrr); +/* */ } +/* 87 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 104 */ protected float maxdvFB = 300.0F; +/* */ +/* */ +/* */ +/* */ +/* */ +/* 110 */ protected float FB_damp = -2.5F; +/* */ +/* */ public void setVelocityDamping(float pDamp) +/* */ { +/* 114 */ this.FB_damp = pDamp; +/* */ } +/* */ +/* */ public float getVelocityDamping() +/* */ { +/* 119 */ return this.FB_damp; +/* */ } +/* */ +/* */ +/* 123 */ protected float minFB_vel = 4.0F; +/* */ +/* */ +/* 126 */ protected float minFB_pixDouble = 40.0F; +/* */ +/* */ +/* 129 */ protected float maxdvLR = 166.0F; +/* */ +/* */ +/* */ +/* */ +/* */ +/* 135 */ protected float LR_damp = -5.0F; +/* */ +/* */ +/* 138 */ protected float minLR_vel = 3.0F; +/* */ +/* */ +/* 141 */ protected float minLR_pixDouble = 40.0F; +/* */ +/* */ +/* */ +/* */ +/* */ +/* 147 */ protected float eyeHeight = 150.0F; +/* */ +/* */ public void setEyeHeight(float newHeight) +/* */ { +/* 151 */ this.eyeHeight = newHeight; +/* */ } +/* */ +/* */ public float getEyeHeight() +/* */ { +/* 156 */ return this.eyeHeight; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void applyFrameForce(Event e) +/* */ { +/* 171 */ if (!(e.receiver instanceof Pilot)) { +/* 172 */ return; +/* */ } +/* 174 */ Pilot pilot = (Pilot)e.receiver; +/* 175 */ if (!pilot.isActive()) { +/* 176 */ return; +/* */ } +/* 178 */ this.appliedForceThisFrame += 1; +/* */ +/* */ +/* 181 */ int now = e.time; +/* 182 */ float dt = (now - this.lastTime) / 1000.0F; +/* */ +/* */ +/* */ +/* 186 */ if (dt <= 0.0F) { +/* 187 */ return; +/* */ } +/* */ +/* */ +/* 191 */ if (dt > 0.33F) { +/* 192 */ dt = 0.33F; +/* */ } +/* 194 */ this.lastTime = now; +/* */ +/* */ +/* 197 */ float dx = this.FB_vel * dt; +/* */ +/* */ +/* */ +/* 201 */ float dv = 0.0F; +/* */ +/* */ +/* 204 */ if (this.FB_force != 0.0F) +/* */ { +/* 206 */ dv += this.FB_force * dt; +/* */ +/* */ +/* */ +/* */ +/* 211 */ dv = this.maxdvFB * (float)Math.atan(dv / this.maxdvFB); +/* */ +/* 213 */ this.FB_vel += dv; +/* 214 */ dx += dv * dt; +/* */ } +/* */ +/* */ +/* 218 */ float dz = this.eyeHeight - pilot.getZ(); +/* 219 */ Room room = pilot.getRoom(); +/* 220 */ if (room != null) { +/* 221 */ dz += room.floorHeight( +/* 222 */ pilot.getX(), pilot.getY(), pilot.getZ()); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* 229 */ if ((dx != 0.0F) || (dz != 0.0F)) { +/* 230 */ moveLevel(pilot, dx, dz); +/* */ } +/* */ +/* 233 */ this.FB_vel = ((float)(this.FB_vel * Math.exp(this.FB_damp * dt))); +/* 234 */ if (Math.abs(this.FB_vel) < this.minFB_vel) { +/* 235 */ this.FB_vel = 0.0F; +/* */ } +/* */ +/* */ +/* */ +/* 240 */ float dTheta = this.LR_vel * dt; +/* */ +/* */ +/* 243 */ float dv = 0.0F; +/* */ +/* 245 */ if (this.LR_force != 0.0F) +/* */ { +/* 247 */ dv += this.LR_force * dt; +/* */ +/* */ +/* */ +/* 251 */ dv = this.maxdvLR * (float)Math.atan(dv / this.maxdvLR); +/* */ +/* 253 */ this.LR_vel += dv; +/* 254 */ dTheta += dv * dt; +/* */ } +/* */ +/* 257 */ if (dTheta != 0.0F) { +/* 258 */ yawLevel(pilot, dTheta); +/* */ } +/* 260 */ this.LR_vel = ((float)(this.LR_vel * Math.exp(this.LR_damp * dt))); +/* 261 */ if (Math.abs(this.LR_vel) < this.minLR_vel) { +/* 262 */ this.LR_vel = 0.0F; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void moveLevel(Pilot pilot, float dx, float dz) +/* */ { +/* 272 */ float currentYaw = pilot.getYaw(); +/* 273 */ Point3Temp currentSpinAxis = Point3Temp.make(); +/* 274 */ float currentSpin = pilot.getSpin(currentSpinAxis); +/* 275 */ Point3Temp currentPosition = pilot.getPosition(); +/* */ +/* 277 */ pilot.makeIdentity() +/* 278 */ .moveTo(currentPosition) +/* 279 */ .yaw(-currentYaw); +/* */ +/* 281 */ pilot.premoveThrough(Point3Temp.make(0.0F, dx, dz)); +/* */ +/* 283 */ pilot.yaw(currentYaw); +/* 284 */ pilot.spin(currentSpinAxis, currentSpin); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void yawLevel(Pilot pilot, float dTheta) +/* */ { +/* 293 */ float currentYaw = pilot.getYaw(); +/* 294 */ Point3Temp currentSpinAxis = Point3Temp.make(); +/* 295 */ float currentSpin = pilot.getSpin(currentSpinAxis); +/* 296 */ Point3Temp currentPosition = pilot.getPosition(); +/* */ +/* 298 */ pilot.makeIdentity() +/* 299 */ .moveTo(currentPosition) +/* 300 */ .yaw(-currentYaw); +/* */ +/* 302 */ pilot.yaw(dTheta); +/* */ +/* 304 */ pilot.yaw(currentYaw); +/* 305 */ pilot.spin(currentSpinAxis, currentSpin); +/* */ } +/* */ +/* 308 */ private int appliedForceThisFrame = 0; +/* 309 */ private int forceDouble = 0; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean handle(FrameEvent e) +/* */ { +/* 317 */ if ((this.FB_forceFromMouse) && (!isDelta(e))) { +/* 318 */ applyFrameForce(e); +/* 319 */ this.FB_force = 0.0F; +/* 320 */ this.FB_forceFromMouse = false; +/* */ } +/* */ +/* */ +/* 324 */ if (this.appliedForceThisFrame == 0) +/* 325 */ applyFrameForce(e); +/* 326 */ this.appliedForceThisFrame = 0; +/* 327 */ return true; +/* */ } +/* */ +/* */ +/* 331 */ protected float FB_key = 1200.0F; +/* */ +/* */ +/* 334 */ protected float LR_key = 500.0F; +/* */ +/* */ +/* */ +/* */ +/* */ public boolean handle(KeyDownEvent e) +/* */ { +/* 341 */ if (UniverseHandler.handle(e)) { +/* 342 */ return true; +/* */ } +/* */ +/* */ float FB; +/* 346 */ if (e.key == 58150) { +/* 347 */ FB = this.FB_key; } else { float FB; +/* 348 */ if (e.key == 58152) { +/* 349 */ FB = -this.FB_key; +/* */ } +/* */ else { +/* */ float LR; +/* 353 */ if (e.key == 58149) { +/* 354 */ LR = this.LR_key; } else { float LR; +/* 355 */ if (e.key == 58151) { +/* 356 */ LR = -this.LR_key; +/* */ } else +/* 358 */ return true; } +/* */ float LR; +/* 360 */ applyFrameForce(e); +/* */ +/* */ +/* 363 */ this.LR_force = LR; +/* 364 */ return true; +/* */ } } +/* */ float FB; +/* 367 */ applyFrameForce(e); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 377 */ this.FB_force = FB; +/* 378 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public boolean handle(KeyUpEvent e) +/* */ { +/* 386 */ if (UniverseHandler.handle(e)) { +/* 387 */ return true; +/* */ } +/* */ +/* 390 */ if ((e.key == 58150) || (e.key == 58152)) { +/* 391 */ applyFrameForce(e); +/* 392 */ this.FB_force = 0.0F; +/* 393 */ } else if ((e.key == 58149) || (e.key == 58151)) { +/* 394 */ applyFrameForce(e); +/* 395 */ this.LR_force = 0.0F; +/* */ } +/* 397 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ private boolean isDelta(Event e) +/* */ { +/* 404 */ if ((!(e.receiver instanceof Pilot)) || (!((Pilot)e.receiver).isActive())) { +/* 405 */ return false; +/* */ } +/* 407 */ Window w = Window.getMainWindow(); +/* 408 */ if ((w == null) || (!w.getDeltaMode())) { +/* 409 */ return false; +/* */ } +/* 411 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public boolean handle(MouseDownEvent e) +/* */ { +/* 419 */ if ((e.key == 58114) && (isDelta(e))) { +/* 420 */ applyFrameForce(e); +/* */ +/* */ +/* 423 */ this.FB_force = this.FB_key; +/* 424 */ this.FB_forceFromMouse = true; +/* */ } +/* 426 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public boolean handle(MouseUpEvent e) +/* */ { +/* 434 */ if ((e.key == 58114) && (isDelta(e))) { +/* 435 */ applyFrameForce(e); +/* */ +/* */ +/* 438 */ this.FB_force = 0.0F; +/* 439 */ this.FB_forceFromMouse = false; +/* */ } +/* 441 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public Object properties(int index, int offset, int mode, Object value) +/* */ throws NoSuchPropertyException +/* */ { +/* 450 */ Object ret = null; +/* 451 */ switch (index - offset) { +/* */ case 0: +/* 453 */ if (mode == 0) { +/* 454 */ ret = FloatPropertyEditor.make( +/* 455 */ new Property(this, index, "Eye Height")); +/* 456 */ } else if (mode == 1) { +/* 457 */ ret = new Float(getEyeHeight()); +/* 458 */ } else if (mode == 2) +/* 459 */ setEyeHeight(((Float)value).floatValue()); +/* 460 */ break; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ case 1: +/* 472 */ if (mode == 0) { +/* 473 */ ret = FloatPropertyEditor.make( +/* 474 */ new Property(this, index, "Fore/aft max acceleration")); +/* 475 */ } else if (mode == 1) { +/* 476 */ ret = new Float(this.maxdvFB); +/* 477 */ } else if (mode == 2) +/* 478 */ this.maxdvFB = ((Float)value).floatValue(); +/* 479 */ break; +/* */ case 2: +/* 481 */ if (mode == 0) { +/* 482 */ ret = FloatPropertyEditor.make( +/* 483 */ new Property(this, index, "Fore/aft velocity damping")); +/* 484 */ } else if (mode == 1) { +/* 485 */ ret = new Float(this.FB_damp); +/* 486 */ } else if (mode == 2) +/* 487 */ this.FB_damp = ((Float)value).floatValue(); +/* 488 */ break; +/* */ case 3: +/* 490 */ if (mode == 0) { +/* 491 */ ret = FloatPropertyEditor.make( +/* 492 */ new Property(this, index, "Fore/aft min velocity")); +/* 493 */ } else if (mode == 1) { +/* 494 */ ret = new Float(this.minFB_vel); +/* 495 */ } else if (mode == 2) +/* 496 */ this.minFB_vel = ((Float)value).floatValue(); +/* 497 */ break; +/* */ case 4: +/* 499 */ if (mode == 0) { +/* 500 */ ret = FloatPropertyEditor.make( +/* 501 */ new Property(this, index, +/* 502 */ "Fore/aft velocity threshold for pixel doubling")); +/* 503 */ } else if (mode == 1) { +/* 504 */ ret = new Float(this.minFB_pixDouble); +/* 505 */ } else if (mode == 2) +/* 506 */ this.minFB_pixDouble = ((Float)value).floatValue(); +/* 507 */ break; +/* */ case 5: +/* 509 */ if (mode == 0) { +/* 510 */ ret = FloatPropertyEditor.make( +/* 511 */ new Property(this, index, "Yaw max acceleration")); +/* 512 */ } else if (mode == 1) { +/* 513 */ ret = new Float(this.maxdvLR); +/* 514 */ } else if (mode == 2) +/* 515 */ this.maxdvLR = ((Float)value).floatValue(); +/* 516 */ break; +/* */ case 6: +/* 518 */ if (mode == 0) { +/* 519 */ ret = FloatPropertyEditor.make( +/* 520 */ new Property(this, index, "Yaw rate damping")); +/* 521 */ } else if (mode == 1) { +/* 522 */ ret = new Float(this.LR_damp); +/* 523 */ } else if (mode == 2) +/* 524 */ this.LR_damp = ((Float)value).floatValue(); +/* 525 */ break; +/* */ case 7: +/* 527 */ if (mode == 0) { +/* 528 */ ret = FloatPropertyEditor.make( +/* 529 */ new Property(this, index, "Yaw min rate")); +/* 530 */ } else if (mode == 1) { +/* 531 */ ret = new Float(this.minLR_vel); +/* 532 */ } else if (mode == 2) +/* 533 */ this.minLR_vel = ((Float)value).floatValue(); +/* 534 */ break; +/* */ case 8: +/* 536 */ if (mode == 0) { +/* 537 */ ret = FloatPropertyEditor.make( +/* 538 */ new Property(this, index, +/* 539 */ "Yaw rate threshold for pixel doubling")); +/* 540 */ } else if (mode == 1) { +/* 541 */ ret = new Float(this.minLR_pixDouble); +/* 542 */ } else if (mode == 2) +/* 543 */ this.minLR_pixDouble = ((Float)value).floatValue(); +/* 544 */ break; +/* */ case 9: +/* 546 */ if (mode == 0) { +/* 547 */ ret = FloatPropertyEditor.make( +/* 548 */ new Property(this, index, +/* 549 */ "Fore/aft velocity increment for up/down arrow keys")); +/* 550 */ } else if (mode == 1) { +/* 551 */ ret = new Float(this.FB_key); +/* 552 */ } else if (mode == 2) +/* 553 */ this.FB_key = ((Float)value).floatValue(); +/* 554 */ break; +/* */ case 10: +/* 556 */ if (mode == 0) { +/* 557 */ ret = FloatPropertyEditor.make( +/* 558 */ new Property(this, index, +/* 559 */ "Yaw rate increment for up/down arrow keys")); +/* 560 */ } else if (mode == 1) { +/* 561 */ ret = new Float(this.LR_key); +/* 562 */ } else if (mode == 2) +/* 563 */ this.LR_key = ((Float)value).floatValue(); +/* 564 */ break; +/* */ default: +/* 566 */ ret = super.properties(index, offset + 11, mode, value); +/* */ } +/* 568 */ return ret; +/* */ } +/* */ +/* 571 */ private static Object classCookie = new Object(); +/* */ +/* */ public void saveState(Saver s) throws IOException +/* */ { +/* 575 */ s.saveVersion(3, classCookie); +/* 576 */ super.saveState(s); +/* 577 */ s.saveFloat(this.FB_vel); +/* 578 */ s.saveFloat(this.LR_vel); +/* 579 */ s.saveFloat(this.maxdvFB); +/* 580 */ s.saveFloat(this.FB_damp); +/* 581 */ s.saveFloat(this.minFB_vel); +/* 582 */ s.saveFloat(this.maxdvLR); +/* 583 */ s.saveFloat(this.LR_damp); +/* 584 */ s.saveFloat(this.minLR_vel); +/* 585 */ s.saveFloat(this.eyeHeight); +/* 586 */ s.saveFloat(this.FB_key); +/* 587 */ s.saveFloat(this.LR_key); +/* 588 */ s.saveInt(this.forceDouble); +/* */ } +/* */ +/* */ public void restoreState(Restorer r) throws IOException, TooNewException +/* */ { +/* 593 */ switch (r.restoreVersion(classCookie)) { +/* */ case 0: +/* 595 */ r.setOldFlag(); +/* 596 */ super.restoreState(r); +/* 597 */ r.restoreFloat(); +/* 598 */ this.FB_vel = r.restoreFloat(); +/* 599 */ r.restoreFloat(); +/* 600 */ this.LR_vel = r.restoreFloat(); +/* 601 */ break; +/* */ case 1: +/* 603 */ r.setOldFlag(); +/* 604 */ super.restoreState(r); +/* 605 */ r.restoreFloat(); +/* 606 */ this.FB_vel = r.restoreFloat(); +/* 607 */ r.restoreFloat(); +/* 608 */ this.LR_vel = r.restoreFloat(); +/* 609 */ this.maxdvFB = r.restoreFloat(); +/* 610 */ this.FB_damp = r.restoreFloat(); +/* 611 */ this.minFB_vel = r.restoreFloat(); +/* 612 */ this.maxdvLR = r.restoreFloat(); +/* 613 */ this.LR_damp = r.restoreFloat(); +/* 614 */ this.minLR_vel = r.restoreFloat(); +/* 615 */ this.eyeHeight = r.restoreFloat(); +/* 616 */ this.FB_key = r.restoreFloat(); +/* 617 */ this.LR_key = r.restoreFloat(); +/* 618 */ break; +/* */ case 2: +/* 620 */ r.setOldFlag(); +/* 621 */ super.restoreState(r); +/* 622 */ r.restoreFloat(); +/* 623 */ this.FB_vel = r.restoreFloat(); +/* 624 */ r.restoreFloat(); +/* 625 */ this.LR_vel = r.restoreFloat(); +/* 626 */ this.maxdvFB = r.restoreFloat(); +/* 627 */ this.FB_damp = r.restoreFloat(); +/* 628 */ this.minFB_vel = r.restoreFloat(); +/* 629 */ this.maxdvLR = r.restoreFloat(); +/* 630 */ this.LR_damp = r.restoreFloat(); +/* 631 */ this.minLR_vel = r.restoreFloat(); +/* 632 */ this.eyeHeight = r.restoreFloat(); +/* 633 */ this.FB_key = r.restoreFloat(); +/* 634 */ this.LR_key = r.restoreFloat(); +/* 635 */ this.forceDouble = r.restoreInt(); +/* 636 */ break; +/* */ case 3: +/* 638 */ super.restoreState(r); +/* 639 */ this.FB_vel = r.restoreFloat(); +/* 640 */ this.LR_vel = r.restoreFloat(); +/* 641 */ this.maxdvFB = r.restoreFloat(); +/* 642 */ this.FB_damp = r.restoreFloat(); +/* 643 */ this.minFB_vel = r.restoreFloat(); +/* 644 */ this.maxdvLR = r.restoreFloat(); +/* 645 */ this.LR_damp = r.restoreFloat(); +/* 646 */ this.minLR_vel = r.restoreFloat(); +/* 647 */ this.eyeHeight = r.restoreFloat(); +/* 648 */ this.FB_key = r.restoreFloat(); +/* 649 */ this.LR_key = r.restoreFloat(); +/* 650 */ this.forceDouble = r.restoreInt(); +/* 651 */ break; +/* */ default: +/* 653 */ throw new TooNewException(); +/* */ } +/* */ } +/* */ +/* */ public void transferFrom(Enumeration<Object> oldMBs) +/* */ { +/* 659 */ this.FB_force = 0.0F; +/* 660 */ this.LR_force = 0.0F; +/* */ +/* */ +/* 663 */ while (oldMBs.hasMoreElements()) { +/* 664 */ SuperRoot sr = (SuperRoot)oldMBs.nextElement(); +/* 665 */ if ((sr instanceof SmoothDriver)) { +/* 666 */ SmoothDriver sd = (SmoothDriver)sr; +/* 667 */ this.FB_vel = sd.FB_vel; +/* 668 */ this.LR_vel = sd.LR_vel; +/* 669 */ this.lastTime = sd.lastTime; +/* 670 */ return; +/* */ } +/* */ } +/* */ +/* 674 */ this.FB_vel = 0.0F; +/* 675 */ this.LR_vel = 0.0F; +/* 676 */ this.lastTime = 0; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\SmoothDriver.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |