1 /* Copyright (c) 2015 Gerald Knizia 2 * 3 * This file is part of the IboView program (see: http://www.iboview.org) 4 * 5 * IboView is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, version 3. 8 * 9 * IboView is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/ 16 * 17 * Please see IboView documentation in README.txt for: 18 * -- A list of included external software and their licenses. The included 19 * external software's copyright is not touched by this agreement. 20 * -- Notes on re-distribution and contributions to/further development of 21 * the IboView software 22 */ 23 24 #ifndef GL_MESH_H 25 #define GL_MESH_H 26 27 #include "Iv.h" 28 29 typedef unsigned int 30 FIndexType; // <- type we'll use for our index buffers. 31 32 // a basic vertex: position, normal, and color. 33 struct FBaseVertex { 34 vec3f vPos; 35 vec3f vNorm; 36 uint32_t dwColor; 37 uint32_t iRole; // used to distinguish sub-surfaces. don't ask. 38 static void AssignVertexAttributes(); 39 }; 40 41 42 // direct, non-indexed triangle. 43 struct FTriangle1 { 44 FVec3d v[3]; FTriangle1FTriangle145 FTriangle1() {}; FTriangle1FTriangle146 FTriangle1(FVec3d v0, FVec3d v1, FVec3d v2) { v[0] = v0; v[1] = v1; v[2] = v2; }; 47 }; 48 49 // convert list of explicit triangles to indexed triangles. 50 void MakeIndexedTriangles(ct::TArray<FVec3d> &PosOut, ct::TArray<unsigned> &Indices, ct::TArray<FTriangle1> const &TrianglesIn); 51 52 53 template<class FVertex> 54 struct TIndexedTriangleList : public ct::FIntrusivePtrDest { 55 ct::TArray<FVertex> 56 Vertices; 57 ct::TArray<vec3ui> 58 Triangles; TIndexedTriangleListTIndexedTriangleList59 TIndexedTriangleList() {}; 60 61 // construct from list of vertex positions, vertex normals, and indices 62 TIndexedTriangleList(FVec3d *Pos, FVec3d *Norm, size_t nVertices, unsigned *Indices, size_t nIndices, FVertex const &RefVertex); 63 64 // append triangles of other list to this one. 65 void Append(TIndexedTriangleList const &Other); 66 }; 67 typedef TIndexedTriangleList<FBaseVertex> 68 FIndexedTriangleList; 69 70 typedef boost::intrusive_ptr<FIndexedTriangleList> 71 FIndexedTriangleListPtr; 72 73 74 // make a sphere at vPos, with radius fRadius, by subdividing an icosahedron. 75 // Number of triangles is 20 * (4^nSubDivLevel). 76 // Basic vertex attributes (i.e., everything excelt for position and normal) are copied from RefVertex. 77 FIndexedTriangleListPtr MakeSubdivSphere(vec3f vPos, float fRadius, uint nSubDivLevel, FBaseVertex const &RefVertex); 78 // make a cylinder oriented along the Z axis, with radius fBaseRadius at z=0 and fTopRadius at z=Height. 79 FIndexedTriangleListPtr MakeCylinder(float fBaseRadius, float fTopRadius, float fHeight, uint nSlices, FBaseVertex const &RefVertex); 80 // similar to MakeSubdivSphere with nSubDivLevel = 0, but creates hard vertex normals. 81 FIndexedTriangleListPtr MakeIcosahedron(float fRadius, FBaseVertex const &RefVertex); 82 83 84 85 86 87 88 #endif // GL_MESH_H 89