Subversion Repositories gelsvn

Rev

Rev 198 | Rev 337 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 198 Rev 299
Line 32... Line 32...
32
#include <IL/ilu.h>
32
#include <IL/ilu.h>
33
 
33
 
34
#include <CGLA/Vec3f.h>
34
#include <CGLA/Vec3f.h>
35
#include <CGLA/Mat4x4f.h>
35
#include <CGLA/Mat4x4f.h>
36
#include "GLGraphics/gel_glut.h"
36
#include "GLGraphics/gel_glut.h"
37
#include "GLGraphics/SimpleTrackBall.h"
37
#include "GLGraphics/QuatTrackBall.h"
38
#include "GLGraphics/draw.h"
38
#include "GLGraphics/draw.h"
39
#include "Geometry/TriMesh.h"
39
#include "Geometry/TriMesh.h"
40
#include "Geometry/obj_load.h"
40
#include "Geometry/obj_load.h"
41
 
41
 
42
using namespace std;
42
using namespace std;
Line 47... Line 47...
47
namespace
47
namespace
48
{
48
{
49
int win_size_x = 800;
49
int win_size_x = 800;
50
int win_size_y = 800;
50
int win_size_y = 800;
51
 
51
 
52
SimpleTrackBall* ball;
52
QuatTrackBall* ball;
-
 
53
int spin_timer = 20;
-
 
54
void spin(int x);
53
 
55
 
54
int main_window;
56
int main_window;
55
 
57
 
56
bool load_image_into_texture(const std::string& name, GLuint& id)
58
bool load_image_into_texture(const std::string& name, GLuint& id)
57
{
59
{
Line 197... Line 199...
197
 
199
 
198
    // The lines below copy the viewing transformation from OpenGL
200
    // The lines below copy the viewing transformation from OpenGL
199
    // to local variables. The call to gluLookAt must have exactly
201
    // to local variables. The call to gluLookAt must have exactly
200
    // the same parameters as when the scene is drawn.
202
    // the same parameters as when the scene is drawn.
201
    glLoadIdentity();
203
    glLoadIdentity();
202
    ball->gl_view();
204
    ball->set_gl_modelview();
203
    double mvmat[16];
205
    double mvmat[16];
204
    glGetDoublev(GL_MODELVIEW_MATRIX, mvmat);
206
    glGetDoublev(GL_MODELVIEW_MATRIX, mvmat);
205
 
207
 
206
    // Copy the projection matrix. We assume it is unchanged.
208
    // Copy the projection matrix. We assume it is unchanged.
207
    double prjmat[16];
209
    double prjmat[16];
Line 221... Line 223...
221
 
223
 
222
TriMesh mesh;
224
TriMesh mesh;
223
 
225
 
224
void mouse_motion(int x, int y)
226
void mouse_motion(int x, int y)
225
{
227
{
226
    ball->roll(x,y);
228
    ball->roll_ball(Vec2i(x,y));
227
}
229
}
228
 
230
 
229
void mouse(int button, int state, int x, int y)
231
void mouse(int btn, int state, int x, int y)
230
{
232
{
231
    if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
233
  if(state == GLUT_DOWN) 
232
    {
234
  {
233
        Vec3f p;
235
	if(btn == GLUT_LEFT_BUTTON) 
-
 
236
	   ball->grab_ball(ROTATE_ACTION, Vec2i(x,y));
234
        if(depth_pick(x, y, p))
237
    else if(btn == GLUT_MIDDLE_BUTTON) 
235
            ball->set_center(p);
238
	  ball->grab_ball(ZOOM_ACTION, Vec2i(x, y));
236
    }
-
 
237
    else if(button==3)
239
    else if(btn == GLUT_RIGHT_BUTTON) 
238
        ball->farther();
240
	  ball->grab_ball(PAN_ACTION, Vec2i(x, y));
-
 
241
  }
239
    else if(button==4)
242
  else if(state == GLUT_UP)
240
        ball->closer();
243
    ball->release_ball();	
241
}
244
}
242
 
245
 
-
 
246
void spin(int x)
-
 
247
{
-
 
248
  ball->do_spin();
-
 
249
  glutTimerFunc(spin_timer, spin, 0);  
-
 
250
  glutPostRedisplay();
-
 
251
}
-
 
252
/*
243
void idle()
253
void idle()
244
{
254
{
245
    if ( glutGetWindow() != main_window )
255
    if ( glutGetWindow() != main_window )
246
        glutSetWindow(main_window);
256
        glutSetWindow(main_window);
247
    glutPostRedisplay();
257
    glutPostRedisplay();
248
}
258
}
249
 
259
*/
250
void display()
260
void display()
251
{
261
{
252
    static bool washere = false;
262
    static bool washere = false;
253
    static unsigned int l;
263
    static unsigned int l;
254
    if(!washere)
264
    if(!washere)
Line 257... Line 267...
257
        l = glGenLists(1);
267
        l = glGenLists(1);
258
        glNewList(l, GL_COMPILE);
268
        glNewList(l, GL_COMPILE);
259
        draw(mesh);
269
        draw(mesh);
260
        glEndList();
270
        glEndList();
261
        washere = true;
271
        washere = true;
-
 
272
      glutTimerFunc(spin_timer, spin, 0);	
262
    }
273
	}
263
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
274
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
264
    glLoadIdentity();
275
    glLoadIdentity();
265
    ball->gl_view();
276
    ball->set_gl_modelview();
266
    glCallList(l);
277
    glCallList(l);
267
    glutSwapBuffers();
278
    glutSwapBuffers();
268
}
279
}
269
 
280
 
270
void keyboard(unsigned char key, int x, int y)
281
void keyboard(unsigned char key, int x, int y)
271
{
282
{
272
    switch(key)
283
    switch(key)
273
    {
284
    {
274
    case '\033': exit(0); break;
285
    case '\033': exit(0); break;
275
    case '+': ball->closer(); break;
286
    //case '+': ball->closer(); break;
276
    case '-': ball->farther(); break;
287
    //case '-': ball->farther(); break;
277
    default:
288
    //default:
278
        ball->up_axis(key);
289
    //    ball->up_axis(key);
279
    }
290
    }
280
}
291
}
281
}
292
}
282
 
