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. 分割【代码

    2023-12-08 13:46:04       8 阅读
  2. 、分辨率、公差概念

    2023-12-08 13:46:04       39 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-08 13:46:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-08 13:46:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-08 13:46:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-08 13:46:04       18 阅读

热门阅读

  1. facebook广告和谷歌广告的区别

    2023-12-08 13:46:04       40 阅读
  2. QT作业1

    QT作业1

    2023-12-08 13:46:04      38 阅读
  3. Spring Task

    2023-12-08 13:46:04       39 阅读
  4. Swagger PHP Thinkphp 接口文档

    2023-12-08 13:46:04       47 阅读
  5. 一、C#笔记

    2023-12-08 13:46:04       34 阅读
  6. QT学习随记 (二)—— QT基础

    2023-12-08 13:46:04       38 阅读