Cesium模型隨視角轉動(僅沿Z軸轉

鼠標移動事件git

//鼠標移動事件——註記轉動
 viewer.screenSpaceEventHandler.setInputAction(function leftClick(movement) { //var pickedFeature = viewer.scene.pick(movement.endPosition);
    //var entity = viewer.entities.getById(pickedFeature.id._id);
    /*var Position=movement.endPosition; var ellipsoid = viewer.scene.globe.ellipsoid; var cartesian = viewer.camera.pickEllipsoid(movement.endPosition, ellipsoid); //將笛卡爾座標轉換爲地理座標 var cartographic = ellipsoid.cartesianToCartographic(cartesian); //將弧度轉爲度的十進制度表示 var longitudeString = Cesium.Math.toDegrees(cartographic.longitude); var latitudeString = Cesium.Math.toDegrees(cartographic.latitude);*/
    if (tilesetArray.length>0){ var heading = Cesium.Math.toDegrees(viewer.camera.heading).toFixed(2);//當前方向 由北向東旋轉的角度
       // var pitch = Cesium.Math.toDegrees(viewer.camera.pitch).toFixed(2);//方向和水平平面的夾角, Pitch爲正 表示方向向量指向水平平面上方,反之表示方向向量指向平面下方
       // var roll = Cesium.Math.toDegrees(viewer.camera.roll).toFixed(2);//方向向量以正東方向爲軸的旋轉角度
        for(var i=0;i<tilesetArray.length;i++){ var array=tilesetArray[i]; for(var j=0;j<array.length;j++){ update3dtilesMaxtrix(0,0,-heading,array[j]); } } }; if (tilesetArray1_STBHHX.length>0){ var heading = Cesium.Math.toDegrees(viewer.camera.heading).toFixed(2);//當前方向 由北向東旋轉的角度
       // var pitch = Cesium.Math.toDegrees(viewer.camera.pitch).toFixed(2);//方向和水平平面的夾角, Pitch爲正 表示方向向量指向水平平面上方,反之表示方向向量指向平面下方
       // var roll = Cesium.Math.toDegrees(viewer.camera.roll).toFixed(2);//方向向量以正東方向爲軸的旋轉角度
        for(var i=0;i<tilesetArray1_STBHHX.length;i++){ var array=tilesetArray1_STBHHX[i]; for(var j=0;j<array.length;j++){ update3dtilesMaxtrix(0,0,-heading,array[j]); } } } }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); function update3dtilesMaxtrix(rx,ry,rz,tileset) {     //旋轉
        var mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(rx));     var my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(ry));     var mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(rz));     var rotationX = Cesium.Matrix4.fromRotationTranslation(mx);     var rotationY = Cesium.Matrix4.fromRotationTranslation(my);     var rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);     //平移
        //var position = Cesium.Cartesian3.fromDegrees(params.tx, params.ty, params.tz);
        //var m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
        var m = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);     //旋轉、平移矩陣相乘
     Cesium.Matrix4.multiply(m, rotationX, m);     Cesium.Matrix4.multiply(m, rotationY, m);     Cesium.Matrix4.multiply(m, rotationZ, m);     //賦值給tileset
        tileset._root.transform = m; };
相關文章
相關標籤/搜索