root/juggler/branches/2.2/modules/vrjuggler/tools/trackerConfigApp.h

Revision 19729, 9.5 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27 #ifndef _TRK_CONFIG_APP_H_
28 #define _TRK_CONFIG_APP_H_
29
30 #include <sgGlutApp.h>
31 #include <sgGlutWin.h>
32 #include <sgDrawFunctor.h>
33
34 //#include <sgTbXformer.h>
35
36 class trackerConfigApp : public sgGlutApp, public sgDrawFunctor
37 {
38 protected:
39         trackerConfigApp()
40         {
41                 init();
42         }
43
44 public:
45        
46         void init()
47         {
48                         // -- Setup Trackball -- //
49                 //trackBall.setRootNode(rootNode);
50                 //trackBall.setDCS(rootDCS);           
51
52       // -- Initialize state //
53       mDrawWireFrame = false;
54       mTransmitterPos.makeIdent();
55         }
56        
57        
58         // function to do setup needed after windows have been allocated.
59         // PRE: win array has values in it.
60         void initWindows()
61         {
62                 winHandles[0] = createNewGlutWin(50, 50, 500, 500, "Tracker Configuration");
63                
64                 int winHndl = winHandles[0];
65                 win[winHndl]->getChan()->setDrawFunc(this);        // We are the draw function
66       win[winHndl]->chan.setFov(60.0f);
67                 win[winHndl]->chan.setNearFar(0.1, 1000.0f);
68       win[winHndl]->chan.setView(vrj::Vec3(0.0f, -5.0f, -20.0f), vrj::Vec3(0.0f, -45.0f, 0.0f));
69                 //**//win[winHndl]->chan.setView(sgVec3(0.0, 0.0, 20.0), sgVec3(0.0, 0.0, 0.0));
70                 
71                         // Set the trackballs input
72                 //trackBall.setMouseInput(&(win[winHndl]->input));
73         }
74
75         virtual void appFunc()
76         {
77                 // Do my updates
78         }
79
80    // Define what to do when drawing
81    //
82    // Draw function for sgDrawFunctor
83    virtual void draw(sgChan* chan)
84    {
85       // Set base model matrix
86       glPushMatrix();
87          vrj::Matrix model_dcs; model_dcs = getModelMatrix();
88          glMultMatrixf(model_dcs.getFloatPtr());
89
90          // Draw a base system XXX: In future this should come from a config file or something
91          glPushMatrix();
92             drawBaseSystem();
93          glPopMatrix();
94
95          // ----- TRANSMITTER ------ //
96          const vrj::Vec3 TmtCubeColor(0.0,1.0,1.0f);
97          const float TmtCubeSize(1.0f);
98          glPushMatrix();
99             glMultMatrixf(mTransmitterPos.getFloatPtr());
100             glColor3fv(TmtCubeColor.vec);
101             drawWireCube(TmtCubeSize);
102             drawAxis(2.0f,0.8f,2.5f);
103          glPopMatrix();
104
105          // ----- TRACKER ------ //
106          const vrj::Vec3 TrkCubeColor(1.0,1.0,0.0f);
107          const float TrkCubeSize(0.20f);
108          glPushMatrix();
109             glMultMatrixf(mTrackerPos.getFloatPtr());
110             glColor3fv(TrkCubeColor.vec);
111             drawWireCube(TrkCubeSize);
112             drawAxis(2.0f,0.6f,1.5f);
113
114              // ----- PROXY ------ //
115             const vrj::Vec3 PxyCubeColor(1.0,0.0,1.0f);
116             const float PxyCubeSize(0.20f);
117             glPushMatrix();
118                glMultMatrixf(mProxyPos.getFloatPtr());
119                glColor3fv(PxyCubeColor.vec);
120                drawWireCube(PxyCubeSize);
121                drawAxis(4.0f,0.95f,0.75f);
122             glPopMatrix();
123
124          glPopMatrix();
125
126       glPopMatrix();    // Model matrix
127    }
128
129    void drawBaseSystem()
130    {
131       const float CubeSize(10.0f);     // Size of the system to draw
132       const vrj::Vec3 CubeColor(0.8f,0.8f,0.8f);
133
134       drawAxis(1.0f, 0.5, 1.5f);
135       glPushMatrix();
136          glTranslatef(0.0, CubeSize/2.0f, 0.0f);
137          glColor3fv(CubeColor.vec);
138          drawWireCube(CubeSize);
139       glPopMatrix();
140    }
141
142         virtual void preDraw()
143         {
144                 //cout << "----------- PreDraw -----------" << endl << flush;
145
146                 //glEnable(GL_CULL_FACE);
147                 glDisable(GL_CULL_FACE);
148                
149                 if(mDrawWireFrame)
150                         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
151                 else
152                         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
153
154                 glEnable(GL_DEPTH_TEST);
155
156                         // --- LIGHT --- //
157                 //sgVec4 specular(1.0, 1.0, 1.0, 1.0);
158                 //float shininess = 15.0;
159                 //sgVec4 lightPos(0.0, 1.0, 1.0, 0.0);
160
161                 //glMaterialfv(GL_FRONT, GL_SPECULAR, specular.vec);
162                 //glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);
163                 //glLightfv(GL_LIGHT0, GL_POSITION, lightPos.vec);
164
165                 //glEnable(GL_LIGHTING);
166                 //glEnable(GL_LIGHT0);
167         }
168
169         virtual void postDraw()
170         {
171                 //**//trackBall.update();
172         }
173
174 public: // State interface //
175         void setWireframeMode(bool mode)
176         { mDrawWireFrame = mode; }
177
178    vrj::Matrix getTransmitterPos()
179    { return mTransmitterPos; }
180    void setTransmitterPos(vrj::Matrix mat)
181    { mTransmitterPos = mat; }
182
183    // Used to get a to the correct model view
184    vrj::Matrix getModelMatrix()
185    { return mModelRotation; }
186    void setModelMatrix(vrj::Matrix mat)
187    { mModelRotation = mat; }
188
189    vrj::Matrix getTrackerPos()
190    { return mTrackerPos; }
191    void setTrackerPos(vrj::Matrix mat)
192    { mTrackerPos = mat; }
193
194    vrj::Matrix getProxyPos()
195    { return mProxyPos; }
196    void setProxyPos(vrj::Matrix mat)
197    { mProxyPos = mat; }
198
199
200 private: // State vars //
201         bool        mDrawWireFrame;
202    vrj::Matrix    mModelRotation;      // Updated by menu system
203    vrj::Matrix    mTransmitterPos;     // Position of transmitter
204    vrj::Matrix    mTrackerPos;         // Position of a tracker
205    vrj::Matrix    mProxyPos;           // Tracker proxy relative to tracker
206
207 protected:     // --- Geom helpers --- //
208    void initQuadObj();
209    void drawLine(vrj::Vec3& start, vrj::Vec3& end);
210    void drawSphere(float radius, int slices, int stacks);
211    void drawCone(float base, float height, int slices, int stacks);
212    void drawCube(float size, GLenum type);
213    void drawWireCube(float size);
214    void drawSolidCube(float size);
215    // Draw a set of axis
216    void drawAxis(float lineWidth=1.0f, float brightness=1.0f, float scale=1.0f);
217
218    GLUquadricObj* mQuadObj;
219        
220 public:
221    //sgTbXformer        trackBall;              // Trackball xformer
222
223         int   winHandles[10];
224
225 public:
226         static trackerConfigApp*        getInstance()
227         {
228                 if(_instance == NULL)
229                         _instance = new trackerConfigApp;               // Allocate an object
230
231                 return dynamic_cast<trackerConfigApp*>(_instance);
232         }
233 };
234
235 ////////////////////////////////////////////////////////////////////////////////////////
236 ////////////////////////////////////////////////////////////////////////////////////////
237 ////////////////////////////////////////////////////////////////////////////////////////
238
239
240
241 // Draw a set of axis
242 void trackerConfigApp::drawAxis(float lineWidth, float brightness, float scale)
243 {
244    vrj::Vec3 x_axis(scale,0.0f,0.0f);
245    vrj::Vec3 y_axis(0.0f, scale, 0.0f);
246    vrj::Vec3 z_axis(0.0f, 0.0f, scale);
247    vrj::Vec3 origin(0.0f, 0.0f, 0.0f);
248
249    glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_LINE_BIT);
250    glDisable(GL_LIGHTING);
251    glLineWidth(lineWidth);
252    glPushMatrix();
253       glBegin(GL_LINES);
254          glColor3f(brightness, 0.0f, 0.0f);
255          glVertex3fv(origin.vec);
256          glVertex3fv(x_axis.vec);
257
258          glColor3f(0.0f, brightness, 0.0f);
259          glVertex3fv(origin.vec);
260          glVertex3fv(y_axis.vec);
261
262          glColor3f(0.0f, 0.0f, brightness);
263          glVertex3fv(origin.vec);
264          glVertex3fv(z_axis.vec);
265       glEnd();
266    glPopMatrix();
267
268    glPopAttrib();
269 }
270
271 void trackerConfigApp::initQuadObj()
272 {
273    if (mQuadObj == NULL)
274       mQuadObj = gluNewQuadric();
275 }
276
277 void trackerConfigApp::drawLine(vrj::Vec3& start, vrj::Vec3& end)
278 {
279    glBegin(GL_LINES);
280       glVertex3fv(start.vec);
281       glVertex3fv(end.vec);
282    glEnd();
283 }
284
285 void trackerConfigApp::drawSphere(float radius, int slices, int stacks)
286 {
287   initQuadObj();
288   gluQuadricDrawStyle(mQuadObj, (GLenum) GLU_FILL);
289   gluQuadricNormals(mQuadObj, (GLenum) GLU_SMOOTH);
290   gluSphere(mQuadObj, radius, slices, stacks);
291 }
292
293
294 void trackerConfigApp::drawCone(float base, float height, int slices, int stacks)
295 {
296   initQuadObj();
297   gluQuadricDrawStyle(mQuadObj, (GLenum) GLU_FILL);
298   gluQuadricNormals(mQuadObj, (GLenum) GLU_SMOOTH);
299   gluCylinder(mQuadObj, base, 0.0, height, slices, stacks);
300 }
301
302
303
304 void trackerConfigApp::drawCube(float size, GLenum type)
305 {
306   static GLfloat n[6][3] =
307   {
308     {-1.0, 0.0, 0.0},
309     {0.0, 1.0, 0.0},
310     {1.0, 0.0, 0.0},
311     {0.0, -1.0, 0.0},
312     {0.0, 0.0, 1.0},
313     {0.0, 0.0, -1.0}
314   };
315
316   static GLint faces[6][4] =
317   {
318     {0, 1, 2, 3},
319     {3, 2, 6, 7},
320     {7, 6, 5, 4},
321     {4, 5, 1, 0},
322     {5, 6, 2, 1},
323     {7, 4, 0, 3}
324   };
325   GLfloat v[8][3];
326   GLint i;
327
328   v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
329   v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
330   v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
331   v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
332   v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
333   v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;
334
335   for (i = 5; i >= 0; i--) {
336     glBegin(type);
337     glNormal3fv(&n[i][0]);
338     glVertex3fv(&v[faces[i][0]][0]);
339     glVertex3fv(&v[faces[i][1]][0]);
340     glVertex3fv(&v[faces[i][2]][0]);
341     glVertex3fv(&v[faces[i][3]][0]);
342     glEnd();
343   }
344 }
345
346 void trackerConfigApp::drawWireCube(float size)
347 {
348   drawCube(size, GL_LINE_LOOP);
349 }
350
351 void trackerConfigApp::drawSolidCube(float size)
352 {
353   drawCube(size, GL_QUADS);
354 }
355
356
357 #endif
358
Note: See TracBrowser for help on using the browser.