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

📄 mgcquadricsurface.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 MGCQUADRICSURFACE_H
#define MGCQUADRICSURFACE_H

#include "MgcImplicitSurface.h"
#include "MgcMatrix3.h"


class MgcQuadricSurface
{
public:
    // Quadric surfaces are defined implicitly by x^T A x + b^T x + c = 0
    // where A is symmetric 3x3, b and x are 3x1, and c is a scalar.
    MgcQuadricSurface (const MgcMatrix3& rkA, const MgcVector3& rkB,
        MgcReal fC);

    enum Type
    {
        QST_NONE,  // the implicit equation has no solution or is a tautology
        QST_POINT,
        QST_LINE,
        QST_PLANE,
        QST_TWO_PLANES,
        QST_PARABOLIC_CYLINDER,
        QST_ELLIPTIC_CYLINDER,
        QST_HYPERBOLIC_CYLINDER,
        QST_ELLIPTIC_PARABOLOID,
        QST_HYPERBOLIC_PARABOLOID,
        QST_ELLIPTIC_CONE,
        QST_HYPERBOLOID_ONE_SHEET,
        QST_HYPERBOLOID_TWO_SHEETS,
        QST_ELLIPSOID,
        QST_MAX_TYPE
    };

    // The returned array contains the eigenvalues of A, the entries of the
    // diagonal matrix D in y^T D y + e^T x + c = 0.
    void GetCharacterization (Type& eType, MgcReal afD[3]) const;


    // Tessellation of a sphere using a 'seed' inscribed convex polyhedron.
    class Edge;
    class Triangle;
    class Vertex
    {
    public:
        MgcVector3* m_pkPoint;
        int m_iNumEdges;
        class Edge** m_apkEdge;
    };

    class Edge
    {
    public:
        Vertex* m_apkVertex[2];
        Triangle* m_apkTriangle[2];

        // For testing purposes, but not necessary for the algorithm.  This
        // allows the display program to show the subdivision structure.
        unsigned int m_uiStep;
    };

    class Triangle
    {
    public:
        // pointers to triangle vertices (counterclockwise order)
        Vertex* m_apkVertex[3];

        // triangle edges: E0 = <V0,V1>, E1 = <V1,V2>, E2 = <V2,V0>
        Edge* m_apkEdge[3];

        // adjacent triangles:  adjacent[i] shares edge[i]
        Triangle* m_apkAdjacent[3];
    };

    class ConvexPolyhedron
    {
    public:
        int m_iNumVertices;
        Vertex* m_apkVertex;

        int m_iNumEdges;
        Edge* m_apkEdge;

        int m_iNumTriangles;
        Triangle* m_apkTriangle;

        // temporary storage, average of polyhedron vertices
        MgcVector3 m_kCentroid;
    };

    static void TessellateSphere (unsigned int uiSteps,
        ConvexPolyhedron& rkPoly);
    static void DeletePolyhedron (ConvexPolyhedron& rkPoly);

protected:
    MgcMatrix3 m_kA;
    MgcVector3 m_kB;
    MgcReal m_fC;

    // support for sphere tessellation
    static int VertexIndex (const ConvexPolyhedron& rkPoly,
        const Vertex* pkV);
    static int EdgeIndex (const ConvexPolyhedron& rkPoly, const Edge* pkE);
    static int TriangleIndex (const ConvexPolyhedron& rkPoly,
        const Triangle* pkT);
    static int AdjacentOrient (const Triangle* pkT, const Triangle* pkA);
    static void ComputeCentroid (ConvexPolyhedron& rkPoly, int iNumVertices);
    static void RayIntersectSphere (const MgcVector3& rkCen,
        const MgcVector3& rkMid, MgcVector3* pkIntersect);
    static void Expand (unsigned int uiSteps, ConvexPolyhedron& rkPoly);
};

#endif

⌨️ 快捷键说明

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