cesium 像素代表的距离(实时)

        cesium中有时会用到每个像素代表的米数量这个计算,在metersPerPixel.glsl文件中,例如:当计算裁切时,在裁切面的裁切边缘上想要看到边界,而边界占用几个像素就可以通过这个计算公式得出。

float czm_metersPerPixel(vec4 positionEC, float pixelRatio) {
    float width = czm_viewport.z;
    float height = czm_viewport.w;
    float pixelWidth;
    float pixelHeight;
    float top = czm_frustumPlanes.x;
    float bottom = czm_frustumPlanes.y;
    float left = czm_frustumPlanes.z;
    float right = czm_frustumPlanes.w;
    if (czm_sceneMode == czm_sceneMode2D || czm_orthographicIn3D == 1.0) {
        float frustumWidth = right - left;
        float frustumHeight = top - bottom;
        pixelWidth = frustumWidth / width;
        pixelHeight = frustumHeight / height;
    }
    else {
        float distanceToPixel = -positionEC.z;
        float inverseNear = 1.0 / czm_currentFrustum.x;
        float tanTheta = top * inverseNear;
        pixelHeight = 2.0 * distanceToPixel * tanTheta / height;
        tanTheta = right * inverseNear;
        pixelWidth = 2.0 * distanceToPixel * tanTheta / width;
    }
    return max(pixelWidth, pixelHeight) * pixelRatio;
}

1、计算视锥中近裁切面中的宽度和高度(一般会设置于视口相同的大小,单位是像素);

2、计算当前像素点距离相机的实际距离(单位是米),并通过视锥的视野(视角范围)计算出当前像素距离处的宽度和高度(单位是米);

3、将步骤1中计算的宽高与步骤2中计算的结果进行比较,取最大的即可得到结果。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值