@ericchen1990/pano-view 3.6.2 → 3.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +42 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +42 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3723,12 +3723,18 @@ var PointerDragAnchor = class {
|
|
|
3723
3723
|
this.projection = projection;
|
|
3724
3724
|
this.local = new Vector3();
|
|
3725
3725
|
this.rotation = new Euler2(0, 0, 0, "YXZ");
|
|
3726
|
-
|
|
3726
|
+
const startRay = this.ray(start).clone();
|
|
3727
|
+
this.baseAzimuth = Math.atan2(startRay.x, -startRay.z);
|
|
3728
|
+
this.baseElevation = Math.atan2(startRay.y, -startRay.z);
|
|
3729
|
+
this.anchor = startRay.clone().applyEuler(this.rotation.set(
|
|
3727
3730
|
MathUtils2.degToRad(origin.pitch),
|
|
3728
3731
|
MathUtils2.degToRad(-origin.yaw),
|
|
3729
3732
|
0,
|
|
3730
3733
|
"YXZ"
|
|
3731
3734
|
));
|
|
3735
|
+
const originPitch = MathUtils2.degToRad(origin.pitch);
|
|
3736
|
+
const roots = this.pitchRoots(startRay, originPitch);
|
|
3737
|
+
this.useSupplementary = Math.abs(roots.supplementary - originPitch) + 1e-6 < Math.abs(roots.principal - originPitch);
|
|
3732
3738
|
}
|
|
3733
3739
|
ray(point) {
|
|
3734
3740
|
return this.local.set(
|
|
@@ -3737,6 +3743,21 @@ var PointerDragAnchor = class {
|
|
|
3737
3743
|
0.5
|
|
3738
3744
|
).applyMatrix4(this.projection.projectionMatrixInverse).normalize();
|
|
3739
3745
|
}
|
|
3746
|
+
/** Pitch roots of the level-camera constraint. The supplementary root is unwrapped toward the press. */
|
|
3747
|
+
pitchRoots(ray, originPitch) {
|
|
3748
|
+
const latitude = Math.asin(MathUtils2.clamp(
|
|
3749
|
+
this.anchor.y / Math.max(Math.hypot(ray.y, ray.z), 1e-12),
|
|
3750
|
+
-1,
|
|
3751
|
+
1
|
|
3752
|
+
));
|
|
3753
|
+
const offset = Math.atan2(ray.y, -ray.z);
|
|
3754
|
+
const principal = latitude - offset;
|
|
3755
|
+
const turned = Math.PI - latitude - offset;
|
|
3756
|
+
return {
|
|
3757
|
+
principal,
|
|
3758
|
+
supplementary: originPitch + Math.atan2(Math.sin(turned - originPitch), Math.cos(turned - originPitch))
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3740
3761
|
solve(point, speed = DEFAULT_POINTER_DRAG_SPEED, invert = false) {
|
|
3741
3762
|
const multiplier = (Number.isFinite(speed) && speed >= 0 ? speed : DEFAULT_POINTER_DRAG_SPEED) / DEFAULT_POINTER_DRAG_SPEED * (invert ? -1 : 1);
|
|
3742
3763
|
if (multiplier === 0) return { yaw: 0, pitch: 0 };
|
|
@@ -3744,22 +3765,27 @@ var PointerDragAnchor = class {
|
|
|
3744
3765
|
x: this.start.x + (point.x - this.start.x) * multiplier,
|
|
3745
3766
|
y: this.start.y + (point.y - this.start.y) * multiplier
|
|
3746
3767
|
});
|
|
3747
|
-
const latitude = Math.asin(MathUtils2.clamp(this.anchor.y / Math.max(Math.hypot(ray.y, ray.z), 1e-12), -1, 1));
|
|
3748
|
-
const offset = Math.atan2(ray.y, -ray.z);
|
|
3749
3768
|
const originPitch = MathUtils2.degToRad(this.origin.pitch);
|
|
3750
|
-
const
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3769
|
+
const roots = this.pitchRoots(ray, originPitch);
|
|
3770
|
+
const exactPitch = MathUtils2.clamp(
|
|
3771
|
+
this.useSupplementary ? roots.supplementary : roots.principal,
|
|
3772
|
+
-Math.PI / 2,
|
|
3773
|
+
Math.PI / 2
|
|
3774
|
+
);
|
|
3775
|
+
const stablePitch = originPitch - (Math.atan2(ray.y, -ray.z) - this.baseElevation);
|
|
3776
|
+
const fromPole = Math.asin(Math.min(1, Math.hypot(this.anchor.x, this.anchor.z)));
|
|
3777
|
+
const pointerLock = MathUtils2.smoothstep(fromPole, MathUtils2.degToRad(8), MathUtils2.degToRad(18));
|
|
3778
|
+
const pitchTurn = Math.atan2(Math.sin(exactPitch - stablePitch), Math.cos(exactPitch - stablePitch));
|
|
3779
|
+
const pitch = MathUtils2.clamp(
|
|
3780
|
+
pointerLock >= 1 ? exactPitch : stablePitch + pointerLock * pitchTurn,
|
|
3781
|
+
-Math.PI / 2,
|
|
3782
|
+
Math.PI / 2
|
|
3783
|
+
);
|
|
3784
|
+
const pitchedZ = Math.sin(exactPitch) * ray.y + Math.cos(exactPitch) * ray.z;
|
|
3785
|
+
const exactYaw = Math.atan2(this.anchor.x, -this.anchor.z) - Math.atan2(ray.x, -pitchedZ);
|
|
3786
|
+
const stableYaw = MathUtils2.degToRad(this.origin.yaw) + Math.atan2(ray.x, -ray.z) - this.baseAzimuth;
|
|
3787
|
+
const yawTurn = Math.atan2(Math.sin(exactYaw - stableYaw), Math.cos(exactYaw - stableYaw));
|
|
3788
|
+
const yaw = MathUtils2.radToDeg(stableYaw + pointerLock * yawTurn);
|
|
3763
3789
|
return { yaw: normalizeViewYaw(yaw - this.origin.yaw), pitch: MathUtils2.radToDeg(pitch) - this.origin.pitch };
|
|
3764
3790
|
}
|
|
3765
3791
|
};
|