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

📄 mgccontellipsoid.cpp

📁 3D Game Engine Design Source Code非常棒
💻 CPP
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf

#include "MgcContEllipsoid.h"
#include "MgcGaussPointsFit.h"

//----------------------------------------------------------------------------
MgcEllipsoid MgcContEllipsoid (int iQuantity, const MgcVector3* akPoint)
{
    MgcVector3 kCenter, akAxis[3];
    MgcReal afD[3];
    MgcGaussPointsFit(iQuantity,akPoint,kCenter,akAxis,afD);

    MgcReal fMaxValue = 0.0;
    for (int i = 0; i < iQuantity; i++)
    {
        MgcVector3 kDiff = akPoint[i] - kCenter;
        MgcReal fU[3] =
        {
            akAxis[0].Dot(kDiff),
            akAxis[1].Dot(kDiff),
            akAxis[2].Dot(kDiff)
        };

        MgcReal fValue = afD[0]*fU[0]*fU[0] + afD[1]*fU[1]*fU[1] +
            afD[2]*fU[2]*fU[2];

        if ( fValue > fMaxValue )
            fMaxValue = fValue;
    }

    MgcEllipsoid kEllipsoid;
    kEllipsoid.Center() = kCenter;

    MgcMatrix3 kTensor[3];
    MgcMatrix3::TensorProduct(akAxis[0],akAxis[0],kTensor[0]);
    MgcMatrix3::TensorProduct(akAxis[1],akAxis[1],kTensor[1]);
    MgcMatrix3::TensorProduct(akAxis[2],akAxis[2],kTensor[2]);

    MgcReal fInv = 1.0/fMaxValue;
    kEllipsoid.A() = (fInv*afD[0])*kTensor[0] + (fInv*afD[1])*kTensor[1] +
        (fInv*afD[2])*kTensor[2];

    return kEllipsoid;
}
//----------------------------------------------------------------------------

⌨️ 快捷键说明

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