1 | #include <GL/glut.h> |
---|
2 | #include "trackball.h" |
---|
3 | #include "trackball.c" |
---|
4 | |
---|
5 | GLfloat m[4][4]; |
---|
6 | float last[4]; |
---|
7 | float cur[4]; |
---|
8 | int width; |
---|
9 | int height; |
---|
10 | int beginx; |
---|
11 | int beginy; |
---|
12 | float p1x; |
---|
13 | float p1y; |
---|
14 | float p2x; |
---|
15 | float p2y; |
---|
16 | |
---|
17 | void display() |
---|
18 | { |
---|
19 | glPushMatrix(); |
---|
20 | build_rotmatrix(m, cur); |
---|
21 | glLoadIdentity(); |
---|
22 | glMultMatrixf(*m); |
---|
23 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
24 | glutSolidTeapot(0.5); |
---|
25 | glPopMatrix(); |
---|
26 | glutSwapBuffers(); |
---|
27 | } |
---|
28 | |
---|
29 | void mouse(int button,int state, int x, int y) |
---|
30 | { |
---|
31 | beginx = x; |
---|
32 | beginy = y; |
---|
33 | } |
---|
34 | |
---|
35 | void motion(int x,int y) |
---|
36 | { |
---|
37 | p1x = (2.0*beginx - width)/width; |
---|
38 | p1y = (height - 2.0*beginy)/height; |
---|
39 | p2x = (2.0 * x - width) / width; |
---|
40 | p2y = (height - 2.0 * y) / height; |
---|
41 | trackball(last,p1x, p1y, p2x, p2y); |
---|
42 | add_quats(last, cur, cur); |
---|
43 | beginx = x; |
---|
44 | beginy = y; |
---|
45 | glutPostRedisplay(); |
---|
46 | } |
---|
47 | |
---|
48 | void reshape (int w, int h) |
---|
49 | { |
---|
50 | width=w; |
---|
51 | height=h; |
---|
52 | double l; |
---|
53 | l = 1; |
---|
54 | glViewport (0, 0, w, h); |
---|
55 | glMatrixMode (GL_PROJECTION); |
---|
56 | glLoadIdentity(); |
---|
57 | glOrtho(-l, l, -l, l, -l, l); |
---|
58 | glMatrixMode(GL_MODELVIEW); |
---|
59 | glLoadIdentity(); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | int main(int argc, char *argv[]) |
---|
64 | { |
---|
65 | glutInit(&argc, argv); |
---|
66 | trackball(cur, 0.0, 0.0, 0.0, 0.0); |
---|
67 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); |
---|
68 | glutCreateWindow("Rotacija z misko"); |
---|
69 | glutDisplayFunc(display); |
---|
70 | glutMouseFunc(mouse); |
---|
71 | glutMotionFunc(motion); |
---|
72 | glutReshapeFunc(reshape); |
---|
73 | glEnable(GL_LIGHTING); |
---|
74 | glEnable(GL_LIGHT0); |
---|
75 | glEnable(GL_DEPTH_TEST); |
---|
76 | glutMainLoop(); |
---|
77 | return 0; |
---|
78 | } |
---|