Cesium--获取当前相机中心与地面的射线焦点
创始人
2025-01-09 12:36:26
0

本文记录获取当前相机中心与地面的射线焦点的方法,可用于视角缩放过程中,控制视角自动平滑切换到二维等场景:

方法一定是视角中心能与地面有交集,如果对着地平线或对着天空肯定是没效果的。直接放代码:

//调整相机到正北方向 上帝视角 const limitViewerController=(viewer)=>{ 	try{ 		viewer.scene.screenSpaceCameraController.enableTilt = false; //禁止中键旋转视角 		// 将相机朝向正北方向(即Z轴指向正北,Y轴指向正东) 		var heading = Cesium.Math.toRadians(0.0); // 正北方向为90度 		var pitch = Cesium.Math.toRadians(0.0); // 保持平面视角 		var roll = 0.0; // 无滚动 		var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); 		let camera_position = viewer.camera.position.clone(); 		let cameraHeight = viewer.camera.positionCartographic.height;  		let camera = viewer.scene.camera; 		const rayget = new Cesium.Ray(camera.position, camera.direction) 		 		//射线监测 不到目标时 无法设置视角 		const rayintersection = Cesium.IntersectionTests.rayEllipsoid(rayget, Cesium.Ellipsoid.WGS84); 		if(rayintersection){ 			const raypoint = Cesium.Ray.getPoint(rayget, rayintersection.start); 			 			// 获取当前使用的地球椭球体 			var ellipsoid = viewer.scene.globe.ellipsoid; 			// 将Cartesian3转换为经纬度 			var raycartographic = ellipsoid.cartesianToCartographic(raypoint); 			 var cameracartographic = ellipsoid.cartesianToCartographic(camera_position); 			  			// 获取经度、纬度和高度 			var raylongitude = Cesium.Math.toDegrees(raycartographic.longitude); 			var raylatitude = Cesium.Math.toDegrees(raycartographic.latitude); 			var rayheight = cameracartographic.height; 			 			const destinationPostion = Cesium.Cartesian3.fromDegrees(raylongitude, raylatitude, rayheight+100000); 			 			viewer.camera.flyTo({ 			    destination : destinationPostion, 				duration: 1.5, 			    orientation : { 			        heading : 6.283185307179586, 			        pitch : -1.5707963267948966, 			        roll : 0.0 			    } 			}); 		} 		 		 		//调整也可以通过TWEEN.js 实现过渡动画 		//import * as TWEEN from '@tweenjs/tween.js' 		// const coords = {x: viewer.camera.heading, y: viewer.camera.pitch,z:viewer.camera.roll} // Start at (0, 0) 		// const tween = new TWEEN.Tween(coords, false) // Create a new tween that modifies 'coords'. 		// .to({x: 6.283185307179586, y: -1.5707963267948966, z:0}, 1000)  		// .easing(TWEEN.Easing.Quadratic.InOut) 		// .onUpdate((object) => { 		// 	viewer.camera.setView({ 		// 		//destination : new Cesium.Cartesian3(raypoint.x, raypoint.y, camera_position.z), 		// 	    orientation: { 		// 			heading: object.x, // 方向的朝向,以弧度为单位 		// 			pitch: object.y, // 视角的高度,以弧度为单位 		// 	        roll: object.z // 绕着圆周运动的角度,一般设置为0 		// 	    } 		// 	}); 		// 	// viewer.scene.camera.setView({ 		// 	// 	 destination : new Cesium.Cartesian3(camera_position.x, camera_position.y, camera_position.z), 		// 	//     orientation: { 		// 	//         headingPitchRoll: new Cesium.HeadingPitchRoll(object.x, object.y, object.z) 		// 	//     } 		// 	// }); 		// }) 		// .start() // Start the tween immediately. 		// function animate() { 		// 	tween.update() 		// 	requestAnimationFrame(animate) 		// } 		// requestAnimationFrame(animate) 		 	 	}catch(err){ 		console.log(err); 	} }

 

相关内容

热门资讯

透视美元局!wepoker底牌... 透视美元局!wepoker底牌透视脚本app,红龙poker透视,必赢教程(有挂详情)1、wepok...
透视脚本!aapoker透视怎... 透视脚本!aapoker透视怎么用,hhpoker透视脚本视频,2025新版教程(有挂揭秘)1、下载...
透视好牌!wepoker辅助下... 透视好牌!wepoker辅助下载,红龙poker作弊指令,教你攻略(有挂教程)1、不需要AI权限,帮...
透视免费!wpk辅助工具,we... 透视免费!wpk辅助工具,wepoker免费透视脚本,系统教程(有挂教程);透视免费!wpk辅助工具...
透视透视挂!德普之星透视辅助软... 透视透视挂!德普之星透视辅助软件,德普之星透视辅助软件下载,我来教教你(有挂介绍)1、许多玩家不知道...
透视能赢!wpk透视辅助方法,... 透视能赢!wpk透视辅助方法,智星菠萝辅助怎么买,线上教程(有挂攻略);1、这是跨平台的智星菠萝辅助...
透视挂透视!wepoker透视... 透视挂透视!wepoker透视脚本苹果,德普之星辅助器,扑克教程(有挂细节)透视挂透视!wepoke...
透视挂!aapoker有脚本吗... 透视挂!aapoker有脚本吗,wpk有脚本吗,wepoke教程(有挂方法)1、每一步都需要思考,不...
透视黑科技!红龙poker透视... 透视黑科技!红龙poker透视工具,德普之星透视辅助软件下载,普及教程(有挂教程)1、让任何用户在无...
透视辅助!智星菠萝辅助怎么买,... 透视辅助!智星菠萝辅助怎么买,aapoker透视插件,可靠教程(有挂辅助)1、该软件可以轻松地帮助玩...