293
 
283
int main(int argc, char** argv)
294
int main(int argc, char** argv)
Line 289... Line 300...
289
    main_window = glutCreateWindow("OBJ Viewer");
300
    main_window = glutCreateWindow("OBJ Viewer");
290
    glutDisplayFunc(display);
301
    glutDisplayFunc(display);
291
    glutKeyboardFunc(keyboard);
302
    glutKeyboardFunc(keyboard);
292
    glutMotionFunc(mouse_motion);
303
    glutMotionFunc(mouse_motion);
293
    glutMouseFunc(mouse);
304
    glutMouseFunc(mouse);
294
    glutIdleFunc(idle);
305
    //glutIdleFunc(idle);
295
 
306
 
296
    // GL INIT
307
    // GL INIT
297
    glClearColor(.8f, 0.9f, 1.0f, 0.f);
308
    glClearColor(.8f, 0.9f, 1.0f, 0.f);
298
    glEnable(GL_DEPTH_TEST);
309
    glEnable(GL_DEPTH_TEST);
299
    glEnable(GL_LIGHTING);
310
    glEnable(GL_LIGHTING);
Line 322... Line 333...
322
    // Initialize Trackball
333
    // Initialize Trackball
323
    Vec3f c;
334
    Vec3f c;
324
    float r;
335
    float r;
325
    mesh.get_bsphere(c,r);
336
    mesh.get_bsphere(c,r);
326
    r *= 1.5;
337
    r *= 1.5;
327
    ball = new SimpleTrackBall(c,r);
338
    ball = new QuatTrackBall(c,r,800,800);
328
 
339
 
329
    // Setup projection
340
    // Setup projection
330
    glMatrixMode(GL_PROJECTION);
341
    glMatrixMode(GL_PROJECTION);
331
    glLoadIdentity();
342
    glLoadIdentity();
332
    gluPerspective(53,1.0f,r/100,r*3);
343
    gluPerspective(53,1.0f,r/100.0,r*3.0);
333
    glMatrixMode(GL_MODELVIEW);
344
    glMatrixMode(GL_MODELVIEW);
334
 
345
 
335
    // Pass control to GLUT
346
    // Pass control to GLUT
336
    glutMainLoop();
347
    glutMainLoop();
337
 
348