mgcclodmesh.h

来自「3D Game Engine Design Source Code非常棒」· C头文件 代码 · 共 122 行

H
122
字号
// 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
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#ifndef MGCCLODMESH_H
#define MGCCLODMESH_H

#include "MgcTriMesh.h"


class MgcCLodMesh : public MgcTriMesh
{
    MgcDeclareRTTI;
    MgcDeclareStream;

public:
    // Construction and destruction.  MgcCLodMesh accepts responsibility for
    // deleting the input arrays.
    MgcCLodMesh (unsigned int uiVertexQuantity, MgcVector3* akVertex,
        MgcVector3* akNormal, MgcColor* akColor, MgcVector2* akTexture,
        unsigned int uiTriangleQuantity, unsigned int* auiConnect);

    virtual ~MgcCLodMesh ();

    // LOD selection is based on manual selection by the application.  To
    // use distance from camera or screen space coverage, derived a class
    // from MgcCLodMesh and override 'GetAutomatedTargetRecord'.
    void SetTargetRecord (int iTargetRecord);
    int GetTargetRecord () const;
    virtual int GetAutomatedTargetRecord ();

protected:
    MgcCLodMesh ();

    // geometric updates
    void SelectLevelOfDetail (MgcRenderer& rkRenderer);
    virtual void UpdateWorldData (MgcReal fAppTime);

    // drawing
    virtual void Draw (MgcRenderer& rkRenderer);

    // for deferred updates
    MgcReal m_fLastUpdateTime;

    // selection of LOD
    unsigned int m_uiMinIndex, m_uiMaxIndex;
    unsigned int m_uiMinArea, m_uiMaxArea;

    // Edge contraction uses the already existing vertices and attributes
    // that were passed to the constructor.
    class Record
    {
    public:
        Record ();
        ~Record ();

        // edge <I0,I1> collapses so that I1 is replaced by I0
        unsigned int m_uiI0, m_uiI1;

        // number of triangles after edge collapse
        unsigned int m_uiTriangleQuantity;

        // connectivity array indices in [0..TQ-1] that contain I1
        unsigned int m_uiVertexQuantity;
        unsigned int* m_auiIndex;
    };

    void ComputeRecords ();

    unsigned int m_uiInitialTriangleQuantity;
    int m_iCurrentRecord, m_iTargetRecord;
    Record* m_akRecord;

private:
    // support for computing the edge collapses
    class KeyType
    {
    public:
        KeyType (unsigned int uiI0 = 0, unsigned int uiI1 = 0);

        KeyType& operator= (const KeyType& rkKey);
        bool operator== (const KeyType& rkKey) const;
        bool operator!= (const KeyType& rkKey) const;
        operator unsigned int () const;

        unsigned int m_uiI0, m_uiI1;
    };

    typedef MgcReal ErrorMatrix[10];  // upper triangular entries
    ErrorMatrix* ComputeVertexErrorMatrices ();

    typedef MgcTClassMap<KeyType,MgcReal> HeapType;
    HeapType* ComputeEdgeErrorMetrics (ErrorMatrix* akQ);

    bool TriangleContainsEdge (unsigned int uiT, unsigned int uiI0,
        unsigned int uiI1);
    void MoveTrianglesToEnd ();

    void GetConnectivityIndices ();

    void RecalculateErrors (HeapType* pkHeap, ErrorMatrix* akQ,
        unsigned int uiKeep, unsigned int uiRemove);

    void ComputeEdgeCollapses (HeapType* pkHeap, ErrorMatrix* akQ);

    void ReorderVertices ();
};

MgcSmartPointer(MgcCLodMesh);
MgcRegisterStream(MgcCLodMesh);
#include "MgcCLodMesh.inl"

#endif

⌨️ 快捷键说明

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