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

📄 mgcbeziercylinderg.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 "MgcBezierCylinderG.h"

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

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

    // triangles T = 2*2^L*2^C
    m_uiTriangleQuantity = 2*uiTwoPowC*uiTwoPowL;
    delete[] m_auiConnect;
    m_auiConnect = new unsigned int[3*m_uiTriangleQuantity];

    // generate connectivity
    unsigned int* puiConnect = m_auiConnect;
    for (unsigned int uiY = 0, uiYStart = 0; uiY < uiTwoPowC; uiY++)
    {
        unsigned int uiI0 = uiYStart;
        uiYStart += uiTwoPowLPlusOne;
        unsigned int uiI1 = uiI0 + 1;
        unsigned int uiI2 = uiYStart;
        unsigned int uiI3 = uiI2 + 1;
        for (unsigned int uiX = 0; uiX < uiTwoPowL; uiX++)
        {
            *puiConnect++ = uiI0;
            *puiConnect++ = uiI1;
            *puiConnect++ = uiI2;
            *puiConnect++ = uiI1;
            *puiConnect++ = uiI3;
            *puiConnect++ = uiI2;
            uiI0++;
            uiI1++;
            uiI2++;
            uiI3++;
        }
    }
}
//----------------------------------------------------------------------------

⌨️ 快捷键说明

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