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


C++ GfMatrix4d::Transform方法代码示例

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


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

示例1: ComputeViewInverse

vector<GfVec3d>
GfFrustum::ComputeCornersAtDistance(double d) const
{
    const GfVec2d &winMin = _window.GetMin();
    const GfVec2d &winMax = _window.GetMax();

    vector<GfVec3d> corners;
    corners.reserve(4);

    if (_projectionType == Perspective) {
        // Similar to ComputeCorners
        corners.push_back(GfVec3d(d * winMin[0], d * winMin[1], -d));
        corners.push_back(GfVec3d(d * winMax[0], d * winMin[1], -d));
        corners.push_back(GfVec3d(d * winMin[0], d * winMax[1], -d));
        corners.push_back(GfVec3d(d * winMax[0], d * winMax[1], -d));
    }
    else {
        corners.push_back(GfVec3d(winMin[0], winMin[1], -d));
        corners.push_back(GfVec3d(winMax[0], winMin[1], -d));
        corners.push_back(GfVec3d(winMin[0], winMax[1], -d));
        corners.push_back(GfVec3d(winMax[0], winMax[1], -d));
    }

    // Each corner is then transformed into world space by the inverse
    // of the view matrix.
    const GfMatrix4d m = ComputeViewInverse();
    for (int i = 0; i < 4; i++)
        corners[i] = m.Transform(corners[i]);

    return corners;
}
开发者ID:JT-a,项目名称:USD,代码行数:31,代码来源:frustum.cpp

示例2: vp

void
GfFrustum::_CalculateFrustumPlanes() const
{
    if (!_planes.empty())
        return;

    _planes.reserve(6);

    // These are values we need to construct the planes.
    const GfVec2d &winMin = _window.GetMin();
    const GfVec2d &winMax = _window.GetMax();
    double near           = _nearFar.GetMin();
    double far            = _nearFar.GetMax();
    GfMatrix4d m          = ComputeViewInverse();

    // For a perspective frustum, we use the viewpoint and four
    // corners of the near-plane frustum rectangle to define the 4
    // planes forming the left, right, top, and bottom sides of the
    // frustum.
    if (_projectionType == GfFrustum::Perspective) {

        //
        // Get the eye-space viewpoint (the origin) and the four corners
        // of the near-plane frustum rectangle using similar triangles.
        //
        // This picture may help:   
        //                 
        //                  top of near plane
        //                  frustum rectangle
        //
        //                  + --
        //                / |  | 
        //              /   |  |
        //            /     |  | h
        //          /       |  |
        //        /         |  |                 
        //   vp +-----------+ --               
        //                    center of near plane frustum rectangle
        //      |___________|
        //           near    
        //
        // The height (h) of this triangle is found by the following
        // equation, based on the definition of the _window member
        // variable, which is the size of the image rectangle in the
        // reference plane (a distance of 1 from the viewpoint):
        //
        //      h       _window.GetMax()[1]
        //    ------ = --------------------
        //     near             1
        //
        // Solving for h gets the height of the triangle. Doing the
        // similar math for the other 3 sizes of the near-plane
        // rectangle is left as an exercise for the reader.
        //
        // XXX Note: If we ever allow reference plane depth to be other 
        // than 1.0, we'll need to revisit this.

        GfVec3d vp(0.0, 0.0, 0.0);
        GfVec3d lb(near * winMin[0], near * winMin[1], -near);
        GfVec3d rb(near * winMax[0], near * winMin[1], -near);
        GfVec3d lt(near * winMin[0], near * winMax[1], -near);
        GfVec3d rt(near * winMax[0], near * winMax[1], -near);

        // Transform all 5 points into world space by the inverse of the
        // view matrix (which converts from world space to eye space).
        vp = m.Transform(vp);
        lb = m.Transform(lb);
        rb = m.Transform(rb);
        lt = m.Transform(lt);
        rt = m.Transform(rt);

        // Construct the 6 planes. The three points defining each plane
        // should obey the right-hand-rule; they should be in counter-clockwise 
        // order on the inside of the frustum. This makes the intersection of 
        // the half-spaces defined by the planes the contents of the frustum.
        _planes.push_back( GfPlane(vp, lb, lt) );     // Left
        _planes.push_back( GfPlane(vp, rt, rb) );     // Right
        _planes.push_back( GfPlane(vp, rb, lb) );     // Bottom
        _planes.push_back( GfPlane(vp, lt, rt) );     // Top
        _planes.push_back( GfPlane(rb, lb, lt) );     // Near
    }

    // For an orthographic projection, we need only the four corners
    // of the near-plane frustum rectangle and the view direction to
    // define the 4 planes forming the left, right, top, and bottom
    // sides of the frustum.
    else {

        //
        // The math here is much easier than in the perspective case,
        // because we have parallel lines instead of triangles. Just
        // use the size of the image rectangle in the reference plane,
        // which is the same in the near plane.
        //
        GfVec3d lb(winMin[0], winMin[1], -near);
        GfVec3d rb(winMax[0], winMin[1], -near);
        GfVec3d lt(winMin[0], winMax[1], -near);
        GfVec3d rt(winMax[0], winMax[1], -near);

        // Transform the 4 points into world space by the inverse of
//.........这里部分代码省略.........
开发者ID:JT-a,项目名称:USD,代码行数:101,代码来源:frustum.cpp


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