Cesium模型随视角转动(仅沿Z轴转

鼠标移动事件

  //鼠标移动事件——注记转动
 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;
    };

 

posted @ 2019-11-25 20:53  敏敏酱  阅读(3737)  评论(1编辑  收藏  举报