sphereMesh.h

Engine/source/math/util/sphereMesh.h

More...

Classes:

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _SPHEREMESH_H_
25#define _SPHEREMESH_H_
26
27#ifndef _MMATH_H_
28#include "math/mMath.h"
29#endif
30#ifndef _TVECTOR_H_
31#include "core/util/tVector.h"
32#endif
33
34//------------------------------------------------------------------------------
35// Class: SphereMesh
36//------------------------------------------------------------------------------
37// * ctor takes type of base polyhedron that is subdivided to create sphere
38// * getMesh(...) will subdivide the current mesh to the desired level where
39//   (each level has 4 times the polys of the previous level)
40
41class SphereMesh
42{
43   public:
44
45      // regular polyhedra with triangle face polygons (num of faces)
46      enum {
47         Tetrahedron = 4,
48         Octahedron = 8,
49         Icosahedron = 20,
50
51         MaxLevel       = 5
52      };
53
54      struct Triangle {
55         Triangle() {}
56         Triangle(const Point3F &a, const Point3F &b, const Point3F &c)
57         {
58            pnt[0] = a;
59            pnt[1] = b;
60            pnt[2] = c;
61         }
62
63         Point3F     pnt[3];
64         Point3F     normal;
65      };
66
67      struct TriangleMesh {
68         U32            numPoly;
69         Triangle *     poly;
70      };
71
72      SphereMesh(U32 baseType = Octahedron);
73      ~SphereMesh();
74
75      const TriangleMesh * getMesh(U32 level = 0);
76
77   private:
78
79      TriangleMesh * createTetrahedron();
80      TriangleMesh * createOctahedron();
81      TriangleMesh * createIcosahedron();
82
83      Vector<TriangleMesh*>      mDetails;
84
85      void calcNormals(TriangleMesh *);
86      TriangleMesh * subdivideMesh(TriangleMesh*);
87};
88
89#endif
90