⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmldistvec3fru3.cpp

📁 3D Game Engine Design Source Code非常棒
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                        else if ( fUDDot >= fMinUDDot )
                        {
                            // U-face
                            fUDot = fDMin*kTest.Y() - fUMin*kTest.Z();
                            fT = fUDot/fMinUDDot;
                            kClosest.X() = kTest.X();
                            kClosest.Y() = kTest.Y() - fT*fDMin;
                            kClosest.Z() = kTest.Z() + fT*fUMin;
                        }
                        else
                        {
                            // UN-edge
                            kClosest.X() = kTest.X();
                            kClosest.Y() = fUMin;
                            kClosest.Z() = fDMin;
                        }
                    }
                    else
                    {
                        if ( fLUDDot >= fMaxLUDDot )
                        {
                            // LUF-vertex
                            kClosest.X() = fLMax;
                            kClosest.Y() = fUMax;
                            kClosest.Z() = fDMax;
                        }
                        else if ( fLUDDot >= fMinLUDDot )
                        {
                            // LU-edge
                            fT = fLUDDot/fMinLUDDot;
                            kClosest.X() = fT*fLMin;
                            kClosest.Y() = fT*fUMin;
                            kClosest.Z() = fT*fDMin;
                        }
                        else
                        {
                            // LUN-vertex
                            kClosest.X() = fLMin;
                            kClosest.Y() = fUMin;
                            kClosest.Z() = fDMin;
                        }
                    }
                }
            }
        }
    }
    else
    {
        fLDot = fDMin*kTest.X() - fLMin*kTest.Z();
        fUDot = fDMin*kTest.Y() - fUMin*kTest.Z();
        if ( fLDot <= (Real)0.0 )
        {
            if ( fUDot <= (Real)0.0 )
            {
                // point inside frustum
                kClosest = kTest;
            }
            else
            {
                fUDDot = fUMin*kTest.Y() + fDMin*kTest.Z();
                if ( fUDDot >= fMaxUDDot )
                {
                    // UF-edge
                    kClosest.X() = kTest.X();
                    kClosest.Y() = fUMax;
                    kClosest.Z() = fDMax;
                }
                else
                {
                    // U-face
                    fUDot = fDMin*kTest.Y() - fUMin*kTest.Z();
                    fT = fUDot/fMinUDDot;
                    kClosest.X() = kTest.X();
                    kClosest.Y() = kTest.Y() - fT*fDMin;
                    kClosest.Z() = kTest.Z() + fT*fUMin;
                }
            }
        }
        else
        {
            if ( fUDot <= (Real)0.0 )
            {
                fLDDot = fLMin*kTest.X() + fDMin*kTest.Z();
                if ( fLDDot >= fMaxLDDot )
                {
                    // LF-edge
                    kClosest.X() = fLMax;
                    kClosest.Y() = kTest.Y();
                    kClosest.Z() = fDMax;
                }
                else
                {
                    // L-face
                    fLDot = fDMin*kTest.X() - fLMin*kTest.Z();
                    fT = fLDot/fMinLDDot;
                    kClosest.X() = kTest.X() - fT*fDMin;
                    kClosest.Y() = kTest.Y();
                    kClosest.Z() = kTest.Z() + fT*fLMin;
                }
            }
            else
            {
                fLUDDot = fLMin*kTest.X() + fUMin*kTest.Y() + fDMin*kTest.Z();
                fLEdgeDot = fUMin*fLUDDot - fMinLUDDot*kTest.Y();
                if ( fLEdgeDot >= (Real)0.0 )
                {
                    fLDDot = fLMin*kTest.X() + fDMin*kTest.Z();
                    if ( fLDDot >= fMaxLDDot )
                    {
                        // LF-edge
                        kClosest.X() = fLMax;
                        kClosest.Y() = kTest.Y();
                        kClosest.Z() = fDMax;
                    }
                    else // assert( fLDDot >= fMinLDDot ) from geometry
                    {
                        // L-face
                        fLDot = fDMin*kTest.X() - fLMin*kTest.Z();
                        fT = fLDot/fMinLDDot;
                        kClosest.X() = kTest.X() - fT*fDMin;
                        kClosest.Y() = kTest.Y();
                        kClosest.Z() = kTest.Z() + fT*fLMin;
                    }
                }
                else
                {
                    fUEdgeDot = fLMin*fLUDDot - fMinLUDDot*kTest.X();
                    if ( fUEdgeDot >= (Real)0.0 )
                    {
                        fUDDot = fUMin*kTest.Y() + fDMin*kTest.Z();
                        if ( fUDDot >= fMaxUDDot )
                        {
                            // UF-edge
                            kClosest.X() = kTest.X();
                            kClosest.Y() = fUMax;
                            kClosest.Z() = fDMax;
                        }
                        else // assert( fUDDot >= fMinUDDot ) from geometry
                        {
                            // U-face
                            fUDot = fDMin*kTest.Y() - fUMin*kTest.Z();
                            fT = fUDot/fMinUDDot;
                            kClosest.X() = kTest.X();
                            kClosest.Y() = kTest.Y() - fT*fDMin;
                            kClosest.Z() = kTest.Z() + fT*fUMin;
                        }
                    }
                    else
                    {
                        if ( fLUDDot >= fMaxLUDDot )
                        {
                            // LUF-vertex
                            kClosest.X() = fLMax;
                            kClosest.Y() = fUMax;
                            kClosest.Z() = fDMax;
                        }
                        else // assert( fLUDDot >= fMinLUDDot ) from geometry
                        {
                            // LU-edge
                            fT = fLUDDot/fMinLUDDot;
                            kClosest.X() = fT*fLMin;
                            kClosest.Y() = fT*fUMin;
                            kClosest.Z() = fT*fDMin;
                        }
                    }
                }
            }
        }
    }

    kDiff = kTest - kClosest;

    // convert back to original quadrant
    if ( bLSignChange )
        kClosest.X() = -kClosest.X();

    if ( bUSignChange )
        kClosest.Y() = -kClosest.Y();

    if ( pkClosest )
    {
        // caller wants closest point, convert back to world coordinates
        *pkClosest = rkFrustum.Origin() +
            kClosest.X()*rkFrustum.LVector() +
            kClosest.Y()*rkFrustum.UVector() +
            kClosest.Z()*rkFrustum.DVector();
    }

    // compute and return squared distance
    return kDiff.SquaredLength();
}
//----------------------------------------------------------------------------
template <class Real>
Real Wml::Distance (const Vector3<Real>& rkPoint,
    const Frustum3<Real>& rkFrustum, Vector3<Real>* pkClosest)
{
    return Math<Real>::Sqrt(SqrDistance(rkPoint,rkFrustum,pkClosest));
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// explicit instantiation
//----------------------------------------------------------------------------
namespace Wml
{
template WML_ITEM float SqrDistance<float> (const Vector3<float>&,
    const Frustum3<float>&, Vector3<float>*);
template WML_ITEM float Distance<float> (const Vector3<float>&,
    const Frustum3<float>&, Vector3<float>*);

template WML_ITEM double SqrDistance<double> (const Vector3<double>&,
    const Frustum3<double>&, Vector3<double>*);
template WML_ITEM double Distance<double> (const Vector3<double>&,
    const Frustum3<double>&, Vector3<double>*);
}
//----------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -