1 | // generated by Fast Light User Interface Designer (fluid) version 2.0100 |
---|
2 | #ifndef GeoMeshView_h |
---|
3 | #define GeoMeshView_h |
---|
4 | #include "GL/glew.h" |
---|
5 | #ifdef _WIN32 |
---|
6 | #include "GL/wglew.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #include <fltk/events.h> |
---|
10 | #include <stdlib.h> |
---|
11 | #include <time.h> |
---|
12 | #include <iostream> |
---|
13 | #include <glut.h> |
---|
14 | #include <fltk/GlWindow.h> |
---|
15 | #include <GeoVertexBuffer.h> |
---|
16 | #include <GeoMesh.h> |
---|
17 | #include <GeoMeshSaver.h> |
---|
18 | #include <GeoMeshViewUI.h> |
---|
19 | |
---|
20 | namespace Geometry{ class LodTreeLibrary; } |
---|
21 | |
---|
22 | class GeoMeshView : public fltk::GlWindow |
---|
23 | { |
---|
24 | friend class GeoMeshViewUI; |
---|
25 | |
---|
26 | public: |
---|
27 | |
---|
28 | // this value determines the scaling factor used to draw the cube. |
---|
29 | double size; |
---|
30 | double mScaleFactor; |
---|
31 | bool mWire; |
---|
32 | bool mSolid; |
---|
33 | bool mCW; |
---|
34 | bool mCCW; |
---|
35 | bool mPan; |
---|
36 | bool mRotate; |
---|
37 | bool mLodStrip; |
---|
38 | bool mLodTree; |
---|
39 | |
---|
40 | GeoMeshView(int x, |
---|
41 | int y, |
---|
42 | int w, |
---|
43 | int h, |
---|
44 | const char *l = 0, |
---|
45 | GeoMeshViewUI *geoMeshViewUI = 0); |
---|
46 | |
---|
47 | /* This function is callalled by the zoom slider |
---|
48 | * |
---|
49 | */ |
---|
50 | void scale(double factor){size = factor;}; |
---|
51 | |
---|
52 | /* Set the rotation about the vertical (y ) axis. |
---|
53 | * |
---|
54 | * This function is called by the horizontal roller in GeoMeshViewUI |
---|
55 | * and the initialize button in GeoMeshViewUI. |
---|
56 | */ |
---|
57 | void v_angle(float angle){vAng=angle;}; |
---|
58 | |
---|
59 | // Return the rotation about the vertical (y ) axis. |
---|
60 | float v_angle(){return vAng;}; |
---|
61 | |
---|
62 | /* Set the rotation about the horizontal (x ) axis. |
---|
63 | * |
---|
64 | * This function is called by the vertical roller in GeoMeshViewUI |
---|
65 | and the |
---|
66 | * initialize button in GeoMeshViewUI. |
---|
67 | */ |
---|
68 | void h_angle(float angle){hAng=angle;}; |
---|
69 | |
---|
70 | // the rotation about the horizontal (x ) axis. |
---|
71 | float h_angle(){return hAng;}; |
---|
72 | |
---|
73 | /* Sets the x shift of the cube view camera. |
---|
74 | * |
---|
75 | * This function is called by the slider in GeoMeshViewUI and the |
---|
76 | * initialize button in GeoMeshViewUI. |
---|
77 | */ |
---|
78 | void panx(float x){xshift=x;}; |
---|
79 | |
---|
80 | /* Sets the y shift of the cube view camera. |
---|
81 | * |
---|
82 | * This function is called by the slider in GeoMeshViewUI and the |
---|
83 | * initialize button in GeoMeshViewUI. |
---|
84 | */ |
---|
85 | void pany(float y){yshift=y;}; |
---|
86 | |
---|
87 | // Wire model. |
---|
88 | void activeWire(){mWire = true;}; |
---|
89 | void deactiveWire(){mWire = false;}; |
---|
90 | |
---|
91 | // Solid model. |
---|
92 | void activeSolid(){mSolid = true;}; |
---|
93 | void deactiveSolid(){mSolid = false;}; |
---|
94 | |
---|
95 | // Clockwise mode. |
---|
96 | void activeCW(){mCW = true;}; |
---|
97 | void deactiveCW(){mCW = false;}; |
---|
98 | |
---|
99 | // Counter Clockwise mode. |
---|
100 | void activeCCW(){mCCW = true;} |
---|
101 | void deactiveCCW(){mCCW = false;} |
---|
102 | |
---|
103 | // Pan mode. |
---|
104 | void activePan(){mPan = true;} |
---|
105 | void deactivePan(){mPan = false;} |
---|
106 | |
---|
107 | // Rotate mode. |
---|
108 | void activeRotate(){mRotate = true;} |
---|
109 | void deactiveRotate(){mRotate = false;} |
---|
110 | |
---|
111 | // LodStrip mode. |
---|
112 | void activeLodStrip(){mLodStrip = true;} |
---|
113 | void deactiveLodStrip(){mLodStrip = false;} |
---|
114 | |
---|
115 | // LodTree mode. |
---|
116 | void activeLodTree(){mLodTree = true;} |
---|
117 | void deactiveLodTree(){mLodTree = false;} |
---|
118 | |
---|
119 | |
---|
120 | // Ilumination modes. |
---|
121 | void flat(){glShadeModel(GL_FLAT);}; |
---|
122 | void smooth(){glShadeModel(GL_SMOOTH);}; |
---|
123 | |
---|
124 | // Change Open GL context. |
---|
125 | #ifdef _WIN32 |
---|
126 | HDC hOldDC; |
---|
127 | HGLRC hOldRC; |
---|
128 | #endif |
---|
129 | void saveContext() |
---|
130 | { |
---|
131 | #ifdef _WIN32 |
---|
132 | hOldDC = wglGetCurrentDC(); |
---|
133 | hOldRC = wglGetCurrentContext(); |
---|
134 | #endif |
---|
135 | } |
---|
136 | void restoreContext() |
---|
137 | { |
---|
138 | #ifdef _WIN32 |
---|
139 | wglMakeCurrent( hOldDC, hOldRC ); |
---|
140 | #endif |
---|
141 | } |
---|
142 | |
---|
143 | // Fits the object in the window view. |
---|
144 | void fit() |
---|
145 | { |
---|
146 | vAng = 0.0; |
---|
147 | hAng = 0.0; |
---|
148 | size = 0.0; |
---|
149 | xshift = 0.0; |
---|
150 | yshift = 0.0; |
---|
151 | }; |
---|
152 | |
---|
153 | /* Sets the Mesh to display. |
---|
154 | */ |
---|
155 | void setMesh(Geometry::Mesh *geomesh); |
---|
156 | |
---|
157 | /* The widget class draw() override. |
---|
158 | * The draw() function initialize Gl for another round of |
---|
159 | * drawing then calls specialized functions for drawing each |
---|
160 | * of the entities displayed in the cube view. |
---|
161 | */ |
---|
162 | void draw(); |
---|
163 | |
---|
164 | // Gets the bounding box. |
---|
165 | //Geometry::GeometryBounds getBoundingBox(); |
---|
166 | |
---|
167 | // Store one random color to each strip. |
---|
168 | void setStripColors(); |
---|
169 | |
---|
170 | // Get the number of frames per second. |
---|
171 | size_t getFPS(); |
---|
172 | |
---|
173 | // Sets the submesh selected. |
---|
174 | void setSubMeshSelected(int submeshIndex); |
---|
175 | |
---|
176 | // Sets the leaves submesh index. |
---|
177 | void setLeavesSubMesh(int submeshIndex); |
---|
178 | |
---|
179 | // Gets the leaves submesh index. |
---|
180 | int getLeavesSubMesh(); |
---|
181 | |
---|
182 | // Gets the triangle count of the current lod. |
---|
183 | size_t getLodStripsTriangleCount(); |
---|
184 | |
---|
185 | // Sets the lodstripslibrary object. |
---|
186 | void setLodStripsLibrary(Geometry::LodStripsLibrary *lodstrips); |
---|
187 | |
---|
188 | // Sets the lodtreeslibrary object. |
---|
189 | void setLodTreesLibrary(Geometry::LodTreeLibrary *lodtrees); |
---|
190 | |
---|
191 | // Change de Level of detail of the object. |
---|
192 | void GoToLod_LodStrip(unsigned int lod); |
---|
193 | void GoToLod_LodTree(unsigned int lod); |
---|
194 | |
---|
195 | // load a image file as a texture |
---|
196 | void LoadTexture(const char *); |
---|
197 | void LoadTextureSubMesh(int isubmesh, const char *); |
---|
198 | |
---|
199 | int getSubMeshCount(void) const { return mSubMeshCount; } |
---|
200 | void resetTextures(void); |
---|
201 | int findLeavesSubMesh(void); |
---|
202 | |
---|
203 | private: |
---|
204 | /* Draw the cube boundaries |
---|
205 | * Draw the faces of the cube using the boxv[] vertices, using |
---|
206 | * GL_LINE_LOOP for the faces. The color is #defined by |
---|
207 | * CUBECOLOR. |
---|
208 | */ |
---|
209 | |
---|
210 | // GeoMeshViewUI. |
---|
211 | GeoMeshViewUI *mGeoMeshViewUI; |
---|
212 | |
---|
213 | // LodStrips library object. |
---|
214 | Geometry::LodStripsLibrary *lodStripsLib; |
---|
215 | // LodTree library object. |
---|
216 | Geometry::LodTreeLibrary *lodTreeLib; |
---|
217 | |
---|
218 | // Flag tha activate / deactivate the color strips. |
---|
219 | bool colorStripsFlag; |
---|
220 | |
---|
221 | // Stores the index of the mesh to paint of red color. |
---|
222 | int mSubMeshSelected; |
---|
223 | |
---|
224 | // Frames per second. |
---|
225 | size_t mFPS; |
---|
226 | |
---|
227 | // StartTime for FPS. |
---|
228 | clock_t mStartTime; |
---|
229 | |
---|
230 | float xMed; |
---|
231 | float yMed; |
---|
232 | float zMed; |
---|
233 | |
---|
234 | int leavesSubMesh; |
---|
235 | |
---|
236 | // Submesh count. |
---|
237 | int mSubMeshCount; |
---|
238 | |
---|
239 | // Mesh to show. |
---|
240 | Geometry::Mesh *geoMesh; |
---|
241 | |
---|
242 | // Current texture handle (OpenGL handle: 0=no texture) |
---|
243 | GLuint current_texture; |
---|
244 | GLuint *current_texture_submesh; |
---|
245 | bool use_texture_mapping; // this flag enables texture mapping when a texture is loaded |
---|
246 | bool SetTextureRenderingState(int submesh); // returns true if textures must be used |
---|
247 | |
---|
248 | virtual int handle(int event); |
---|
249 | |
---|
250 | // Paint the mesh object. |
---|
251 | void drawGeoMesh(bool paintWire); |
---|
252 | void drawTriangleList(int submesh, bool selectedMesh, bool paintWire); |
---|
253 | void drawTriangleStrip(int submesh); |
---|
254 | void drawLodStrip(); |
---|
255 | void drawLodTree(); |
---|
256 | void enableColorStrips(); |
---|
257 | void disableColorStrips(); |
---|
258 | void enableTextureMapping(){ use_texture_mapping=true; } |
---|
259 | void disableTextureMapping(){ use_texture_mapping=false; } |
---|
260 | bool isTextureMappingEnabled(){ return use_texture_mapping; } |
---|
261 | bool getColorStrips(); |
---|
262 | |
---|
263 | // Calculate the number of frames per second. |
---|
264 | void calcFPS(); |
---|
265 | |
---|
266 | // Copy the mesh vertices to the vertex array. |
---|
267 | void refreshVertices(Geometry::Mesh *geomesh); |
---|
268 | |
---|
269 | float vAng; |
---|
270 | float hAng; |
---|
271 | float xshift; |
---|
272 | float yshift; |
---|
273 | int mMouseX; |
---|
274 | int mMouseY; |
---|
275 | int mSizeY; |
---|
276 | GLfloat **mPosArray; |
---|
277 | GLfloat **mNorArray; |
---|
278 | GLfloat **mTexCoordArray; |
---|
279 | GLfloat *mSharedPosArray; |
---|
280 | GLfloat *mSharedNorArray; |
---|
281 | GLfloat *mSharedTexCoordArray; |
---|
282 | GLuint **mIndexArray; |
---|
283 | |
---|
284 | struct ColorElement |
---|
285 | { |
---|
286 | float r; |
---|
287 | float g; |
---|
288 | float b; |
---|
289 | }; |
---|
290 | |
---|
291 | ColorElement **mStripColors; |
---|
292 | int mStripColorsCount; |
---|
293 | |
---|
294 | // Idetifier of Visualization List. |
---|
295 | GLuint mIdVisualList; |
---|
296 | }; |
---|
297 | |
---|
298 | #endif |
---|
299 | |
---|