belinghy commited on
Commit
b4e4b93
1 Parent(s): c89fc88

make camera control more natural

Browse files
Files changed (1) hide show
  1. static/demo.min.js +13 -13
static/demo.min.js CHANGED
@@ -111,6 +111,9 @@
111
  let rollX = this.gamepads[pad].axes[2];
112
  let rollY = this.gamepads[pad].axes[3];
113
 
 
 
 
114
  if (panX < -this.SPACEMOUSE_THRESHOLD ||
115
  panX > this.SPACEMOUSE_THRESHOLD) {
116
  this.lStick.x = panX;
@@ -418,10 +421,6 @@
418
  let endTime = performance.now();
419
  let elapsedTime = endTime - startTime;
420
 
421
- // if (gamepad.connected) {
422
- // gamepad.update();
423
- // }
424
-
425
  if (!guiParams.Pause && elapsedTime > fpsInterval) {
426
  startTime = endTime - (elapsedTime % fpsInterval);
427
 
@@ -454,11 +453,16 @@
454
  taskVector[1] = (b * targetDelta[0] + d * targetDelta[1]) * M2F;
455
  } else if (guiParams.Task == "joystick") {
456
 
457
- if (gamepad.connected) {
458
- gamepad.update();
459
- heading = Math.atan2(gamepad.lStick.x, gamepad.lStick.y);
460
- speed = Math.min(Math.max(gamepad.lStick.length(), 0.2), 0.8);
461
- }
 
 
 
 
 
462
 
463
  target.position.x = rootXYZ[0] + (2 * speed + 0.6) * Math.cos(heading);
464
  target.position.z = rootXYZ[2] + (2 * speed + 0.6) * Math.sin(heading);
@@ -467,10 +471,6 @@
467
  taskVector[0] = speed * Math.cos(targetAngle);
468
  taskVector[1] = speed * Math.sin(targetAngle);
469
 
470
- let dz = camera.position.z - controls.target.z;
471
- let dx = camera.position.x - controls.target.x;
472
- let cameraAngle = Math.atan2(dz, dx) + gamepad.rStick.x * 10 / 360 * Math.PI;
473
-
474
  let cx = rootXYZ[0] + Math.cos(cameraAngle) * 30;
475
  let cz = rootXYZ[2] + Math.sin(cameraAngle) * 30;
476
  camera.position.set(cx, 10, cz);
 
111
  let rollX = this.gamepads[pad].axes[2];
112
  let rollY = this.gamepads[pad].axes[3];
113
 
114
+ let buttons = this.gamepads[pad].buttons;
115
+ this.rStick.z = buttons[11].pressed ? 1 : 0;
116
+
117
  if (panX < -this.SPACEMOUSE_THRESHOLD ||
118
  panX > this.SPACEMOUSE_THRESHOLD) {
119
  this.lStick.x = panX;
 
421
  let endTime = performance.now();
422
  let elapsedTime = endTime - startTime;
423
 
 
 
 
 
424
  if (!guiParams.Pause && elapsedTime > fpsInterval) {
425
  startTime = endTime - (elapsedTime % fpsInterval);
426
 
 
453
  taskVector[1] = (b * targetDelta[0] + d * targetDelta[1]) * M2F;
454
  } else if (guiParams.Task == "joystick") {
455
 
456
+ let dz = camera.position.z - controls.target.z;
457
+ let dx = camera.position.x - controls.target.x;
458
+ let cameraAngle = Math.atan2(dz, dx);
459
+
460
+ if (gamepad.connected) { gamepad.update(); }
461
+
462
+ heading = Math.atan2(gamepad.lStick.x, gamepad.lStick.y) + (cameraAngle - Math.PI);
463
+ speed = Math.min(Math.max(gamepad.lStick.length(), 0.2), 0.8);
464
+ cameraAngle += gamepad.rStick.x * 5 / 360 * Math.PI;
465
+ if (gamepad.rStick.z == 1) { cameraAngle = Math.PI; }
466
 
467
  target.position.x = rootXYZ[0] + (2 * speed + 0.6) * Math.cos(heading);
468
  target.position.z = rootXYZ[2] + (2 * speed + 0.6) * Math.sin(heading);
 
471
  taskVector[0] = speed * Math.cos(targetAngle);
472
  taskVector[1] = speed * Math.sin(targetAngle);
473
 
 
 
 
 
474
  let cx = rootXYZ[0] + Math.cos(cameraAngle) * 30;
475
  let cz = rootXYZ[2] + Math.sin(cameraAngle) * 30;
476
  camera.position.set(cx, 10, cz);