summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/VehicleDriver.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/scape/VehicleDriver.java')
-rw-r--r--NET/worlds/scape/VehicleDriver.java1086
1 files changed, 1086 insertions, 0 deletions
diff --git a/NET/worlds/scape/VehicleDriver.java b/NET/worlds/scape/VehicleDriver.java
new file mode 100644
index 0000000..79b6406
--- /dev/null
+++ b/NET/worlds/scape/VehicleDriver.java
@@ -0,0 +1,1086 @@
+/* */ package NET.worlds.scape;
+/* */
+/* */ import java.io.PrintStream;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class VehicleDriver
+/* */ extends SwitchableBehavior
+/* */ implements MouseDeltaHandler, KeyUpHandler, KeyDownHandler, MouseDownHandler, MouseUpHandler, FrameHandler
+/* */ {
+/* */ protected VehicleShape vehicle;
+/* */ static final boolean debug = true;
+/* */ static final float gravity = 32.1F;
+/* */ static final float densityOfAir = 0.0801F;
+/* */ static final float dragCoefficient = 0.3F;
+/* */ static final float feetToWorld = 30.48F;
+/* */ static final float worldToFeet = 0.0328084F;
+/* */ static final float epsilon = 0.001F;
+/* */ static final float maxCamber = 0.4F;
+/* */ static final float rotationalDampener = 0.5F;
+/* */ static final int asphalt = 0;
+/* */ static final int grass = 1;
+/* */ static final int numTerrainTypes = 2;
+/* 66 */ float acceleratorDepression = 0.0F;
+/* */
+/* 68 */ float brakesDepression = 0.0F;
+/* */
+/* 70 */ int currentGear = 1;
+/* */
+/* 72 */ float steeringWheelPosition = 0.0F;
+/* */
+/* 74 */ boolean gasKeyDown = false; boolean brakeKeyDown = false;
+/* 75 */ boolean leftKeyDown = false; boolean rightKeyDown = false;
+/* */
+/* */
+/* 78 */ Point3 velocityVector = new Point3(0.0F, 0.0F, 0.0F);
+/* 79 */ Point3 velocityVectorCarFrame = new Point3(0.0F, 0.0F, 0.0F);
+/* 80 */ float velocity = 0.0F;
+/* */
+/* 82 */ Point3 angularVelocity = new Point3(0.0F, 0.0F, 0.0F);
+/* 83 */ Point3 angularVelocityCarFrame = new Point3(0.0F, 0.0F, 0.0F);
+/* */
+/* 85 */ Point3 worldCenterOfMass = new Point3(0.0F, 0.0F, 0.0F);
+/* 86 */ float engineRPM = 0.0F;
+/* */
+/* */
+/* */
+/* 90 */ Point3 integratedForce = new Point3(0.0F, 0.0F, 0.0F);
+/* */
+/* 92 */ Point3 integratedTorque = new Point3(0.0F, 0.0F, 0.0F);
+/* */
+/* */
+/* 95 */ boolean disabled = false;
+/* */
+/* */ float[] minRPMs;
+/* */ Tire[] tires;
+/* */ protected Room room;
+/* */ protected Pilot pilot;
+/* */
+/* */ protected class Tire
+/* */ {
+/* */ Point3 force;
+/* */ Point3 torque;
+/* */ Point3 relativePos;
+/* */ float underGround;
+/* */ double driveForce;
+/* */ float wheelAngle;
+/* */ boolean slipping;
+/* */
+/* */ public Tire()
+/* */ {
+/* 114 */ this.force = new Point3();
+/* 115 */ this.torque = new Point3();
+/* 116 */ this.relativePos = new Point3();
+/* 117 */ this.driveForce = 0.0D;
+/* 118 */ this.underGround = 0.0F;
+/* 119 */ this.wheelAngle = 0.0F;
+/* 120 */ this.slipping = false;
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public VehicleDriver(VehicleShape p_Vehicle)
+/* */ {
+/* 132 */ this.vehicle = p_Vehicle;
+/* */
+/* 134 */ initLateralForceTable();
+/* 135 */ initTorqueTable();
+/* 136 */ initRPMTable();
+/* 137 */ this.tires = new Tire[4];
+/* 138 */ for (int tire = 0; tire < 4; tire++)
+/* */ {
+/* 140 */ this.tires[tire] = new Tire();
+/* 141 */ this.tires[tire].relativePos.copy(this.vehicle.tirePositions[tire]);
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public boolean handle(MouseDeltaEvent e)
+/* */ {
+/* 150 */ if (UniverseHandler.handle(e)) {
+/* 151 */ return true;
+/* */ }
+/* 153 */ return false;
+/* */ }
+/* */
+/* */ public boolean handle(KeyDownEvent e)
+/* */ {
+/* 158 */ if (UniverseHandler.handle(e)) {
+/* 159 */ return true;
+/* */ }
+/* 161 */ switch (e.key)
+/* */ {
+/* */
+/* */ case '':
+/* 165 */ this.gasKeyDown = true;
+/* 166 */ break;
+/* */
+/* */
+/* */
+/* */ case '':
+/* 171 */ this.brakeKeyDown = true;
+/* 172 */ break;
+/* */
+/* */
+/* */
+/* */ case '':
+/* 177 */ this.leftKeyDown = true;
+/* 178 */ break;
+/* */
+/* */
+/* */
+/* */ case '':
+/* 183 */ this.rightKeyDown = true;
+/* 184 */ break;
+/* */
+/* */
+/* */
+/* */ case 'R':
+/* */ case 'r':
+/* 190 */ this.currentGear = 0;
+/* 191 */ break;
+/* */
+/* */
+/* */
+/* */ case '1':
+/* 196 */ if (this.vehicle.stickShift) this.currentGear = 1;
+/* 197 */ break;
+/* */
+/* */
+/* */
+/* */ case '2':
+/* 202 */ if (this.vehicle.stickShift) this.currentGear = 2;
+/* 203 */ break;
+/* */
+/* */
+/* */
+/* */ case '3':
+/* 208 */ if (this.vehicle.stickShift) this.currentGear = 3;
+/* 209 */ break;
+/* */
+/* */
+/* */
+/* */ case '4':
+/* 214 */ if (this.vehicle.stickShift) this.currentGear = 4;
+/* 215 */ break;
+/* */
+/* */
+/* */
+/* */ case '5':
+/* 220 */ if (this.vehicle.stickShift) { this.currentGear = 5;
+/* */ }
+/* */ break;
+/* */ }
+/* */
+/* 225 */ return true;
+/* */ }
+/* */
+/* */ public boolean handle(KeyUpEvent e)
+/* */ {
+/* 230 */ if (UniverseHandler.handle(e)) {
+/* 231 */ return true;
+/* */ }
+/* 233 */ switch (e.key)
+/* */ {
+/* */
+/* */ case '':
+/* 237 */ this.gasKeyDown = false;
+/* 238 */ break;
+/* */
+/* */
+/* */
+/* */ case '':
+/* 243 */ this.brakeKeyDown = false;
+/* 244 */ break;
+/* */
+/* */
+/* */
+/* */ case '':
+/* 249 */ this.leftKeyDown = false;
+/* 250 */ break;
+/* */
+/* */
+/* */
+/* */ case '':
+/* 255 */ this.rightKeyDown = false;
+/* */ }
+/* */
+/* */
+/* */
+/* 260 */ return true;
+/* */ }
+/* */
+/* */ public boolean handle(MouseDownEvent e)
+/* */ {
+/* 265 */ return false;
+/* */ }
+/* */
+/* */ public boolean handle(MouseUpEvent e)
+/* */ {
+/* 270 */ return false;
+/* */ }
+/* */
+/* 273 */ static float lastTime = 0.0F;
+/* */ static final int lateralForceIncrements = 1000;
+/* */ static float[][] muTable;
+/* */
+/* */ public boolean handle(FrameEvent e) {
+/* 278 */ if (!(e.receiver instanceof Pilot)) {
+/* 279 */ return true;
+/* */ }
+/* 281 */ this.pilot = ((Pilot)e.receiver);
+/* 282 */ if (!this.pilot.isActive()) {
+/* 283 */ return true;
+/* */ }
+/* */
+/* 286 */ Point3Temp com = Point3Temp.make(this.vehicle.centerOfGravity);
+/* 287 */ com.times(30.48F);
+/* 288 */ com.times(this.pilot.getObjectToWorldMatrix());
+/* */
+/* 290 */ com.times(0.0328084F);
+/* 291 */ this.worldCenterOfMass.set(com.x, com.y, com.z);
+/* */
+/* */
+/* 294 */ this.room = this.pilot.getRoom();
+/* */
+/* */
+/* */
+/* 298 */ int now = e.time;
+/* 299 */ float dt = (now - lastTime) / 1000.0F;
+/* 300 */ lastTime = now;
+/* */
+/* */
+/* */
+/* 304 */ if (dt <= 0.0F) {
+/* 305 */ return true;
+/* */ }
+/* */
+/* */
+/* 309 */ if (dt > 0.33F) {
+/* 310 */ dt = 0.33F;
+/* */ }
+/* */
+/* 313 */ if (this.gasKeyDown) {
+/* 314 */ this.acceleratorDepression = ((float)(this.acceleratorDepression + 1.2D * dt));
+/* */ } else
+/* 316 */ this.acceleratorDepression = 0.0F;
+/* 317 */ if (this.acceleratorDepression > 1.0D) {
+/* 318 */ this.acceleratorDepression = 1.0F;
+/* */ }
+/* 320 */ if (this.brakeKeyDown) {
+/* 321 */ this.brakesDepression = ((float)(this.brakesDepression + 1.2D * dt));
+/* */ } else
+/* 323 */ this.brakesDepression = 0.0F;
+/* 324 */ if (this.brakesDepression > 1.0D) {
+/* 325 */ this.brakesDepression = 1.0F;
+/* */ }
+/* 327 */ float wheelDelta = 0.282F * dt;
+/* */
+/* */
+/* 330 */ if (Math.abs(this.velocityVectorCarFrame.y) < 10.0F) {
+/* 331 */ wheelDelta = (float)(wheelDelta * 0.5D);
+/* */ }
+/* 333 */ if (this.leftKeyDown) {
+/* 334 */ this.steeringWheelPosition -= wheelDelta;
+/* 335 */ } else if (this.rightKeyDown) {
+/* 336 */ this.steeringWheelPosition += wheelDelta;
+/* */ } else
+/* 338 */ this.steeringWheelPosition = 0.0F;
+/* 339 */ if (this.steeringWheelPosition > 0.5D)
+/* 340 */ this.steeringWheelPosition = 0.5F;
+/* 341 */ if (this.steeringWheelPosition < -0.5D) {
+/* 342 */ this.steeringWheelPosition = -0.5F;
+/* */ }
+/* 344 */ DoPhysics(dt);
+/* */
+/* 346 */ return true;
+/* */ }
+/* */
+/* */
+/* */
+/* */ protected void DoPhysics(float dt)
+/* */ {
+/* 353 */ System.out.println("-----------------------------");
+/* */
+/* */
+/* 356 */ float engineTorque = this.vehicle.maxEngineTorque *
+/* 357 */ this.acceleratorDepression * getTorque(this.engineRPM);
+/* */
+/* 359 */ assert (this.vehicle.wheelDiameter != 0.0F);
+/* */
+/* 361 */ float gearRatio = getGearRatio(this.currentGear);
+/* */
+/* */
+/* */
+/* 365 */ float wheelForce = engineTorque * this.vehicle.rearEndRatio *
+/* 366 */ gearRatio / (this.vehicle.wheelDiameter * 0.5F);
+/* */
+/* */
+/* 369 */ if (Math.abs(this.velocityVectorCarFrame.y) > 2.0D)
+/* */ {
+/* 371 */ wheelForce -= this.brakesDepression * this.vehicle.mass * 100.0F;
+/* */
+/* */
+/* */ }
+/* 375 */ else if (this.brakesDepression > 0.0F) {
+/* 376 */ this.velocityVectorCarFrame.y = 0.0F;
+/* */ }
+/* */
+/* */
+/* 380 */ if (gearRatio == 0.0F) {
+/* 381 */ wheelForce *= -1.0F;
+/* */ }
+/* */
+/* 384 */ if (this.disabled) {
+/* 385 */ wheelForce = 0.0F;
+/* */ }
+/* */
+/* 388 */ switch (this.vehicle.driveType)
+/* */ {
+/* */
+/* */ case 0:
+/* 392 */ wheelForce = (float)(wheelForce * 0.25D);
+/* 393 */ this.tires[0].driveForce = (this.tires[1].driveForce =
+/* 394 */ wheelForce);
+/* 395 */ this.tires[2].driveForce = (this.tires[3].driveForce =
+/* 396 */ wheelForce);
+/* 397 */ break;
+/* */
+/* */
+/* */
+/* */ case 1:
+/* 402 */ wheelForce = (float)(wheelForce * 0.5D);
+/* 403 */ this.tires[0].driveForce = (this.tires[1].driveForce =
+/* 404 */ wheelForce);
+/* 405 */ this.tires[2].driveForce = (this.tires[3].driveForce = 0.0D);
+/* 406 */ break;
+/* */
+/* */
+/* */
+/* */ case 2:
+/* */ default:
+/* 412 */ wheelForce = (float)(wheelForce * 0.5D);
+/* 413 */ this.tires[0].driveForce = (this.tires[1].driveForce = 0.0D);
+/* 414 */ this.tires[2].driveForce = (this.tires[3].driveForce =
+/* 415 */ wheelForce);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* 421 */ float wheelAngle = this.steeringWheelPosition * 1.57F;
+/* */
+/* 423 */ this.tires[0].wheelAngle = (this.tires[1].wheelAngle = -wheelAngle);
+/* */
+/* */
+/* 426 */ float wheelRPM = 60.0F * this.velocityVectorCarFrame.y / (
+/* 427 */ 3.1415927F * this.vehicle.wheelDiameter);
+/* 428 */ this.engineRPM = (wheelRPM * this.vehicle.rearEndRatio * gearRatio);
+/* 429 */ if (this.engineRPM < this.vehicle.idleRPM) {
+/* 430 */ this.engineRPM = this.vehicle.idleRPM;
+/* */ }
+/* 432 */ if (!this.vehicle.stickShift)
+/* */ {
+/* 434 */ if (this.engineRPM > this.vehicle.rpmTorquePeak)
+/* */ {
+/* 436 */ if (this.currentGear < 5)
+/* 437 */ this.currentGear += 1;
+/* */ }
+/* 439 */ if (this.engineRPM < this.minRPMs[this.currentGear])
+/* */ {
+/* 441 */ if (this.currentGear > 1) {
+/* 442 */ this.currentGear -= 1;
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 452 */ Point3Temp netForce = Point3Temp.make(0.0F, 0.0F, 0.0F);
+/* 453 */ Point3Temp netTorque = Point3Temp.make(0.0F, 0.0F, 0.0F);
+/* 454 */ for (int wheel = 0; wheel < 4; wheel++)
+/* */ {
+/* 456 */ calculateForces(this.tires[wheel]);
+/* 457 */ netForce.plus(this.tires[wheel].force);
+/* 458 */ netTorque.plus(this.tires[wheel].torque);
+/* */ }
+/* */
+/* */
+/* 462 */ Point3Temp airFriction = Point3Temp.make(this.velocityVectorCarFrame);
+/* 463 */ airFriction.negate();
+/* 464 */ airFriction.normalize();
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 471 */ float drag = 0.15F * this.vehicle.frontalArea *
+/* 472 */ 0.0801F * this.velocity * this.velocity / 32.1F;
+/* 473 */ airFriction.times(drag);
+/* 474 */ netForce.plus(airFriction);
+/* */
+/* */
+/* 477 */ netForce.vectorTimes(this.pilot.getObjectToWorldMatrix());
+/* */
+/* */
+/* */
+/* 481 */ System.out.println("Net force " + netForce.x + " " +
+/* 482 */ netForce.y + " " + netForce.z);
+/* 483 */ System.out.println("Net torque " + netTorque.x + " " +
+/* 484 */ netTorque.y + " " + netTorque.z);
+/* */
+/* */
+/* */
+/* */
+/* 489 */ Point3Temp gravityForce = Point3Temp.make(0.0F, 0.0F,
+/* 490 */ -this.vehicle.mass * 32.1F);
+/* 491 */ netForce.plus(gravityForce);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 497 */ Point3Temp inertialDampener = Point3Temp.make(0.5F,
+/* 498 */ 0.5F, 0.5F);
+/* 499 */ inertialDampener.times(this.angularVelocityCarFrame);
+/* 500 */ inertialDampener.times(this.vehicle.momentsOfInertia);
+/* 501 */ inertialDampener.times(1.0F / dt);
+/* 502 */ netTorque.minus(inertialDampener);
+/* */
+/* */
+/* */
+/* 506 */ this.integratedForce.plus(netForce);
+/* 507 */ this.integratedForce.times(0.5F);
+/* 508 */ this.integratedTorque.plus(netTorque);
+/* 509 */ this.integratedTorque.times(0.5F);
+/* */
+/* */
+/* */
+/* 513 */ Point3Temp acceleration = Point3Temp.make(this.integratedForce);
+/* 514 */ acceleration.times(1.0F / this.vehicle.mass);
+/* */
+/* 516 */ Point3Temp dV = Point3Temp.make(acceleration);
+/* 517 */ dV.times(dt);
+/* */
+/* */
+/* 520 */ Point3Temp lastV = Point3Temp.make(this.velocityVector);
+/* 521 */ Point3Temp lastW = Point3Temp.make(this.angularVelocityCarFrame);
+/* 522 */ this.velocityVector.plus(dV);
+/* 523 */ this.velocityVector.plus(lastV);
+/* 524 */ this.velocityVector.times(0.5F);
+/* 525 */ this.velocity = this.velocityVector.length();
+/* 526 */ this.velocityVectorCarFrame.copy(this.velocityVector);
+/* 527 */ this.velocityVectorCarFrame.vectorTimes(
+/* 528 */ this.pilot.getObjectToWorldMatrix().invert());
+/* */
+/* */
+/* 531 */ Point3Temp dw = Point3Temp.make(this.integratedTorque);
+/* 532 */ dw.times(dt);
+/* 533 */ dw.dividedBy(this.vehicle.momentsOfInertia);
+/* */
+/* 535 */ this.angularVelocityCarFrame.plus(dw);
+/* 536 */ this.angularVelocityCarFrame.plus(lastW);
+/* 537 */ this.angularVelocityCarFrame.times(0.5F);
+/* 538 */ this.angularVelocity.copy(this.angularVelocityCarFrame);
+/* 539 */ this.angularVelocity.vectorTimes(this.pilot.getObjectToWorldMatrix());
+/* */
+/* */
+/* 542 */ Point3Temp dx = Point3Temp.make(this.velocityVector);
+/* 543 */ dx.times(dt);
+/* */
+/* 545 */ float maxUnderground = 0.0F;
+/* 546 */ for (int tire = 0; tire < 4; tire++)
+/* */ {
+/* 548 */ float diff = -this.tires[tire].underGround;
+/* 549 */ if (diff > maxUnderground)
+/* 550 */ maxUnderground = diff;
+/* */ }
+/* 552 */ dx.z += maxUnderground;
+/* */
+/* */
+/* 555 */ dx.times(30.48F);
+/* */
+/* 557 */ Point3Temp da = Point3Temp.make(this.angularVelocity);
+/* 558 */ da.times(dt);
+/* */
+/* 560 */ this.pilot.premoveThrough(dx);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 567 */ float convert = 57.295776F;
+/* 568 */ this.pilot.pitch(da.x * convert);
+/* 569 */ this.pilot.roll(da.y * convert);
+/* 570 */ this.pilot.yaw(da.z * convert);
+/* */
+/* */
+/* */
+/* 574 */ System.out.println("dx " + dx.x + " " + dx.y + " " + dx.z);
+/* 575 */ System.out.println("da " + da.x + " " + da.y + " " + da.z);
+/* 576 */ System.out.println("pos" + this.pilot.getX() + " " +
+/* 577 */ this.pilot.getY() + " " + this.pilot.getZ());
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ protected void calculateForces(Tire tire)
+/* */ {
+/* 587 */ tire.force.set(0.0F, 0.0F, 0.0F);
+/* 588 */ tire.torque.set(0.0F, 0.0F, 0.0F);
+/* */
+/* */
+/* 591 */ Transform o2w = this.pilot.getObjectToWorldMatrix();
+/* 592 */ Transform w2o = this.pilot.getObjectToWorldMatrix().invert();
+/* */
+/* 594 */ Point3Temp worldPos = Point3Temp.make(tire.relativePos);
+/* 595 */ worldPos.plus(this.vehicle.centerOfGravity);
+/* */
+/* */
+/* 598 */ worldPos.times(30.48F);
+/* */
+/* 600 */ worldPos.times(o2w);
+/* */
+/* */
+/* 603 */ double groundZ = this.room.floorHeight(worldPos.x, worldPos.y,
+/* 604 */ worldPos.z);
+/* */
+/* 606 */ Point3 N = this.room.surfaceNormal(worldPos.x, worldPos.y,
+/* 607 */ worldPos.z);
+/* */
+/* */
+/* 610 */ groundZ *= 0.03280840069055557D;
+/* 611 */ worldPos.times(0.0328084F);
+/* */
+/* 613 */ tire.underGround = ((float)(worldPos.z - groundZ));
+/* */
+/* */
+/* 616 */ if (tire.underGround > this.vehicle.shockLength) { return;
+/* */ }
+/* */
+/* */
+/* 620 */ Point3Temp R = Point3Temp.make(tire.relativePos);
+/* 621 */ R.vectorTimes(o2w);
+/* */
+/* 623 */ Point3Temp w = Point3Temp.make(this.angularVelocity);
+/* 624 */ w.cross(R);
+/* 625 */ w.plus(this.velocityVector);
+/* 626 */ Point3Temp Vp = Point3Temp.make(w);
+/* */
+/* */
+/* */
+/* 630 */ System.out.println("R " + R.x + " " + R.y + " " + R.z);
+/* 631 */ System.out.println("Vp " + Vp.x + " " + Vp.y + " " +
+/* 632 */ Vp.z);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 639 */ double normalSpeed = Vp.dot(N);
+/* */
+/* */
+/* 642 */ Point3Temp No = Point3Temp.make(N);
+/* 643 */ No.vectorTimes(w2o);
+/* */
+/* */
+/* 646 */ Point3Temp tmp = Point3Temp.make(No);
+/* 647 */ double scalarInertialMoment = tmp.dot(
+/* 648 */ this.vehicle.momentsOfInertia);
+/* 649 */ scalarInertialMoment = Math.abs(scalarInertialMoment);
+/* */
+/* */
+/* 652 */ Point3Temp orthoNormal = Point3Temp.make(R);
+/* 653 */ orthoNormal.cross(N);
+/* 654 */ double r = orthoNormal.length();
+/* */
+/* */
+/* 657 */ double denominator = r * this.vehicle.mass + scalarInertialMoment;
+/* 658 */ assert (denominator != 0.0D);
+/* 659 */ double myMass = this.vehicle.mass * 0.25D;
+/* 660 */ double weight = scalarInertialMoment * myMass /
+/* 661 */ denominator;
+/* 662 */ if (weight < 0.0D) weight = 0.0D;
+/* 663 */ if (weight > this.vehicle.mass) { weight = myMass;
+/* */ }
+/* */
+/* 666 */ assert (this.vehicle.shockLength != 0.0F);
+/* 667 */ double k = weight * 32.099998474121094D / this.vehicle.shockLength;
+/* 668 */ double springLength = worldPos.z - (groundZ +
+/* 669 */ this.vehicle.shockLength);
+/* */
+/* 671 */ if (springLength < -this.vehicle.shockLength)
+/* 672 */ springLength = -this.vehicle.shockLength;
+/* 673 */ if (springLength > this.vehicle.shockLength) {
+/* 674 */ springLength = this.vehicle.shockLength;
+/* */ }
+/* 676 */ double x = springLength;
+/* 677 */ double groundForce = -k * x;
+/* 678 */ double term = k * weight;
+/* 679 */ assert (term >= 0.0D);
+/* 680 */ double damp = -Math.sqrt(term) * normalSpeed *
+/* 681 */ this.vehicle.shockDampingCoeff;
+/* 682 */ groundForce += damp;
+/* */
+/* */
+/* 685 */ Point3Temp groundForceVector = Point3Temp.make(No);
+/* 686 */ groundForceVector.normalize();
+/* 687 */ groundForceVector.times((float)groundForce);
+/* */
+/* */
+/* */
+/* 691 */ tire.force.plus(groundForceVector);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 701 */ Point3Temp VpCarFrame = Point3Temp.make(Vp);
+/* 702 */ VpCarFrame.vectorTimes(w2o);
+/* */
+/* 704 */ Point3Temp normalVelocity = Point3Temp.make(VpCarFrame);
+/* 705 */ normalVelocity.z = 0.0F;
+/* */
+/* */
+/* */
+/* */
+/* 710 */ Point3Temp intendedForce = Point3Temp.make(0.0F, 0.0F, 0.0F);
+/* */
+/* 712 */ Transform wheelXform = Transform.make();
+/* 713 */ wheelXform.yaw(tire.wheelAngle *
+/* 714 */ 229.1831F);
+/* */ float mu;
+/* */ float mu;
+/* 717 */ if (normalVelocity.length() < 0.001F)
+/* */ {
+/* */
+/* 720 */ mu = 0.0F;
+/* */ } else { float mu;
+/* 722 */ if (Math.abs(No.x) > 0.4F)
+/* */ {
+/* */
+/* 725 */ mu = 0.0F;
+/* */ }
+/* */ else
+/* */ {
+/* 729 */ normalVelocity.normalize();
+/* */
+/* */
+/* */
+/* 733 */ Point3Temp wheelDirection = Point3Temp.make(0.0F, 1.0F, 0.0F);
+/* 734 */ wheelDirection.vectorTimes(wheelXform);
+/* */
+/* 736 */ wheelDirection.normalize();
+/* 737 */ float cosSlipAngle = normalVelocity.dot(wheelDirection);
+/* */
+/* */
+/* */
+/* 741 */ System.out.println("wheel direction " +
+/* 742 */ wheelDirection.x + " " + wheelDirection.y +
+/* 743 */ " " + wheelDirection.z);
+/* 744 */ System.out.println("normal velocity " +
+/* 745 */ normalVelocity.x + " " + normalVelocity.y +
+/* 746 */ " " + normalVelocity.z);
+/* 747 */ System.out.println("cos of slip angle " +
+/* 748 */ cosSlipAngle);
+/* */
+/* */
+/* */
+/* */
+/* 753 */ mu = getLateralForceCoef(cosSlipAngle, 0);
+/* */
+/* 755 */ float crossZ = normalVelocity.x * wheelDirection.y -
+/* 756 */ normalVelocity.y * wheelDirection.x;
+/* 757 */ if (crossZ > 0.0F)
+/* 758 */ mu *= -1.0F;
+/* */ }
+/* */ }
+/* 761 */ intendedForce.x = (mu * (float)groundForce);
+/* */
+/* */
+/* 764 */ intendedForce.y = ((float)tire.driveForce);
+/* */
+/* */
+/* */
+/* 768 */ System.out.println("Lateral forces " + intendedForce.x +
+/* 769 */ ", " + intendedForce.y);
+/* */
+/* */
+/* */
+/* 773 */ float forceMag = intendedForce.length();
+/* 774 */ float maxForce = (float)groundForce * this.vehicle.tireAdhesiveLimit;
+/* 775 */ if (forceMag > maxForce)
+/* */ {
+/* 777 */ intendedForce.normalize();
+/* 778 */ intendedForce.times(maxForce);
+/* 779 */ tire.slipping = true;
+/* */ }
+/* */ else
+/* */ {
+/* 783 */ tire.slipping = false;
+/* */ }
+/* */
+/* */
+/* */
+/* 788 */ intendedForce.vectorTimes(wheelXform);
+/* */
+/* */
+/* 791 */ tire.force.plus(intendedForce);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 806 */ Point3Temp rollingFriction = Point3Temp.make(0.0F, 0.0F, 0.0F);
+/* 807 */ float S = 1.0F;
+/* 808 */ float magV = Vp.length();
+/* 809 */ rollingFriction.y =
+/* 810 */ ((float)groundForce * 0.001F * (5.7F + 0.036F * magV * 0.6818182F) * S);
+/* 811 */ if (this.velocityVectorCarFrame.y > 0.0F) {
+/* 812 */ rollingFriction.y *= -1.0F;
+/* */ }
+/* 814 */ rollingFriction.vectorTimes(wheelXform);
+/* */
+/* */
+/* */
+/* 818 */ System.out.println("Rolling friction " +
+/* 819 */ rollingFriction.x + " " + rollingFriction.y +
+/* 820 */ " " + rollingFriction.z);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 826 */ wheelXform.recycle();
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 833 */ Point3Temp rCopy = Point3Temp.make(tire.relativePos);
+/* 834 */ rCopy.negate();
+/* 835 */ tire.torque.copy(tire.force);
+/* 836 */ tire.torque.cross(rCopy);
+/* */
+/* */
+/* */
+/* 840 */ System.out.println("Underground " + springLength +
+/* 841 */ " damping " + damp);
+/* 842 */ System.out.println("Force " + tire.force.x + " " +
+/* 843 */ tire.force.y + " " + tire.force.z);
+/* */
+/* */
+/* 846 */ System.out.println("Torque " + tire.torque.x + " " +
+/* 847 */ tire.torque.y + " " + tire.torque.z);
+/* 848 */ System.out.println(); }
+/* */
+/* */ private float getGearRatio(int gearNumber) { float gearRatio;
+/* */ float gearRatio;
+/* */ float gearRatio;
+/* */ float gearRatio;
+/* */ float gearRatio;
+/* 855 */ float gearRatio; float gearRatio; switch (gearNumber)
+/* */ {
+/* */
+/* */ case 0:
+/* 859 */ gearRatio = this.vehicle.gearRatio1;
+/* 860 */ break;
+/* */
+/* */
+/* */
+/* */ case 1:
+/* 865 */ gearRatio = this.vehicle.gearRatio1;
+/* 866 */ break;
+/* */
+/* */
+/* */
+/* */ case 2:
+/* 871 */ gearRatio = this.vehicle.gearRatio2;
+/* 872 */ break;
+/* */
+/* */
+/* */
+/* */ case 3:
+/* 877 */ gearRatio = this.vehicle.gearRatio3;
+/* 878 */ break;
+/* */
+/* */
+/* */
+/* */ case 4:
+/* 883 */ gearRatio = this.vehicle.gearRatio4;
+/* 884 */ break;
+/* */
+/* */
+/* */
+/* */ case 5:
+/* 889 */ gearRatio = this.vehicle.gearRatio5;
+/* 890 */ break;
+/* */
+/* */
+/* */
+/* */ default:
+/* 895 */ System.out.println("Illegal gear " + this.currentGear);
+/* 896 */ gearRatio = 1.0F;
+/* */ }
+/* */
+/* */
+/* */
+/* 901 */ return gearRatio;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ protected float getLateralForceCoef(float cosSlipAngle, int terrainType)
+/* */ {
+/* 911 */ if (cosSlipAngle > 1.0D) cosSlipAngle = 1.0F;
+/* 912 */ if (cosSlipAngle < -1.0D) cosSlipAngle = -1.0F;
+/* 913 */ float index = (float)Math.ceil(Math.abs(cosSlipAngle) *
+/* 914 */ 1000.0F / 1.0F);
+/* 915 */ return muTable[terrainType][((int)index)];
+/* */ }
+/* */
+/* 918 */ static boolean lateralForceTableInited = false;
+/* */
+/* */
+/* */ static final int torqueIncrements = 500;
+/* */
+/* */
+/* */ static final float maxRPM = 7000.0F;
+/* */
+/* */
+/* */ static final float minRPM = 1500.0F;
+/* */
+/* */
+/* */ static final float rpmInc = 500.0F;
+/* */
+/* */ static final int numRPMs = 12;
+/* */
+/* */ static float[] torqueTable;
+/* */
+/* */
+/* */ protected void initLateralForceTable()
+/* */ {
+/* 939 */ if (lateralForceTableInited) return;
+/* 940 */ lateralForceTableInited = true;
+/* */
+/* 942 */ muTable = new float[2]['ϩ'];
+/* */
+/* 944 */ for (int type = 0; type < 2; type++)
+/* */ {
+/* 946 */ for (int i = 0; i <= 1000; i++)
+/* */ {
+/* 948 */ float degrees = (float)Math.acos(i /
+/* 949 */ 1000.0F);
+/* 950 */ degrees = degrees * 360.0F / 6.2831855F;
+/* */
+/* 952 */ switch (type)
+/* */ {
+/* */
+/* */
+/* */
+/* */ case 0:
+/* 958 */ if (degrees > 45.0F) degrees = 45.0F;
+/* 959 */ muTable[type][i] =
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 965 */ (-0.084496F + 0.1241739F * degrees - 0.003676377F * (float)Math.pow(degrees, 2.0D) - 5.5137E-6F * (float)Math.pow(degrees, 3.0D) + 6.461E-7F * (float)Math.pow(
+/* 966 */ degrees, 4.0D));
+/* 967 */ break;
+/* */
+/* */
+/* */
+/* */ case 1:
+/* 972 */ muTable[type][i] =
+/* */
+/* 974 */ (0.055731F + 0.069871F * degrees - 0.002175398F * degrees * degrees);
+/* */ }
+/* */
+/* */
+/* */
+/* 979 */ if (muTable[type][i] < 0.0F) {
+/* 980 */ muTable[type][i] = 0.0F;
+/* */ }
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 993 */ static boolean torqueTableInited = false;
+/* */
+/* */ float getTorque(float rpm)
+/* */ {
+/* 997 */ if (rpm > 7000.0F)
+/* 998 */ rpm = 7000.0F;
+/* 999 */ if (rpm < 1500.0F) {
+/* 1000 */ rpm = 1500.0F;
+/* */ }
+/* 1002 */ int index = (int)(rpm / 7000.0F);
+/* 1003 */ return torqueTable[index];
+/* */ }
+/* */
+/* 1006 */ static float[] rawTorqueData = { 80.0F, 82.0F, 91.0F, 92.0F, 89.0F, 90.0F, 98.0F, 93.0F,
+/* 1007 */ 94.0F, 78.0F, 83.0F, 75.0F };
+/* */
+/* */ static final float torqueMax = 98.0F;
+/* */
+/* */ void initTorqueTable()
+/* */ {
+/* 1013 */ if (torqueTableInited) return;
+/* 1014 */ torqueTableInited = true;
+/* */
+/* 1016 */ torqueTable = new float['ǵ'];
+/* */
+/* 1018 */ for (int i = 0; i <= 500; i++)
+/* */ {
+/* 1020 */ float rpm = i / 500.0F * 7000.0F;
+/* 1021 */ if (rpm < 1500.0F) rpm = 1500.0F;
+/* 1022 */ int closest = 0;
+/* 1023 */ for (int j = 0; j < 12; j++)
+/* */ {
+/* 1025 */ float thisRpm = j * 500.0F + 1500.0F;
+/* 1026 */ if (thisRpm >= rpm)
+/* */ {
+/* 1028 */ closest = j;
+/* 1029 */ break;
+/* */ }
+/* */ }
+/* */
+/* 1033 */ if (closest == 0)
+/* */ {
+/* 1035 */ torqueTable[i] = (rawTorqueData[0] / 98.0F);
+/* */
+/* */ }
+/* */ else
+/* */ {
+/* 1040 */ Point2 low = new Point2();
+/* 1041 */ Point2 high = new Point2();
+/* 1042 */ Point2 result = new Point2();
+/* 1043 */ low.x = ((closest - 1) * 500.0F + 1500.0F);
+/* 1044 */ low.y = rawTorqueData[(closest - 1)];
+/* 1045 */ low.x += 500.0F;
+/* 1046 */ high.y = rawTorqueData[closest];
+/* 1047 */ float alpha = (rpm - low.x) / 500.0F;
+/* */
+/* */
+/* */
+/* 1051 */ result.x = (low.x * alpha + high.x * (1.0F - alpha));
+/* 1052 */ result.y = (low.y * alpha + high.y * (1.0F - alpha));
+/* */
+/* 1054 */ torqueTable[i] = (result.y / 98.0F);
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* */
+/* */ private void initRPMTable()
+/* */ {
+/* 1062 */ this.minRPMs = new float[6];
+/* */
+/* 1064 */ float[] maxVel = new float[5];
+/* 1065 */ for (int x = 0; x < 5; x++)
+/* */ {
+/* 1067 */ maxVel[x] =
+/* */
+/* 1069 */ (this.vehicle.rpmTorquePeak * 3.1415927F * this.vehicle.wheelDiameter / (60.0F * this.vehicle.rearEndRatio * getGearRatio(x)));
+/* */ }
+/* */
+/* 1072 */ this.minRPMs[0] = 0.0F;
+/* 1073 */ for (int x = 1; x <= 5; x++)
+/* */ {
+/* 1075 */ this.minRPMs[x] =
+/* */
+/* 1077 */ (60.0F * maxVel[(x - 1)] * this.vehicle.rearEndRatio * getGearRatio(x) / (3.1415927F * this.vehicle.wheelDiameter));
+/* */ }
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\VehicleDriver.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file