Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

glvu.hpp

00001 //============================================================================
00002 // glvu.hpp : OpenGL/GLUT -based viewer
00003 //============================================================================
00004 
00005 #ifndef _GLVU_
00006 #define _GLVU_
00007 
00008 #include <stdlib.h>
00009 #include <time.h>            // FOR TIMED PATH PLAYBACK (glvu_camview)
00010 #include <sys/timeb.h>       // FOR FRAME TIMING (glvu_camview)
00011 #include <GL/glut.h>
00012 #include <vec3f.hpp>
00013 #include <camera.hpp>
00014 
00015 #ifndef ABS
00016 #define ABS(x) (((x)<0)?(-(x)):x)    // HANDY UNIVERSAL ABSOLUTE VALUE FUNC
00017 #endif
00018 #define INERTIA_MINMOVE 2            // AMOUNT (in pixels) TO MOVE TO INVOKE INERTIAL SYSTEM
00019 #define MAX_GLVUS 33                 // MAX NUMBER OF WINDOWS PLUS 1 SUPPORTED IN ONE APP
00020 #define FPS_INTEGRATE_INTERVAL 1.0f // MINIMUM NUMBER OF SECONDS TO INTEGRATE FRAME-RATE OVER
00021 
00072 class GLVU
00073 {
00074   public:
00075 
00077 
00080     enum WorldNavMode{
00081       NAV_MODE_TRACKBALL, 
00082       NAV_MODE_HYPERBALL,
00083       NAV_MODE_DRIVE, 
00084       NAV_MODE_TRANSLATE, 
00085       NAV_MODE_LOOK
00086     };
00087 
00090     enum CameraID
00091     {
00092       CAMERA_1,
00093       CAMERA_2,
00094       CAMERA_3,
00095       CAMERA_4,
00096       CAMERA_NUM_CAMS
00097     };
00098   
00100     typedef void (*InertiaFunc)(int x, int y);
00101 
00102     GLVU();
00103     virtual ~GLVU();
00104     int Init(char *WindowTitle, 
00105              unsigned int VisualMode,
00106              int WindowStartX, int WindowStartY,
00107              int WindowWidth, int WindowHeight);
00108     virtual int InitWin(int aPreviouslyCreatedGlutWindow);
00109     void BeginFrame();
00110     void EndFrame();
00111 
00112     // CAMVIEW
00113     int GetPlaybackOn() const;
00114     int GetRecordingOn() const;
00115      
00116     // CAMVIEW
00117     void SetAllCams(const Vec3f& WorldMin, const Vec3f& WorldMax, 
00118                     const Vec3f& Eye, const Vec3f& LookAtCntr, 
00119                     const Vec3f& viewup,
00120                     float Yfov, float Aspect, 
00121                     float NearFactor, float FarFactor);
00122     void AllCamsPerspectiveChange(float Yfov, float Aspect, 
00123                                  float Ndist, float Fdist);
00124     void AllCamsPerspectiveAspectChange(float Aspect);
00125     void AllCamsResetToOrig();
00126     float* GetModelviewMatrix(float* M);
00127     float* GetProjectionMatrix(float* M);
00128     void GetPixelRay(int sx, int sy, int ww, int wh, Vec3f *Start, Vec3f *Dir)
00129       const;
00130     void SelectCam(int WhichCam);
00131     Camera* GetCurrentCam();
00132     void SetCurrentCam(Camera *NewCam);
00133     Camera* GetCam(int WhichCam);
00134     int GetInOutMode() const;
00135     void SetInOutMode(int Bool);
00136     void ToggleInOutMode();
00137     void SetOrigCam(Camera *Cam);
00138     const Vec3f& GetViewUp() const ;
00139     const Vec3f& GetWorldCenter() const ;
00140     void SetWorldCenter(const Vec3f& newCenter);
00141     float GetWorldRadius() const ;
00142     void SetWorldRadius(float newRadius) ;
00143     void SetViewUp(Vec3f viewup) ;
00144     void SetMoveSpeed(float speed) ;
00145     void TranslateX(int OldX, int NewX, int WW);
00146     void TranslateY(int OldY, int NewY, int WH);
00147     void DriveY(int OldY, int NewY, int WH);
00148     void LookX(int OldX, int NewX, int WW);
00149     void LookY(int OldY, int NewY, int WH);
00150     void TrackBallX(int OldX, int NewX, int WW);
00151     void TrackBallY(int OldY, int NewY, int WH);
00152     void HyperBall(int OldX, int OldY, int NewX, int NewY,int WW, int WH);
00153     void StartRecording(const char *FileName = "path0.dat");
00154     void EndRecording();
00155     void StartPlayback(const char *FileName = "path0.dat");
00156     void EndPlayback();
00157     void StopRecordingPlayback();
00158     void StartFPSClock() ;
00159     void StopFPSClock() ;
00160     void DrawFPS(int xpos = 5, int ypos = 5);
00161     float GetFPS() const ;
00162     void UpdateFPS();  // USE ONLY IF YOU DO NOT CALL GLVU::BeginFrame()
00163 
00164     // MENU
00165     int GetMainMenuID() const ;
00166     int GetWorldNavMode() const ;
00167     void SetWorldNavMode(int mode) ;
00168     int GetCamDisplayOn(int WhichCam) const ;
00169     int IsWorldNavMode() const ;
00170 
00171     // MOUSE
00172     int GetLeftButtonDown() const ;
00173     int GetInertiaOn() const ; 
00174     int GetInertiaEnabled() const ;
00175     void SetInertiaOn(int Bool);
00176     void SetInertiaEnabled(int Bool) ;
00177     int GetInertiaDelay() const ; 
00178     void SetInertiaDelay(int msec) ;
00179     void SetInertiaFunc(InertiaFunc f) ; 
00180     InertiaFunc GetInertiaFunc() const;
00181 
00182     // DEFAULT CALLBACK FUNCTIONS (MOSTLY JUST CALL THE CALLBACK METHODS)
00183     static void DefaultMouseFunc(int button, int state, int x, int y);
00184     static void DefaultMotionFunc(int x, int y);
00185     static void DefaultReshapeFunc(int WW, int WH);
00186     static void DefaultDisplayFunc();
00187     static void DefaultKeyboardFunc(unsigned char Key, int x, int y);
00188     static void DefaultInertiaFunc(int x, int y);
00189   
00190     // CALLBACK METHODS
00191     virtual void Mouse(int button, int state, int x, int y);
00192     virtual void Motion(int x, int y);
00193     virtual void Reshape(int WW, int WH);
00194     virtual void Display() ;
00195     virtual void Keyboard(unsigned char Key, int x, int y);
00196     virtual void Inertia(int x, int y);
00197 
00198     // MISC
00199     int GetWindowID() const;
00200     void MakeCurrent();
00201     static GLVU* GetCurrent();
00202     static GLVU* GetGLVU(int WindowID);
00203     static GLVU* GetGLVU(); // deprecated
00204     static void PrintVisualInfo();
00205 
00206 
00207   protected:
00208 
00209     // GL VIEWER STATE VARIABLES
00210     Camera *Cams;                // ARRAY OF 4 VIEWER CAMS
00211     Camera *Cam;                 // PTR TO CURRENT CAM (DEFAULT IS CAM 0)
00212     Camera OrigCam;              // THE ORIGINAL VIEW FOR RESETTING
00213     int RecordingOn, PlaybackOn; // CAMERA RECORDING/PLAYBACK FLAGS
00214     FILE *RecordPlaybackFP;      // RECORDING/PLAYBACK FILE POINTER
00215     Vec3f WorldCenter;           // WORLD BOUNDING-SPHERE CENTER
00216     float WorldRadius;           // WORLD BOUNDING-SPHERE RADIUS
00217     Vec3f ViewUp;                // THE WORLD UP-VECTOR
00218     int InsideLookingOutMode;    // NAVIGATION MODE (IN->OUT OR OUT->IN)
00219     clock_t PlaybackTime;        // FOR PATH PLAYBACK TIMING
00220     int NumCams;
00221     struct timeb lastFPSClock;
00222     int calcFPS;
00223     float lastFPS;
00224     int lastFPSCount;
00225 
00226     int LeftButtonDown;
00227     int OldX, OldY, NewX, NewY;  // CURRENT OLD AND NEW MOUSE POSITIONS
00228     float moveSpeed;
00229     int CtrlPressed;
00230     int InertiaOn, InertiaEnabled;
00231     int InertiaDelay;
00232 
00233     int MainMenuID;              // GLUT MAIN MENU ID
00234     int WorldNavMode;            // WORLD NAVIGATION MODE
00235     int *CamDisplayOn;           // DISPLAY FLAG FOR EACH CAMERA
00236 
00237     // MENU
00238     static void MainMenuHandler(int value);
00239     static void vuOptionsMenuHandler(int value);
00240     static void glOptionsMenuHandler(int value);
00241     static void PathPlaybackMenuHandler(int value);
00242     static void CamViewMenuHandler(int value);
00243     static void CamViewDisplayMenuHandler(int value);
00244     static void EscapeHandler(int value);
00245 
00246     // MOUSE
00247     int DoInertia();
00248     InertiaFunc UserInertiaFunc;
00249 
00250     static GLVU *GLVUs[MAX_GLVUS];
00251 
00252     // glut WindowID
00253     int WindowID;
00254    
00255     static void InertialTimerFunc(int value);
00256     static void PathPlaybackTimerFunc(int value);
00257 
00258     virtual void InitMenu();
00259 
00260 };
00261 
00262 //----------------------------------------------------------------------------
00263 
00265 
00273 inline int GLVU::GetPlaybackOn() const
00274 {
00275   return(PlaybackOn); 
00276 }
00277 
00279 
00287 inline int GLVU::GetRecordingOn() const
00288 {
00289   return(RecordingOn); 
00290 }
00291 
00293 
00302 inline void GLVU::SelectCam(int WhichCam)
00303 {
00304   Cam = &Cams[WhichCam]; 
00305 }
00306 
00308 inline Camera* GLVU::GetCurrentCam() 
00309 {
00310   return(Cam); 
00311 }
00312 
00314 
00322 inline void GLVU::SetCurrentCam(Camera *NewCam) 
00323 {
00324   Cam=NewCam; 
00325 }
00326 
00328 
00333 inline Camera* GLVU::GetCam(int WhichCam) 
00334 {
00335   return(&Cams[WhichCam]); 
00336 }
00337    
00343 inline int GLVU::GetInOutMode() const 
00344 {
00345   return(InsideLookingOutMode); 
00346 }
00347 
00353 inline void GLVU::SetInOutMode(int Bool) 
00354 {
00355   InsideLookingOutMode=Bool; 
00356 }
00357 
00363 inline void GLVU::ToggleInOutMode() 
00364 {
00365   if (InsideLookingOutMode) InsideLookingOutMode=0;
00366   else InsideLookingOutMode=1; 
00367 }
00368 
00374 inline void GLVU::SetOrigCam(Camera *Cam) 
00375 {
00376   OrigCam.Copy(*Cam); 
00377 }
00378 
00384 inline const Vec3f& GLVU::GetViewUp() const 
00385 {
00386   return(ViewUp); 
00387 }
00388 
00393 inline const Vec3f& GLVU::GetWorldCenter() const 
00394 {
00395   return WorldCenter; 
00396 }
00397 
00402 inline void GLVU::SetWorldCenter(const Vec3f& center)
00403 {
00404   WorldCenter = center;
00405 }
00406 
00411 inline float GLVU::GetWorldRadius() const 
00412 {
00413   return WorldRadius; 
00414 }
00415 
00420 inline void GLVU::SetWorldRadius(float newRadius) 
00421 {
00422   WorldRadius = newRadius; 
00423 }
00424 
00429 inline void GLVU::SetViewUp(Vec3f viewup) 
00430 {
00431   ViewUp=viewup; 
00432 }
00433 
00440 inline void GLVU::SetMoveSpeed(float speed) 
00441 {
00442   moveSpeed = speed; 
00443 }
00444 
00451 inline void GLVU::StartFPSClock() 
00452 {
00453   calcFPS = 1; ftime(&lastFPSClock); lastFPSCount=0;
00454 }
00455 
00460 inline void GLVU::StopFPSClock() 
00461 {
00462   calcFPS = 0; 
00463 }
00464 
00469 inline float GLVU::GetFPS() const 
00470 {
00471   return lastFPS; 
00472 }
00473 
00479 inline int GLVU::GetMainMenuID() const 
00480 {
00481   return(MainMenuID); 
00482 }
00483 
00489 inline int GLVU::GetWorldNavMode() const 
00490 {
00491   return(WorldNavMode); 
00492 }
00493 
00531 inline void GLVU::SetWorldNavMode(int mode) 
00532 {
00533   WorldNavMode=mode; 
00534 }
00535 
00543 inline int GLVU::GetCamDisplayOn(int WhichCam) const 
00544 {
00545   return(CamDisplayOn[WhichCam]); 
00546 }
00553 inline int GLVU::IsWorldNavMode() const 
00554 {
00555   return(WorldNavMode>=0 && WorldNavMode<=3); 
00556 }
00557 
00562 inline int GLVU::GetLeftButtonDown() const 
00563 {
00564   return(LeftButtonDown); 
00565 }
00566 
00572 inline int GLVU::GetInertiaOn() const 
00573 {
00574   return(InertiaOn); 
00575 } 
00576 
00578 
00582 inline int GLVU::GetInertiaEnabled() const 
00583 {
00584   return(InertiaEnabled);
00585 }
00586 
00588 
00591 inline void GLVU::SetInertiaEnabled(int Bool) 
00592 {
00593   InertiaEnabled=Bool;
00594 }
00595 
00596 
00598 
00605 inline int GLVU::GetInertiaDelay() const 
00606 {
00607   return(InertiaDelay);
00608 } 
00609 
00611 
00620 inline void GLVU::SetInertiaDelay(int msec) 
00621 {
00622   InertiaDelay=msec;
00623 }
00624 
00626 
00630 inline void GLVU::SetInertiaFunc(GLVU::InertiaFunc f) 
00631 {
00632   UserInertiaFunc=f;
00633 } 
00634 
00636 
00639 inline GLVU::InertiaFunc GLVU::GetInertiaFunc() const
00640 {
00641   return UserInertiaFunc;
00642 }
00643 
00645 
00653 inline int GLVU::GetWindowID() const
00654 {
00655   return WindowID;
00656 }
00657 
00659 
00677 inline void GLVU::MakeCurrent()
00678 {
00679   glutSetWindow(WindowID);
00680 }
00681 
00683 
00689 inline GLVU* GLVU::GetCurrent()
00690 {
00691   return GLVUs[ glutGetWindow() ];
00692 }
00693 
00695 
00702 inline GLVU* GLVU::GetGLVU(int WindowID)
00703 {
00704   return GLVUs[ WindowID ];
00705 }
00706 
00708 
00715 inline GLVU* GLVU::GetGLVU(void)
00716 {
00717   return GLVUs[ glutGetWindow() ];
00718 }
00719 
00720 
00721 #endif
00722 
00723 
00724 
00725 
00726 
00727 

Generated at Fri Oct 12 15:12:20 2001 for GLVU by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001