当前位置: 首页>>代码示例>>C++>>正文


C++ Observer::getFOV方法代码示例

本文整理汇总了C++中Observer::getFOV方法的典型用法代码示例。如果您正苦于以下问题:C++ Observer::getFOV方法的具体用法?C++ Observer::getFOV怎么用?C++ Observer::getFOV使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Observer的用法示例。


在下文中一共展示了Observer::getFOV方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: viewCenter

void
SkyGrid::render(Renderer& renderer,
                const Observer& observer,
                int windowWidth,
                int windowHeight)
{
    // 90 degree rotation about the x-axis used to transform coordinates
    // to Celestia's system.
    Quatd xrot90 = Quatd::xrotation(-PI / 2.0);

    double vfov = observer.getFOV();
    double viewAspectRatio = (double) windowWidth / (double) windowHeight;

    // Calculate the cosine of half the maximum field of view. We'll use this for
    // fast testing of marker visibility. The stored field of view is the
    // vertical field of view; we want the field of view as measured on the
    // diagonal between viewport corners.
    double h = tan(vfov / 2);
    double w = h * viewAspectRatio;
    double diag = sqrt(1.0 + square(h) + square(h * viewAspectRatio));
    double cosHalfFov = 1.0 / diag;
    double halfFov = acos(cosHalfFov);
    
    float polarCrossSize = (float) (POLAR_CROSS_SIZE * halfFov);

    // We want to avoid drawing more of the grid than we have to. The following code
    // determines the region of the grid intersected by the view frustum. We're
    // interested in the minimum and maximum phi and theta of the visible patch
    // of the celestial sphere.

    // Find the minimum and maximum theta (longitude) by finding the smallest
    // longitude range containing all corners of the view frustum.

    // View frustum corners
    Vec3d c0(-w, -h, -1.0);
    Vec3d c1( w, -h, -1.0);
    Vec3d c2(-w,  h, -1.0);
    Vec3d c3( w,  h, -1.0);

    Quatd cameraOrientation = observer.getOrientation();
    Mat3d r = (cameraOrientation * xrot90 * ~m_orientation * ~xrot90).toMatrix3();

    // Transform the frustum corners by the camera and grid
    // rotations.
    c0 = toStandardCoords(c0 * r);
    c1 = toStandardCoords(c1 * r);
    c2 = toStandardCoords(c2 * r);
    c3 = toStandardCoords(c3 * r);

    double thetaC0 = atan2(c0.y, c0.x);
    double thetaC1 = atan2(c1.y, c1.x);
    double thetaC2 = atan2(c2.y, c2.x);
    double thetaC3 = atan2(c3.y, c3.x);

    // Compute the minimum longitude range containing the corners; slightly
    // tricky because of the wrapping at PI/-PI.
    double minTheta = thetaC0;
    double maxTheta = thetaC1;   
    double maxDiff = 0.0;
    updateAngleRange(thetaC0, thetaC1, &maxDiff, &minTheta, &maxTheta);
    updateAngleRange(thetaC0, thetaC2, &maxDiff, &minTheta, &maxTheta);
    updateAngleRange(thetaC0, thetaC3, &maxDiff, &minTheta, &maxTheta);
    updateAngleRange(thetaC1, thetaC2, &maxDiff, &minTheta, &maxTheta);
    updateAngleRange(thetaC1, thetaC3, &maxDiff, &minTheta, &maxTheta);
    updateAngleRange(thetaC2, thetaC3, &maxDiff, &minTheta, &maxTheta);

    if (std::fabs(maxTheta - minTheta) < PI)
    {
        if (minTheta > maxTheta)
            std::swap(minTheta, maxTheta);
    }
    else
    {
        if (maxTheta > minTheta)
            std::swap(minTheta, maxTheta);
    }
    maxTheta = minTheta + maxDiff;
    
    // Calculate the normals to the view frustum planes; we'll use these to
    // when computing intersection points with the parallels and meridians of the
    // grid. Coordinate labels will be drawn at the intersection points.
    Vec3d frustumNormal[4];    
    frustumNormal[0] = Vec3d( 0,  1, -h);
    frustumNormal[1] = Vec3d( 0, -1, -h);
    frustumNormal[2] = Vec3d( 1,  0, -w);
    frustumNormal[3] = Vec3d(-1,  0, -w);
    
    {
        for (int i = 0; i < 4; i++)
        {
            frustumNormal[i].normalize();
            frustumNormal[i] = toStandardCoords(frustumNormal[i] * r);
        }
    }

    Vec3d viewCenter(0.0, 0.0, -1.0);
    viewCenter = toStandardCoords(viewCenter * r);

    double centerDec;
    if (fabs(viewCenter.z) < 1.0)
//.........这里部分代码省略.........
开发者ID:jpcoles,项目名称:ZM,代码行数:101,代码来源:skygrid.cpp


注:本文中的Observer::getFOV方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。