@geoblocks/cesium-first-person-mode
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -0,1 +1,2 @@ | ||
import {ScreenSpaceEventType, Math as CesiumMath} from 'cesium'; | ||
@@ -5,10 +6,16 @@ export default class FirstPersonCameraMode { | ||
/** | ||
* @param {import('cesium').Scene} scene | ||
* @param {import('cesium').Viewer} viewer | ||
* @param {number} [zoomFactor=Math.PI / 36] | ||
* @param {number} [movementFactor=0.003] | ||
*/ | ||
constructor(scene, movementFactor = 0.003) { | ||
this.scene_ = scene; | ||
constructor(viewer, zoomFactor = Math.PI / 36, movementFactor = 0.003) { | ||
this.viewer_ = viewer; | ||
this.scene_ = viewer.scene; | ||
this.movementFactor_ = movementFactor; | ||
this.zoomFactor_ = zoomFactor; | ||
this.originalFov_; | ||
this.movementX_ = 0; | ||
@@ -20,12 +27,19 @@ | ||
const onPostRenderCallback = this.onPostRender_.bind(this); | ||
const onMouseWheelCallback = this.onMouseWheel_.bind(this); | ||
document.addEventListener('pointerlockchange', event => { | ||
this.scene_.screenSpaceCameraController.enableInputs = !this.active; | ||
const frustum = /** @type {import('cesium').PerspectiveFrustum} */ (this.scene_.camera.frustum); | ||
if (this.active) { | ||
// enter | ||
this.originalFov_ = frustum.fov; | ||
document.addEventListener('mousemove', onMouseMoveCallback); | ||
this.scene_.postRender.addEventListener(onPostRenderCallback); | ||
this.viewer_.screenSpaceEventHandler.setInputAction(onMouseWheelCallback, ScreenSpaceEventType.WHEEL); | ||
} else { | ||
// leave | ||
frustum.fov = this.originalFov_; | ||
document.removeEventListener('mousemove', onMouseMoveCallback); | ||
this.scene_.postRender.removeEventListener(onPostRenderCallback); | ||
this.viewer_.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.WHEEL); | ||
} | ||
@@ -50,2 +64,11 @@ }); | ||
/** | ||
* @param {number} movement | ||
*/ | ||
onMouseWheel_(movement) { | ||
const frustum = /** @type {import('cesium').PerspectiveFrustum} */ (this.scene_.camera.frustum); | ||
const fov = frustum.fov + (movement > 0 ? -this.zoomFactor_ : this.zoomFactor_); | ||
frustum.fov = CesiumMath.clamp(fov, CesiumMath.toRadians(1), CesiumMath.toRadians(60)); | ||
} | ||
/** | ||
* @param {MouseEvent} event | ||
@@ -52,0 +75,0 @@ */ |
{ | ||
"name": "@geoblocks/cesium-first-person-mode", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "BSD-3-Clause", | ||
"repository": "github:geoblocks/cesium-helpers", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/geoblocks/cesium-helpers/", | ||
"directory": "packages/FirstPersonCameraMode" | ||
}, | ||
"main": "FirstPersonCameraMode.js", | ||
@@ -11,3 +15,6 @@ "module": "FirstPersonCameraMode.js", | ||
}, | ||
"gitHead": "0ee87e1503e54bfb4867b26527939cd18b2d3e0b" | ||
"peerDependencies": { | ||
"cesium": "1.x" | ||
}, | ||
"gitHead": "c08927b0e94ebe8dc39c1e2cf685e7d481ebdfb8" | ||
} |
@@ -1,2 +0,2 @@ | ||
# FirstPerson camera mode for Cesium | ||
# FirstPerson camera mode for CesiumJS | ||
@@ -3,0 +3,0 @@ ## Installation |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
5461
82
0
1