Spaces:
Running
Running
Update orbit-camera.js
Browse files- orbit-camera.js +26 -10
orbit-camera.js
CHANGED
|
@@ -56,11 +56,8 @@ Object.defineProperty(OrbitCamera.prototype, 'orthoHeight', {
|
|
| 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,7 +67,6 @@ Object.defineProperty(OrbitCamera.prototype, 'pitch', {
|
|
| 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,7 +77,6 @@ Object.defineProperty(OrbitCamera.prototype, 'yaw', {
|
|
| 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,8 +403,19 @@ OrbitCameraInputMouse.prototype.onMouseUp = function (event) {
|
|
| 408 |
};
|
| 409 |
OrbitCameraInputMouse.prototype.onMouseMove = function (event) {
|
| 410 |
if (this.lookButtonDown) {
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
} else if (this.panButtonDown) {
|
| 414 |
this.pan(new pc.Vec2(event.x, event.y));
|
| 415 |
}
|
|
@@ -509,8 +515,18 @@ OrbitCameraInputTouch.prototype.onTouchMove = function (event) {
|
|
| 509 |
var touches = event.touches;
|
| 510 |
if (touches.length === 1) {
|
| 511 |
var touch = touches[0];
|
| 512 |
-
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
this.lastTouchPoint.set(touch.x, touch.y);
|
| 515 |
} else if (touches.length === 2) {
|
| 516 |
var currentPinchDistance = this.getPinchDistance(touches[0], touches[1]);
|
|
@@ -521,4 +537,4 @@ OrbitCameraInputTouch.prototype.onTouchMove = function (event) {
|
|
| 521 |
this.pan(pinchMidPoint);
|
| 522 |
this.lastPinchMidPoint.copy(pinchMidPoint);
|
| 523 |
}
|
| 524 |
-
};
|
|
|
|
| 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 |
}
|
| 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 |
}
|
| 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 |
};
|
| 404 |
OrbitCameraInputMouse.prototype.onMouseMove = function (event) {
|
| 405 |
if (this.lookButtonDown) {
|
| 406 |
+
// Compute proposed new pitch and yaw
|
| 407 |
+
var sens = this.orbitSensitivity;
|
| 408 |
+
var currentPitch = this.orbitCamera.pitch;
|
| 409 |
+
var proposedPitch = currentPitch - event.dy * sens;
|
| 410 |
+
// If we're already at the minimum pitch and trying to go further up, ignore vertical
|
| 411 |
+
if (proposedPitch < this.orbitCamera.pitchAngleMin) {
|
| 412 |
+
proposedPitch = currentPitch;
|
| 413 |
+
}
|
| 414 |
+
this.orbitCamera.pitch = proposedPitch;
|
| 415 |
+
// Always allow horizontal yaw
|
| 416 |
+
var currentYaw = this.orbitCamera.yaw;
|
| 417 |
+
var proposedYaw = currentYaw - event.dx * sens;
|
| 418 |
+
this.orbitCamera.yaw = proposedYaw;
|
| 419 |
} else if (this.panButtonDown) {
|
| 420 |
this.pan(new pc.Vec2(event.x, event.y));
|
| 421 |
}
|
|
|
|
| 515 |
var touches = event.touches;
|
| 516 |
if (touches.length === 1) {
|
| 517 |
var touch = touches[0];
|
| 518 |
+
var sens = this.orbitSensitivity;
|
| 519 |
+
var currentPitch = this.orbitCamera.pitch;
|
| 520 |
+
var delta = (touch.y - this.lastTouchPoint.y) * sens;
|
| 521 |
+
var proposedPitch = currentPitch - delta;
|
| 522 |
+
// Suppress upward (negative) pitch when at minimum
|
| 523 |
+
if (proposedPitch < this.orbitCamera.pitchAngleMin) {
|
| 524 |
+
proposedPitch = currentPitch;
|
| 525 |
+
}
|
| 526 |
+
this.orbitCamera.pitch = proposedPitch;
|
| 527 |
+
var currentYaw = this.orbitCamera.yaw;
|
| 528 |
+
var yawDelta = (touch.x - this.lastTouchPoint.x) * sens;
|
| 529 |
+
this.orbitCamera.yaw = currentYaw - yawDelta;
|
| 530 |
this.lastTouchPoint.set(touch.x, touch.y);
|
| 531 |
} else if (touches.length === 2) {
|
| 532 |
var currentPinchDistance = this.getPinchDistance(touches[0], touches[1]);
|
|
|
|
| 537 |
this.pan(pinchMidPoint);
|
| 538 |
this.lastPinchMidPoint.copy(pinchMidPoint);
|
| 539 |
}
|
| 540 |
+
};
|