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

📄 mgcgptrimesh.h

📁 《3D游戏引擎设计》的源码
💻 H
字号:
// 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 MGCGPTRIMESH_H
#define MGCGPTRIMESH_H

#include "MgcTClassStorage.h"
#include "MgcTStorage.h"
#include "MgcGeometry.h"


class MgcGPTriMesh : public MgcGeometry
{
    MgcDeclareRTTI;
    MgcDeclareStream;

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

    MgcGPTriMesh ();

    virtual ~MgcGPTriMesh ();

    // vertex access
    unsigned int GetVertexQuantity () const;
    unsigned int GetVerticesUsed () const;
    MgcVector3& Vertex (unsigned int uiV) const;
    MgcVector3& Normal (unsigned int uiV) const;
    MgcColor& Color (unsigned int uiV) const;
    MgcVector2& Texture (unsigned int uiV) const;
    MgcVector3* GetVertices () const;
    MgcVector3* GetNormals () const;
    MgcColor* GetColors () const;
    MgcVector2* GetTextures () const;
    bool HasNormals () const;
    bool HasColors () const;
    bool HasTextures () const;

    // flag for invalid vertices
    enum { INVALID_INDEX = (unsigned int)(~0) };

    class EdgeRecord
    {
    public:
        EdgeRecord ();

        unsigned int& Vertex (int i);
        unsigned int& Triangle (int i);
        int GetVertexIndex (unsigned int uiV);
        int GetTriangleIndex (unsigned int uiT);

    protected:
        unsigned int m_uiVertex[2];
        unsigned int m_uiTriangle[2];
    };

    class TriangleRecord
    {
    public:
        TriangleRecord ();

        unsigned int& Vertex (int i);
        unsigned int& Edge (int i);
        int GetVertexIndex (unsigned int uiV);
        int GetEdgeIndex (unsigned int uiE);

    protected:
        unsigned int m_uiVertex[3];
        unsigned int m_uiEdge[3];
    };

    // edge access
    unsigned int GetEdgeQuantity () const;
    unsigned int GetEdgesUsed () const;
    EdgeRecord& Edge (unsigned int uiE) const;

    // triangle access
    unsigned int GetTriangleQuantity () const;
    unsigned int GetTrianglesUsed () const;
    TriangleRecord& Triangle (unsigned int uiT) const;
    void GetTriangle (unsigned int uiT, unsigned int& uiV0,
        unsigned int& uiV1, unsigned int& uiV2) const;

    // facet planes
    const MgcPlane& GetFacetPlane (unsigned int uiT) const;
    void UpdateFacetPlanes () { /* TO DO */ }

    // mesh construction
    void InsertTriangle (unsigned int uiV0, unsigned int uiV1,
        unsigned int uiV2);
    void RemoveTriangle (unsigned int uiT);

    // bounds
    virtual void UpdateModelBound ();

protected:
    // mesh construction
    unsigned int AddEdge (unsigned int uiV0, unsigned int uiV1,
        unsigned int uiT);

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

    // vertices
    static unsigned int ms_uiVertexGrowBy;
    unsigned int m_uiVertexQuantity, m_uiVerticesUsed;
    MgcTClassStorage<MgcVector3> m_akVertex;
    MgcTClassStorage<MgcVector3> m_akNormal;
    MgcTClassStorage<MgcColor> m_akColor;
    MgcTClassStorage<MgcVector2> m_akTexture;
    bool m_bHasNormals, m_bHasColors, m_bHasTextures;

    // edges
    static unsigned int ms_uiEdgeGrowBy;
    unsigned int m_uiEdgeQuantity, m_uiEdgesUsed;
    MgcTClassStorage<EdgeRecord> m_akEdge;

    // triangles
    static unsigned int ms_uiTriangleGrowBy;
    unsigned int m_uiTriangleQuantity, m_uiTrianglesUsed;
    MgcTClassStorage<TriangleRecord> m_akTriangle;
    MgcTClassStorage<MgcPlane> m_akFacetPlane;
};

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

#endif

⌨️ 快捷键说明

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