MikaFil commited on
Commit
86b7939
·
verified ·
1 Parent(s): 742d619

Update orbit-camera.js

Browse files
Files changed (1) hide show
  1. orbit-camera.js +18 -66
orbit-camera.js CHANGED
@@ -56,8 +56,11 @@ Object.defineProperty(OrbitCamera.prototype, 'orthoHeight', {
56
  }
57
  });
58
 
 
59
  // Property to get and set the pitch (in degrees) of the camera around the pivot.
60
  // The pitch value is clamped between pitchAngleMin and pitchAngleMax.
 
 
61
  Object.defineProperty(OrbitCamera.prototype, 'pitch', {
62
  get: function () {
63
  return this._targetPitch;
@@ -67,6 +70,7 @@ Object.defineProperty(OrbitCamera.prototype, 'pitch', {
67
  }
68
  });
69
 
 
70
  // Property to get and set the yaw (in degrees) of the camera around the pivot.
71
  Object.defineProperty(OrbitCamera.prototype, 'yaw', {
72
  get: function () {
@@ -77,6 +81,7 @@ Object.defineProperty(OrbitCamera.prototype, 'yaw', {
77
  }
78
  });
79
 
 
80
  // Property to get and set the world position of the pivot point that the camera orbits around.
81
  Object.defineProperty(OrbitCamera.prototype, 'pivotPoint', {
82
  get: function () {
@@ -403,38 +408,8 @@ OrbitCameraInputMouse.prototype.onMouseUp = function (event) {
403
  };
404
  OrbitCameraInputMouse.prototype.onMouseMove = function (event) {
405
  if (this.lookButtonDown) {
406
- var sens = this.orbitSensitivity;
407
- var currentPitch = this.orbitCamera.pitch;
408
- var currentYaw = this.orbitCamera.yaw;
409
- var pitchMin = this.orbitCamera.pitchAngleMin;
410
-
411
- // compute proposed new pitch
412
- var proposedPitch = currentPitch - event.dy * sens;
413
- var atMinPitch = currentPitch <= pitchMin + 1e-4;
414
- var movingUpward = event.dy < 0; // drag up → event.dy negative
415
-
416
- console.log(
417
- "[Mouse] currentPitch=", currentPitch.toFixed(2),
418
- "proposedPitch=", proposedPitch.toFixed(2),
419
- "pitchMin=", pitchMin,
420
- "atMinPitch=", atMinPitch,
421
- "movingUpward=", movingUpward
422
- );
423
-
424
- if (atMinPitch && movingUpward) {
425
- // suppress only upward pitch
426
- proposedPitch = currentPitch;
427
- console.log("[Mouse] Upward pitch suppressed");
428
- } else if (proposedPitch < pitchMin && movingUpward) {
429
- // clamp if slightly past
430
- proposedPitch = pitchMin;
431
- console.log("[Mouse] Pitch clamped to min");
432
- }
433
-
434
- // apply pitch and always apply yaw
435
- this.orbitCamera.pitch = proposedPitch;
436
- this.orbitCamera.yaw = currentYaw - event.dx * sens;
437
-
438
  } else if (this.panButtonDown) {
439
  this.pan(new pc.Vec2(event.x, event.y));
440
  }
@@ -530,43 +505,20 @@ OrbitCameraInputTouch.prototype.pan = function (midPoint) {
530
  };
531
  OrbitCameraInputTouch.pinchMidPoint = new pc.Vec2();
532
  OrbitCameraInputTouch.prototype.onTouchMove = function (event) {
 
533
  var touches = event.touches;
534
  if (touches.length === 1) {
535
  var touch = touches[0];
536
- var sens = this.orbitSensitivity;
537
- var currentPitch = this.orbitCamera.pitch;
538
- var currentYaw = this.orbitCamera.yaw;
539
- var pitchMin = this.orbitCamera.pitchAngleMin;
540
-
541
- var deltaY = touch.y - this.lastTouchPoint.y;
542
- var proposedPitch = currentPitch - deltaY * sens;
543
- var atMinPitch = currentPitch <= pitchMin + 1e-4;
544
- var movingUpward = deltaY > 0; // moving finger up increases touch.y, so deltaY positive
545
-
546
- console.log(
547
- "[Touch] currentPitch=", currentPitch.toFixed(2),
548
- "proposedPitch=", proposedPitch.toFixed(2),
549
- "pitchMin=", pitchMin,
550
- "atMinPitch=", atMinPitch,
551
- "movingUpward=", movingUpward
552
- );
553
-
554
- if (atMinPitch && movingUpward) {
555
- proposedPitch = currentPitch;
556
- console.log("[Touch] Upward pitch suppressed");
557
- } else if (proposedPitch < pitchMin && movingUpward) {
558
- proposedPitch = pitchMin;
559
- console.log("[Touch] Pitch clamped to min");
560
- }
561
-
562
- this.orbitCamera.pitch = proposedPitch;
563
- // always allow horizontal
564
- var deltaX = touch.x - this.lastTouchPoint.x;
565
- this.orbitCamera.yaw = currentYaw - deltaX * sens;
566
-
567
  this.lastTouchPoint.set(touch.x, touch.y);
568
-
569
  } else if (touches.length === 2) {
570
- // ... existing pinch/zoom & pan logic unchanged ...
 
 
 
 
 
 
571
  }
572
- };
 
56
  }
57
  });
58
 
59
+
60
  // Property to get and set the pitch (in degrees) of the camera around the pivot.
61
  // The pitch value is clamped between pitchAngleMin and pitchAngleMax.
62
+ // With your JSON (minAngle: -90, maxAngle: 0), the allowed pitch will be from -90 (overhead)
63
+ // to 0 (horizontal).
64
  Object.defineProperty(OrbitCamera.prototype, 'pitch', {
65
  get: function () {
66
  return this._targetPitch;
 
70
  }
71
  });
72
 
73
+
74
  // Property to get and set the yaw (in degrees) of the camera around the pivot.
75
  Object.defineProperty(OrbitCamera.prototype, 'yaw', {
76
  get: function () {
 
81
  }
82
  });
83
 
84
+
85
  // Property to get and set the world position of the pivot point that the camera orbits around.
86
  Object.defineProperty(OrbitCamera.prototype, 'pivotPoint', {
87
  get: function () {
 
408
  };
409
  OrbitCameraInputMouse.prototype.onMouseMove = function (event) {
410
  if (this.lookButtonDown) {
411
+ this.orbitCamera.pitch -= event.dy * this.orbitSensitivity;
412
+ this.orbitCamera.yaw -= event.dx * this.orbitSensitivity;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  } else if (this.panButtonDown) {
414
  this.pan(new pc.Vec2(event.x, event.y));
415
  }
 
505
  };
506
  OrbitCameraInputTouch.pinchMidPoint = new pc.Vec2();
507
  OrbitCameraInputTouch.prototype.onTouchMove = function (event) {
508
+ var pinchMidPoint = OrbitCameraInputTouch.pinchMidPoint;
509
  var touches = event.touches;
510
  if (touches.length === 1) {
511
  var touch = touches[0];
512
+ this.orbitCamera.pitch -= (touch.y - this.lastTouchPoint.y) * this.orbitSensitivity;
513
+ this.orbitCamera.yaw -= (touch.x - this.lastTouchPoint.x) * this.orbitSensitivity;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
  this.lastTouchPoint.set(touch.x, touch.y);
 
515
  } else if (touches.length === 2) {
516
+ var currentPinchDistance = this.getPinchDistance(touches[0], touches[1]);
517
+ var diffInPinchDistance = currentPinchDistance - this.lastPinchDistance;
518
+ this.lastPinchDistance = currentPinchDistance;
519
+ this.orbitCamera.distance -= (diffInPinchDistance * this.distanceSensitivity * 0.1) * (this.orbitCamera.distance * 0.1);
520
+ this.calcMidPoint(touches[0], touches[1], pinchMidPoint);
521
+ this.pan(pinchMidPoint);
522
+ this.lastPinchMidPoint.copy(pinchMidPoint);
523
  }
524
+ };