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

Revision 19729, 10.7 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_MENU_H_
28 #define _TRK_CONFIG_MENU_H_
29
30 #include <sgGluiWin.h>
31 #include <trackerConfigApp.h>
32
33 //--------------- PANEL CLASS --------------------------------------
34 //
35 //: A class the creates a panel with pos and rotation information in glui
36 //
37 //------------------------------------------------------------------------
38 class posRotPanel
39 {
40 public:
41    posRotPanel(GLUI* theGlui)
42    {
43       mGLUI = theGlui;
44    }
45
46    //: Called to add the panel to the glui window
47    //! NOTE: Only call once!!!
48    //! ARGS: name - Name of the rollout
49    //! ARGS: open - Open initialy?
50    //! ARGS: spinnerCallbackId - Id passed to the callback for the spinners
51    //! ARGS: tbCallbackId - Id passed to the callback for the trackball thingie
52    //! POST: The rollout is build and added to the glui window
53    GLUI_Rollout* add_panel(char* name, bool open, int spinnerCallbackId, int tbCallbackId)
54    {
55       mRollout = mGLUI->add_rollout(name,open);
56       constructPanel(spinnerCallbackId,tbCallbackId);
57    }
58
59    //: Called to add the panel to another panel
60    //! NOTE: Only call once!!!
61    //! ARGS: panel - The panel (or rollout) to add the new rollout to
62    //! ARGS: (Same as add_panel())
63    //! POST: The rollout is built and added to the glui window
64    GLUI_Rollout* add_panel_to_panel(GLUI_Panel* panel, char* name, bool open, int spinnerCallbackId, int tbCallbackId)
65    {
66       mRollout = mGLUI->add_rollout_to_panel(panel, name, open);
67       constructPanel(spinnerCallbackId, tbCallbackId);
68    }
69
70    // Called when one of the spinners causes an event
71    //! POST: mMatrix is in sync with the new values
72    void processSpinnerEvent()
73    {
74       // Make a matrix T*R
75       vrj::Matrix rot_mat;
76       rot_mat.makeXYZEuler(mXRotSpinner->get_float_val(), mYRotSpinner->get_float_val(), mZRotSpinner->get_float_val());
77
78       mMatrix.makeTrans(mXPosSpinner->get_float_val(), mYPosSpinner->get_float_val(), mZPosSpinner->get_float_val());
79       mMatrix.postMult(rot_mat);         // xformMat = T*R
80
81       // Update the trackball with not translated version
82       mTbRotation->set_float_array_val(rot_mat.getFloatPtr());
83    }
84
85    // Called when the trackball generates an event
86    //! POST: mMatrix is in sync with the new values
87    //+       The spinners are updated with the equivalent values
88    void processTbEvent()
89    {
90       // Set mMatrix to new value
91       float m[16];
92       vrj::Matrix rot_mat;
93       mTbRotation->get_float_array_val(m);
94       rot_mat.set(m);
95
96       // Extract the individual components
97       float xr,yr,zr,xt,yt,zt;
98       rot_mat.getXYZEuler(xr,yr,zr);
99
100       // Update the spinners
101       mXRotSpinner->set_float_val(xr); mYRotSpinner->set_float_val(yr); mZRotSpinner->set_float_val(zr);
102
103       // Rebuild the full matrix
104       rot_mat.makeXYZEuler(xr,yr,zr);
105       mMatrix.makeTrans(mXPosSpinner->get_float_val(), mYPosSpinner->get_float_val(), mZPosSpinner->get_float_val());
106       mMatrix.postMult(rot_mat);         // xformMat = T*R
107    }
108
109    vrj::Matrix getMatrix()
110    { return mMatrix; }
111
112 protected:
113    // Build the panel inside the rollout
114    void constructPanel(int spinnerCallbackId, int tbCallbackId)
115    {
116       const int SpinnerWidth(20);
117       const float MinAngle(-180.0f);
118       const float MaxAngle(180.0f);
119
120       // Build Pos panel
121       mPosPanel = mGLUI->add_panel_to_panel(mRollout,"Pos");
122       mXPosSpinner = mGLUI->add_spinner_to_panel(mPosPanel,"X",GLUI_SPINNER_FLOAT,NULL,spinnerCallbackId,sgGluiWin::gluiCallback);
123       mXPosSpinner->set_alignment(GLUI_ALIGN_LEFT); mXPosSpinner->set_w(SpinnerWidth);
124       mGLUI->add_column_to_panel(mPosPanel,false);
125       mYPosSpinner = mGLUI->add_spinner_to_panel(mPosPanel,"Y",GLUI_SPINNER_FLOAT,NULL,spinnerCallbackId,sgGluiWin::gluiCallback);
126       mYPosSpinner->set_alignment(GLUI_ALIGN_LEFT); mYPosSpinner->set_w(SpinnerWidth);
127       mGLUI->add_column_to_panel(mPosPanel,false);
128       mZPosSpinner = mGLUI->add_spinner_to_panel(mPosPanel,"Z",GLUI_SPINNER_FLOAT,NULL,spinnerCallbackId,sgGluiWin::gluiCallback);
129       mZPosSpinner->set_alignment(GLUI_ALIGN_LEFT); mZPosSpinner->set_w(SpinnerWidth);
130
131       // Build Rotation panel
132       mRotPanel = mGLUI->add_panel_to_panel(mRollout,"Rot");
133       mXRotSpinner = mGLUI->add_spinner_to_panel(mRotPanel,"X",GLUI_SPINNER_FLOAT,NULL,spinnerCallbackId,sgGluiWin::gluiCallback);
134       mXRotSpinner->set_alignment(GLUI_ALIGN_LEFT); mXRotSpinner->set_w(SpinnerWidth);
135       mXRotSpinner->set_float_limits(MinAngle,MaxAngle);
136       mGLUI->add_column_to_panel(mRotPanel,false);
137       mYRotSpinner = mGLUI->add_spinner_to_panel(mRotPanel,"Y",GLUI_SPINNER_FLOAT,NULL,spinnerCallbackId,sgGluiWin::gluiCallback);
138       mYRotSpinner->set_alignment(GLUI_ALIGN_LEFT); mYRotSpinner->set_w(SpinnerWidth);
139       mYRotSpinner->set_float_limits(MinAngle,MaxAngle);
140       mGLUI->add_column_to_panel(mRotPanel,false);
141       mZRotSpinner = mGLUI->add_spinner_to_panel(mRotPanel,"Z",GLUI_SPINNER_FLOAT,NULL,spinnerCallbackId,sgGluiWin::gluiCallback);
142       mZRotSpinner->set_alignment(GLUI_ALIGN_LEFT); mZRotSpinner->set_w(SpinnerWidth);
143       mZRotSpinner->set_float_limits(MinAngle,MaxAngle);
144
145       // Build the cool panel
146       mTbPanel = mGLUI->add_panel_to_panel(mRollout,"");
147       mTbRotation = mGLUI->add_rotation_to_panel(mTbPanel,"Rot",NULL,tbCallbackId,sgGluiWin::gluiCallback);
148       mTbRotation->set_spin(0.97f);
149    }
150
151 public:
152    GLUI* mGLUI;
153
154    GLUI_Rollout* mRollout;
155    GLUI_Panel   *mPosPanel, *mRotPanel;
156    GLUI_Spinner *mXPosSpinner,*mYPosSpinner,*mZPosSpinner;
157    GLUI_Spinner *mXRotSpinner,*mYRotSpinner,*mZRotSpinner;
158
159    GLUI_Panel     *mTbPanel;
160    GLUI_Rotation  *mTbRotation, *mTbRotation2;
161
162    vrj::Matrix    mMatrix;       // Matrix of the T*R
163 };
164
165
166 //-----------------------------------------------------------------------------------
167 //: This is a base class for general glui windows.
168 //
169 // NOTE: For now this is a singleton.  Only one is allowed to be created at a time.
170 //
171 //------------------------------------------------------------------------------------
172 class trackerConfigMenu : public sgGluiWin
173 {
174 protected:
175         trackerConfigMenu() : mApp(NULL)
176         {
177                 createWindow("Configuration Information",0,900,300);
178         }
179
180         enum { modelRotCB, tmtSpinnerCB, tmtTbCB, trk1SpinnerCB, trk1TbCB, trk2SpinnerCB, trk2TbCB, wireframeCB};
181
182 public:
183                 // The interface should be created in this function.
184                 // All glui interface items should be created in this class
185         virtual void constructUI()
186         {
187                 gluiWin()->add_statictext("Positional Information");
188                 gluiWin()->add_separator();
189
190       // Model rotation
191       mModelRotation = gluiWin()->add_rotation("Model Rotation",NULL,modelRotCB,sgGluiWin::gluiCallback);
192       mModelRotation->set_spin(0.97);
193
194       // Transmitter
195       mTmtPosRot = new posRotPanel(gluiWin());
196       mTmtPosRot->add_panel("Transmitter",false,tmtSpinnerCB,tmtTbCB);
197
198       // Tracker 1
199       mTrk1PosRot = new posRotPanel(gluiWin());
200       mTrk1PosRot->add_panel("Tracker",false,trk1SpinnerCB,trk1TbCB);
201
202       // Tracker 2
203       mTrk2PosRot = new posRotPanel(gluiWin());
204       mTrk2PosRot->add_panel("Tracker Relative Proxy",false,trk2SpinnerCB,trk2TbCB);
205
206       gluiWin()->add_separator();
207       mWireframeCB =
208                         gluiWin()->add_checkbox( "Wireframe", NULL, wireframeCB, sgGluiWin::gluiCallback);
209                 gluiWin()->add_separator();             
210         }
211        
212    void updateModelMatrix()
213    {
214       float m[16];
215       vrj::Matrix rot_mat;
216       mModelRotation->get_float_array_val(m);
217       rot_mat.set(m);
218
219       mApp->setModelMatrix(rot_mat);
220    }
221
222         //: This function is called by the callback to interact with widgets
223         virtual void interact(int wId)
224         {
225                 //vprASSERT(mApp != NULL);
226                 cout << "Glui:interact: wId: " << wId << endl;
227
228                 switch(wId)
229                 {
230                 case wireframeCB:
231                         if(mWireframeCB->get_int_val() == 0)
232                                 mApp->setWireframeMode(false);
233                         else
234                                 mApp->setWireframeMode(true);
235                         break;
236                
237       // Model rotation
238       case modelRotCB:
239          updateModelMatrix();
240          break;
241
242       // Transmitter
243       case tmtSpinnerCB:
244                         mTmtPosRot->processSpinnerEvent();
245          mApp->setTransmitterPos(mTmtPosRot->getMatrix());
246          // Post redisplay to make trackball draw again.  XXX: glui bug work around
247          /*
248          int old_win = glutGetWindow();
249          glutSetWindow(gluiWin()->get_glut_window_id());
250          glutPostRedisplay();
251          glutSetWindow(old_win);
252          */
253                         break;
254       case tmtTbCB:
255          mTmtPosRot->processTbEvent();
256          mApp->setTransmitterPos(mTmtPosRot->getMatrix());
257          break;
258
259       // Tracker1
260       case trk1SpinnerCB:
261                         mTrk1PosRot->processSpinnerEvent();
262          mApp->setTrackerPos(mTrk1PosRot->getMatrix());
263                         break;
264       case trk1TbCB:
265          mTrk1PosRot->processTbEvent();
266          mApp->setTrackerPos(mTrk1PosRot->getMatrix());
267          break;
268
269       // Tracker2
270       case trk2SpinnerCB:
271                         mTrk2PosRot->processSpinnerEvent();
272          mApp->setProxyPos(mTrk2PosRot->getMatrix());
273                         break;
274       case trk2TbCB:
275          mTrk2PosRot->processTbEvent();
276          mApp->setProxyPos(mTrk2PosRot->getMatrix());
277          break;
278
279
280                 default:
281                         break;
282                 }
283         }
284
285         void setApp(trackerConfigApp* app)
286         { mApp = app; }
287
288 protected:
289         trackerConfigApp*       mApp;
290
291    GLUI_Rotation* mModelRotation;
292
293    // Tmt <--- Transmitter
294    // Trk <--- Tracker
295    posRotPanel* mTmtPosRot;
296    posRotPanel* mTrk1PosRot;
297    posRotPanel* mTrk2PosRot;
298
299    GLUI_Checkbox* mWireframeCB;
300
301                 // ---------- SINGLETON -------- //
302 public:
303                 // NOTE: When deriving subclass, override this function to create a
304                 //        New get instance.
305                 // NOTE2: This one will be that one that muiCallback uses, but that is fine
306                 //        since it will never be called with a NULL _instance
307         static trackerConfigMenu* getInstance()
308         {
309                 if(_instance == NULL)
310                         _instance = new trackerConfigMenu;
311                 return dynamic_cast<trackerConfigMenu*>(_instance);
312         }
313 };
314
315
316 #endif
Note: See TracBrowser for help on using the browser.