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

📄 mgctrianglenetwork.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
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf

#ifndef MGCTRIANGLENETWORK_H
#define MGCTRIANGLENETWORK_H

// The Delaunay triangulation method is a modification of code written by 
// Dave Watson.  It uses an algorithm described in
//
//     Watson, D.F., 1981, Computing the n-dimensional Delaunay 
//     tessellation with application to Voronoi polytopes: 
//     The Computer J., 24(2), p. 167-172.

#include "MgcVector2.h"


class MgcTriangleNetwork
{
public:
    // Construction and destruction.  In the first constructor,
    // MgcTriangleNetwork accepts ownership of the input array and will delete
    // it during destruction.  The second constructor is designed to allow
    // sharing of the network (note that the reference argument is not passed
    // as 'const').  Any other network that shares this object will not delete
    // the data in this object.
    MgcTriangleNetwork (int iVertexQuantity, MgcVector2* akVertex);
    MgcTriangleNetwork (MgcTriangleNetwork& pkNet);
    virtual ~MgcTriangleNetwork ();
    bool IsOwner () const;

    // vertices
    int GetVertexQuantity () const;
    const MgcVector2& GetVertex (int i) const;
    const MgcVector2* GetVertices () const;
    MgcReal GetXMin () const;
    MgcReal GetXMax () const;
    MgcReal GetXRange () const;
    MgcReal GetYMin () const;
    MgcReal GetYMax () const;
    MgcReal GetYRange () const;


    // edges
    class Edge
    {
    public:
        // vertices forming edge
        int m_aiVertex[2];

        // triangles sharing edge
        int m_aiTriangle[2];
    };

    int GetEdgeQuantity () const;
    const Edge& GetEdge (int i) const;
    const Edge* GetEdges () const;


    // triangles
    class Triangle
    {
    public:
        // vertices, listed in counterclockwise order
        int m_aiVertex[3];

        // adjacent triangles,
        //   adj[0] points to triangle sharing edge (ver[0],ver[1])
        //   adj[1] points to triangle sharing edge (ver[1],ver[2])
        //   adj[2] points to triangle sharing edge (ver[2],ver[0])
        int m_aiAdjacent[3];
    };

    int GetTriangleQuantity () const;
    Triangle& GetTriangle (int i);
    const Triangle& GetTriangle (int i) const;
    Triangle* GetTriangles ();
    const Triangle* GetTriangles () const;

    // extra triangles (added to boundary)
    int GetExtraTriangleQuantity () const;
    Triangle& GetExtraTriangle (int i);
    const Triangle& GetExtraTriangle (int i) const;
    Triangle* GetExtraTriangles ();
    const Triangle* GetExtraTriangles () const;

    // helper functions
    static void ComputeBarycenter (const MgcVector2& rkV0,
        const MgcVector2& rkV1, const MgcVector2& rkV2,
        const MgcVector2& rkP, MgcReal afBary[3]);

    static bool InTriangle (const MgcVector2& rkV0, const MgcVector2& rkV1,
        const MgcVector2& rkV2, const MgcVector2& rkTest);

    static void ComputeInscribedCenter (const MgcVector2& rkV0,
        const MgcVector2& rkV1, const MgcVector2& rkV2, MgcVector2& rkCenter);

    // tweaking parameters
    static MgcReal& Epsilon ();  // default = 0.00001
    static MgcReal& Range ();    // default = 10.0
    static int& TSize ();        // default = 75

protected:
    // for sharing
    bool m_bOwner;

    // vertices
    int m_iVertexQuantity;
    MgcVector2* m_akVertex;
    MgcReal m_fXMin, m_fXMax, m_fXRange;
    MgcReal m_fYMin, m_fYMax, m_fYRange;

    // edges
    int m_iEdgeQuantity;
    Edge* m_akEdge;

    // triangles
    int m_iTriangleQuantity;
    Triangle* m_akTriangle;

    // extra triangles to support interpolation on convex hull of vertices
    int m_iExtraTriangleQuantity;
    Triangle* m_akExtraTriangle;

    // tweaking parameters
    static MgcReal ms_fEpsilon;
    static MgcReal ms_fRange;
    static int ms_iTSize;
};

#include "MgcTriangleNetwork.inl"

#endif

⌨️ 快捷键说明

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