main.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 using namespace std;
00003 
00004 #ifdef _WIN32
00005 #include<windows.h>
00006 #endif
00007 
00008 #include <SDL/SDL.h>
00009 
00010 //#include <GL/glew.h>
00011 #include <wrap/gui/trackball.h>
00012 #include <GL/glut.h>
00013 
00014 using namespace vcg;
00015 
00016 bool fullscreen = false;
00017 //int width =1024;
00018 //int height = 768;
00019 int width = 800;
00020 int height = 600;
00021 
00022 
00023 
00024 SDL_Surface *screen = NULL;
00025 
00026 bool init() {
00027   
00028   if(SDL_Init(SDL_INIT_VIDEO) != 0) {
00029     return false;
00030   }
00031 
00032   const SDL_VideoInfo *info = SDL_GetVideoInfo();
00033   int bpp = info->vfmt->BitsPerPixel;
00034 
00035   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
00036   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
00037 
00038   int flags = SDL_OPENGL;
00039   if(fullscreen) 
00040     flags |= SDL_FULLSCREEN;
00041 
00042   screen = SDL_SetVideoMode(width, height, bpp, flags);
00043   if(!screen) {
00044     return false;
00045   }
00046   
00047   SDL_WM_SetIcon(SDL_LoadBMP("inspector.bmp"), NULL);
00048   SDL_WM_SetCaption(" Inspector", "Inspector");
00049 
00050 
00051   glDisable(GL_DITHER);
00052   glShadeModel(GL_SMOOTH);
00053   glHint( GL_FOG_HINT, GL_NICEST );
00054   glEnable(GL_DEPTH_TEST);
00055   glDepthFunc( GL_LEQUAL );
00056   glDisable(GL_LIGHTING); 
00057 
00058   return true;
00059 }
00060 
00061 
00062 
00063 
00064 int main(int argc, unsigned short **argv) {  
00065   if(!init()) return -1;
00066   glewInit();
00067   
00068   Trackball trackball;
00069 
00070   int quit = 0;
00071   int x, y;
00072   SDL_Event event;  
00073   while( !quit ) {                
00074     while( SDL_PollEvent( &event ) ){                        
00075       switch( event.type ) {
00076         case SDL_QUIT:  quit = 1; break; 
00077 
00078         case SDL_KEYDOWN:   
00079           switch(event.key.keysym.sym) {
00080             case SDLK_RSHIFT:
00081             case SDLK_LSHIFT:
00082               trackball.ButtonDown(Trackball::KEY_SHIFT);
00083               break;
00084 
00085             case SDLK_RCTRL:
00086             case SDLK_LCTRL:
00087               trackball.ButtonDown(Trackball::KEY_CTRL);
00088               break;
00089 
00090             case SDLK_RALT:
00091             case SDLK_LALT:
00092               trackball.ButtonDown(Trackball::KEY_ALT);
00093               break;
00094           }
00095           break;
00096 
00097         case SDL_KEYUP:
00098           switch(event.key.keysym.sym) {
00099             case SDLK_q: exit(0); break;            
00100             
00101             case SDLK_RSHIFT:
00102             case SDLK_LSHIFT:
00103               trackball.ButtonUp(Trackball::KEY_SHIFT);
00104               break;
00105 
00106             case SDLK_RCTRL:
00107             case SDLK_LCTRL:
00108               trackball.ButtonUp(Trackball::KEY_CTRL);
00109               break;
00110 
00111             case SDLK_RALT:
00112             case SDLK_LALT:
00113               trackball.ButtonUp(Trackball::KEY_ALT);
00114               break;
00115           }
00116           break;
00117         case SDL_MOUSEBUTTONDOWN:       
00118           x = event.button.x;
00119           y = height - event.button.y;          
00120           trackball.MouseDown(x, y, Trackball::BUTTON_LEFT);
00121         break;
00122         case SDL_MOUSEBUTTONUP:          
00123           x = event.button.x;
00124           y = height - event.button.y;          
00125           trackball.MouseUp(x, y, Trackball::BUTTON_LEFT);
00126           break;
00127         case SDL_MOUSEMOTION: 
00128           while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK));
00129           x = event.motion.x;
00130           y = height - event.motion.y;
00131           trackball.MouseMove(x, y);        
00132           break;  
00133       }
00134         
00135     }
00136     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00137     glMatrixMode(GL_PROJECTION);
00138     glLoadIdentity();
00139     gluPerspective(60, 1, 0.1, 100);
00140     glMatrixMode(GL_MODELVIEW);
00141     glLoadIdentity();
00142     gluLookAt(0,0,6,   0,0,0,   0,1,0);        
00143     glRotatef(130, 1, 1, 0);
00144     glTranslatef(0, 1, 1);
00145     
00146     
00147     //    trackball.SetPosition(Similarityf(Point3f(1, 0, 0)));
00148     //    trackball.local.sca = 0.5;
00149     trackball.GetView();
00150     trackball.Apply();
00151     trackball.Draw();
00152 
00153     glColor3f(0, 1, 0);
00154     glutWireCube(1);
00155     
00156     SDL_GL_SwapBuffers();
00157   }
00158 
00159         
00160   // Clean up
00161   SDL_Quit();
00162   
00163 
00164   return -1;
00165 }
00166   


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:32:52