vcglib/apps/test/trackball/main.cpp

167 lines
3.7 KiB
C++
Raw Normal View History

2004-03-25 14:54:06 +01:00
#include <iostream>
using namespace std;
2004-05-14 05:13:41 +02:00
#ifdef _WIN32
2004-03-25 14:54:06 +01:00
#include<windows.h>
2004-05-14 05:13:41 +02:00
#endif
2004-03-25 14:54:06 +01:00
#include <SDL/SDL.h>
2004-05-14 05:13:41 +02:00
//#include <GL/glew.h>
2004-03-25 14:54:06 +01:00
#include <wrap/gui/trackball.h>
2004-05-14 05:13:41 +02:00
#include <GL/glut.h>
2004-03-25 14:54:06 +01:00
using namespace vcg;
bool fullscreen = false;
//int width =1024;
//int height = 768;
int width = 800;
int height = 600;
SDL_Surface *screen = NULL;
bool init() {
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
return false;
}
const SDL_VideoInfo *info = SDL_GetVideoInfo();
int bpp = info->vfmt->BitsPerPixel;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
int flags = SDL_OPENGL;
if(fullscreen)
flags |= SDL_FULLSCREEN;
screen = SDL_SetVideoMode(width, height, bpp, flags);
if(!screen) {
return false;
}
SDL_WM_SetIcon(SDL_LoadBMP("inspector.bmp"), NULL);
SDL_WM_SetCaption(" Inspector", "Inspector");
glDisable(GL_DITHER);
glShadeModel(GL_SMOOTH);
glHint( GL_FOG_HINT, GL_NICEST );
glEnable(GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL );
glDisable(GL_LIGHTING);
return true;
}
2004-05-14 05:13:41 +02:00
int main(int argc, unsigned short **argv) {
2004-03-25 14:54:06 +01:00
if(!init()) return -1;
2004-05-14 05:13:41 +02:00
glewInit();
2004-03-31 17:08:39 +02:00
2004-03-25 14:54:06 +01:00
Trackball trackball;
int quit = 0;
int x, y;
SDL_Event event;
while( !quit ) {
while( SDL_PollEvent( &event ) ){
switch( event.type ) {
case SDL_QUIT: quit = 1; break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_RSHIFT:
case SDLK_LSHIFT:
trackball.ButtonDown(Trackball::KEY_SHIFT);
break;
case SDLK_RCTRL:
case SDLK_LCTRL:
trackball.ButtonDown(Trackball::KEY_CTRL);
break;
case SDLK_RALT:
case SDLK_LALT:
trackball.ButtonDown(Trackball::KEY_ALT);
break;
}
break;
case SDL_KEYUP:
switch(event.key.keysym.sym) {
case SDLK_q: exit(0); break;
case SDLK_RSHIFT:
case SDLK_LSHIFT:
trackball.ButtonUp(Trackball::KEY_SHIFT);
break;
case SDLK_RCTRL:
case SDLK_LCTRL:
trackball.ButtonUp(Trackball::KEY_CTRL);
break;
case SDLK_RALT:
case SDLK_LALT:
trackball.ButtonUp(Trackball::KEY_ALT);
break;
}
break;
case SDL_MOUSEBUTTONDOWN:
x = event.button.x;
2004-05-14 05:13:41 +02:00
y = height - event.button.y;
2004-03-25 14:54:06 +01:00
trackball.MouseDown(x, y, Trackball::BUTTON_LEFT);
break;
case SDL_MOUSEBUTTONUP:
x = event.button.x;
2004-05-14 05:13:41 +02:00
y = height - event.button.y;
2004-03-25 14:54:06 +01:00
trackball.MouseUp(x, y, Trackball::BUTTON_LEFT);
break;
case SDL_MOUSEMOTION:
while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK));
x = event.motion.x;
2004-05-14 05:13:41 +02:00
y = height - event.motion.y;
2004-03-25 14:54:06 +01:00
trackball.MouseMove(x, y);
break;
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, 1, 0.1, 100);
2004-05-14 05:13:41 +02:00
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,6, 0,0,0, 0,1,0);
2004-03-25 14:54:06 +01:00
glRotatef(130, 1, 1, 0);
2004-05-14 05:13:41 +02:00
glTranslatef(0, 1, 1);
2004-03-25 14:54:06 +01:00
2004-05-14 05:13:41 +02:00
// trackball.SetPosition(Similarityf(Point3f(1, 0, 0)));
// trackball.local.sca = 0.5;
2004-03-25 14:54:06 +01:00
trackball.GetView();
trackball.Apply();
trackball.Draw();
glColor3f(0, 1, 0);
glutWireCube(1);
SDL_GL_SwapBuffers();
}
// Clean up
SDL_Quit();
2004-03-07 19:00:10 +01:00
return -1;
2004-03-25 14:54:06 +01:00
}
2004-05-14 05:13:41 +02:00