Cesium绕点飞行

Cesium绕点飞行

上代码, 简单点

	enableRotation(position, hpr) {
		// this.stopRotation()
		hpr = hpr || {}
		let heading = hpr.heading || Cesium.Math.toDegrees(this.viewer.baseViewer.camera.heading)
		const pitch = hpr.pitch || Cesium.Math.toDegrees(this.viewer.baseViewer.camera.pitch)
		const range = hpr.range || CesiumUtils.distance(this.viewer.baseViewer.camera.position, position)
		let pre = Date.now()
		let now
		let cur
		this._rotationRender = () => {
			cur = Date.now()
			now = cur - pre
			pre = cur
			heading = (heading - now / 1000 * this.rotationSpeed) % 360
			// 相机移动到指定位置
			this.viewer.lookAt(
					position,
					{
						heading, // 平视角
						pitch, // 倾斜角
						range // 距离中心点距离
					}
			)
		}
		// 这里需要你们自己监听渲染器事件
		this.viewer.eventManager.addEventListener(EventConstant.RENDER, this._rotationRender)
	}

我们用时间控制旋转角度, 这样会让旋转看上去更匀速,

	lookAt(position, headingPitchRange) {
		if (!position) return
		if (position.alt) {
			position = CesiumUtils.transformWGS84ToCartesian(position)
		} else if (position.x) {
			position = new Cesium.Cartesian3(position.x, position.y, position.z)
		} else {
			console.warn('错误的参数!')
			return
		}
		this.baseViewer.camera.lookAt(
				position,
				new Cesium.HeadingPitchRange(Cesium.Math.toRadians(headingPitchRange.heading),
						Cesium.Math.toRadians(headingPitchRange.pitch),
						headingPitchRange.range
				)
		)
	}

无非就是利用lookAt 更改偏航角, 你学废了吗?

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值