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

📄 mgcbezierrectangleg.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 "MgcBezierRectangleG.h"
#include "MgcRTLib.h"

//----------------------------------------------------------------------------
MgcBezierRectangleG::MgcBezierRectangleG (unsigned int uiDegree,
    MgcVector3* akCtrlPoint)
    :
    MgcBezierPatchG(uiDegree,(uiDegree+1)*(uiDegree+1),akCtrlPoint)
{
}
//----------------------------------------------------------------------------
void MgcBezierRectangleG::Initialize (unsigned int uiLevel, bool bWantNormals)
{
    // vertices V = (2^L+1)^2
    unsigned int uiTwoPowL = (1 << uiLevel);
    unsigned int uiTwoPowLPlusOne = uiTwoPowL + 1;
    m_uiVertexQuantity = uiTwoPowLPlusOne*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*4^L
    m_uiTriangleQuantity = 2*(1 << 2*uiLevel);
    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 < uiTwoPowL; 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 + -