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

📄 mgcbeziertriangleg.cpp

📁 《3D游戏引擎设计》的源码
💻 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 "MgcBezierTriangleG.h"
#include "MgcRTLib.h"

//----------------------------------------------------------------------------
MgcBezierTriangleG::MgcBezierTriangleG (unsigned int uiDegree,
    MgcVector3* akCtrlPoint)
    :
    MgcBezierPatchG(uiDegree,(uiDegree+1)*(uiDegree+2)/2,akCtrlPoint)
{
}
//----------------------------------------------------------------------------
void MgcBezierTriangleG::Initialize (unsigned int uiLevel, bool bWantNormals)
{
    // vertices V = (2^L+1)*(2^L+2)/2
    unsigned int uiTwoPowL = (1 << uiLevel);
    m_uiVertexQuantity = ((uiTwoPowL + 1)*(uiTwoPowL + 2)) >> 1;
    delete[] m_akVertex;
    m_akVertex = new MgcVector3[m_uiVertexQuantity];

    // normals
    delete[] m_akNormal;
    if ( bWantNormals )
        m_akNormal = new MgcVector3[m_uiVertexQuantity];

    // triangles T = 4^L
    m_uiTriangleQuantity = (1 << 2*uiLevel);
    delete[] m_auiConnect;
    m_auiConnect = new unsigned int[3*m_uiTriangleQuantity];

    // generate connectivity
    unsigned int uiTwiceTwoPowLPlusOne = (uiTwoPowL + 1) << 1;
    unsigned int* puiConnect = m_auiConnect;
    for (unsigned int uiY = 0, uiYStart = 0; uiY < uiTwoPowL; uiY++)
    {
        unsigned int uiI0 = uiYStart;
        unsigned int uiI1 = uiI0 + 1;
        uiYStart = ((uiY + 1)*(uiTwiceTwoPowLPlusOne - uiY)) >> 1;
        unsigned int uiI2 = uiYStart;
        unsigned int uiSum;
        for (unsigned int uiX = 0; (uiSum = uiX + uiY) < uiTwoPowL; uiX++)
        {
            *puiConnect++ = uiI0;
            *puiConnect++ = uiI1;
            *puiConnect++ = uiI2;

            if ( uiSum + 1 < uiTwoPowL )
            {
                *puiConnect++ = uiI1;
                *puiConnect++ = uiI2 + 1;
                *puiConnect++ = uiI2;
            }

            uiI0++;
            uiI1++;
            uiI2++;
        }
    }
}
//----------------------------------------------------------------------------

⌨️ 快捷键说明

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