Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
GeomUtil.h
1 //
2 // GeomUtil.h
3 //
4 // Useful classes and functions for working with geometry and meshes.
5 //
6 // Copyright (c) 2001-2011 Virtual Terrain Project
7 // Free for all uses, see license.txt for details.
8 //
9 
10 #ifndef GEOMUTILH
11 #define GEOMUTILH
12 
15 
39 {
40 public:
41  vtGeomFactory(vtGeode *pGeode, vtMesh::PrimType ePrimType,
42  int iVertType, int iMaxVertsPerMesh, int iMatIndex, int iExpectedVerts = -1);
43  vtGeomFactory(vtMesh *pMesh);
44 
45  void PrimStart();
46  void AddVertex(const FPoint3 &p);
47  void PrimEnd();
48 
49  void SetLineWidth(float width);
50  void SetMatIndex(int iIdx);
51 
52  std::vector<vtMesh*> m_Meshes;
53 
54 protected:
55  void NewMesh();
56 
57  vtGeode *m_pGeode;
58  vtMesh::PrimType m_ePrimType;
59  int m_iVertType;
60  int m_iMaxVertsPerMesh;
61  int m_iExpectedVerts;
62  int m_iMatIndex;
63 
64  vtMesh *m_pMesh;
65  int m_iPrimStart;
66  int m_iPrimVerts;
67  float m_fLineWidth;
68 
69  bool m_bSimple;
70 };
71 
72 
78 class vtDimension : public vtTransform
79 {
80 public:
81  vtDimension(const FPoint3 &p1, const FPoint3 &p2, float height,
82  const RGBf &line_color, const RGBf &text_color,
83  osgText::Font *font, const char *message);
84 
85  void SetText(const char *text);
86 
87  vtGeode *m_pGeode;
88  vtMaterialArrayPtr m_pMats;
89  vtMesh *m_pLines;
90  vtTextMesh *m_pLabel, *m_pLabel2;
91 };
92 
93 
94 // helper functions
95 vtGeode *Create3DCursor(float fSize, float fSmall, float fAlpha = 0.5f);
96 vtGeode *CreateBoundSphereGeom(const FSphere &sphere, int res = 24);
97 vtMesh *CreateSphereMesh(const FSphere &sphere, int res = 24);
98 vtGeode *CreatePlaneGeom(const vtMaterialArray *pMats, int iMatIdx,
99  int Axis1, int Axis2, int Axis3,
100  const FPoint2 &min1, const FPoint2 &max1,
101  float fTiling, int steps);
102 vtGeode *CreateBlockGeom(const vtMaterialArray *pMats, int iMatIdx,
103  const FPoint3 &size);
104 void AddLineMesh(vtGeode *pGeode, int iMatIdx, FPoint3 &p0, FPoint3 &p1);
105 vtGeode *CreateSphereGeom(const vtMaterialArray *pMats, int iMatIdx, int iVertType,
106  float fRadius, int res);
107 vtGeode *CreateCylinderGeom(const vtMaterialArray *pMats, int iMatIdx, int iVertType,
108  float hHeight, float fRadius, int res,
109  bool bTop = true, bool bBottom = true,
110  bool bCentered = true, int direction = 1);
111 vtGeode *CreateLineGridGeom(const vtMaterialArray *pMats, int iMatIdx,
112  const FPoint3 &min1, const FPoint3 &max1, int steps);
113 
129 {
130 public:
131  vtDynBoundBox(const RGBf &color);
132  void SetBox(const FBox3 &box);
133  vtGeode *pGeode;
134  vtMesh *pMesh;
135 };
136 
137 // Writing Wavefront OBJ format
138 struct vtOBJFile
139 {
140  FILE *fp;
141  int verts_written;
142 };
143 vtOBJFile *OBJFileBegin(vtGeode *geode, const char *filename);
144 void OBJFileWriteGeom(vtOBJFile *file, vtGeode *geode);
145 bool WriteGeomToOBJ(vtGeode *geode, const char *filename);
146  // Group sg
148 
149 #endif // GEOMUTILH
150