zoukankan      html  css  js  c++  java
  • OSG中距离转像素公式(PIXEL_SIZE_ON_SCREEN)

    osgearth_computerangecallback.cpp 中
    下面的代码假设:range模式是PIXEL_SIZE_ON_SCREEN,根据距视点的距离计算在屏幕中的像素大小。
    像素大小转距离可以根据此代码中的公式逆推。
    struct MyComputeRangeCallback : public osgEarth::ComputeRangeCallback
    {
        virtual float operator()(osg::Node* node, osg::NodeVisitor& nv)
        {
            osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
            if (cv)
            {
                // This code assumes that the range_mode is PIXEL_SIZE_ON_SCREEN and computes the pixel size on screen 
                // without just using the vertical field of view.
                float distance = nv.getDistanceToViewPoint(node->getBound().center(),true);
                float radius = node->getBound().radius();
    
                double fov, ar, near, far;
                cv->getCurrentCamera()->getProjectionMatrixAsPerspective(fov, ar, near,far);
    
                osg::Viewport* viewPort = cv->getCurrentCamera()->getViewport();
                double angularSize = osg::RadiansToDegrees( 2.0*atan(radius/distance) );
                double dpp = osg::maximum(fov, 1.0e-17) / viewPort->height();
                float pixelSize = angularSize / dpp;
                return pixelSize;
            }
    
            // Fall back to the base calculation.
            return -1.0;
        }
    };
  • 相关阅读:
    PowerDesigner通过SQL文件,反向生成模型
    跨域请求设置
    SSO单点登录与登出
    jwt使用
    git概念理解
    Slf4j MDC机制
    ASP.NET Core依赖注入最佳实践,提示&技巧
    EFCore数据库迁移命令整理
    RSA加密的使用
    CocoaPods 安装的第三方删除
  • 原文地址:https://www.cnblogs.com/ningmouming/p/9798449.html
Copyright © 2011-2022 走看看