source: GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h @ 994

Revision 994, 6.6 KB checked in by gumbau, 18 years ago (diff)

Added support for texture mapping to the GeoTool?

Line 
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
20namespace Geometry{ class LodTreeLibrary; }
21
22class 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
202        private:
203        /* Draw the cube boundaries
204         * Draw the faces of the cube using the boxv[] vertices, using
205         * GL_LINE_LOOP for the faces. The color is #defined by
206         * CUBECOLOR.
207         */
208
209        //      GeoMeshViewUI.
210        GeoMeshViewUI   *mGeoMeshViewUI;
211
212        //      LodStrips library object.
213        Geometry::LodStripsLibrary      *lodStripsLib;
214        //      LodTree library object.
215        Geometry::LodTreeLibrary        *lodTreeLib;
216       
217        //      Flag tha activate / deactivate the color strips.
218        bool    colorStripsFlag;
219
220        // Stores the index of the mesh to paint of red color.
221        int             mSubMeshSelected;
222
223        //      Frames per second.
224        size_t  mFPS;
225
226        //      StartTime for FPS.
227        clock_t mStartTime;
228
229        float           xMed;
230        float           yMed;
231        float           zMed;
232
233        int                     leavesSubMesh;
234       
235        //      Submesh count.
236        int                     mSubMeshCount;
237
238        //      Mesh to show.
239        Geometry::Mesh  *geoMesh;
240
241        // Current texture handle (OpenGL handle: 0=no texture)
242        GLuint current_texture;
243        GLuint *current_texture_submesh;
244        bool use_texture_mapping; // this flag enables texture mapping when a texture is loaded
245
246        virtual int     handle(int event);
247
248        //      Paint the mesh object.
249        void    drawGeoMesh(bool paintWire);
250        void    drawTriangleList(int submesh, bool selectedMesh, bool paintWire);
251        void    drawTriangleStrip(int submesh);
252        void    drawLodStrip();
253        void    drawLodTree();
254        void    enableColorStrips();
255        void    disableColorStrips();
256        void    enableTextureMapping(){ use_texture_mapping=true; }
257        void    disableTextureMapping(){ use_texture_mapping=false; }
258        bool    isTextureMappingEnabled(){ return use_texture_mapping; }
259        bool    getColorStrips();
260
261        //      Calculate the number of frames per second.
262        void    calcFPS();
263
264        //      Copy the mesh vertices to the vertex array.
265        void    refreshVertices(Geometry::Mesh  *geomesh);
266
267        float   vAng;
268        float   hAng;
269        float   xshift;
270        float   yshift;
271        int                     mMouseX;
272        int                     mMouseY;
273        int                     mSizeY;
274        GLfloat **mPosArray;
275        GLfloat **mNorArray;
276        GLfloat **mTexCoordArray;
277        GLfloat *mSharedPosArray;
278        GLfloat *mSharedNorArray;
279        GLfloat *mSharedTexCoordArray;
280        GLuint  **mIndexArray;
281
282        struct  ColorElement
283        {
284                float   r;
285                float   g;
286                float   b;
287        };
288
289        ColorElement    **mStripColors;
290        int                                             mStripColorsCount;
291       
292        //      Idetifier of Visualization List.
293        GLuint  mIdVisualList;
294};
295
296#endif
297
Note: See TracBrowser for help on using the repository browser.