Mercurial > 3de
annotate render.c @ 20:ebc55ce699ec
Rotate the other way around: z, y, x - more useful to us
author | Josef "Jeff" Sipek <jeffpc@optonline.net> |
---|---|
date | Sat, 03 Dec 2005 00:35:58 -0500 |
parents | 4722afb8751c |
children | 9a34b00c0659 |
rev | line source |
---|---|
0 | 1 // System & parser |
2 #include <string.h> | |
3 #include <stdlib.h> | |
4 #include <errno.h> | |
5 #define _GNU_SOURCE | |
6 #include <stdio.h> | |
7 #include <sys/types.h> | |
8 #include <sys/stat.h> | |
9 #include <fcntl.h> | |
10 #include <unistd.h> | |
8 | 11 #include <time.h> |
0 | 12 |
13 // OpenGL | |
14 #include "GL/glut.h" | |
15 | |
8 | 16 #define BUF_SIZE 1024 |
17 #define TIMER_PERIOD 10 | |
18 | |
19 #define PIPE_IN "/tmp/3de.in" | |
20 #define PIPE_OUT "/tmp/3de.out" | |
0 | 21 |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
22 int infd; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
23 int outfd; |
0 | 24 char *buf, *ptr; |
25 | |
8 | 26 int frames; |
27 struct timespec start; | |
28 | |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
29 void display(void); |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
30 |
19
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
31 float cam_x; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
32 float cam_y; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
33 float cam_z; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
34 float cam_ax; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
35 float cam_ay; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
36 float cam_az; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
37 |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
38 int valid_digit_char(char c) |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
39 { |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
40 if (((c >= '0') && (c <= '9')) || (c == '-') || (c == '+') || (c == '.')) |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
41 return 1; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
42 return 0; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
43 } |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
44 |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
45 char* update_ptr(char* buf) |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
46 { |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
47 int i; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
48 int on_num; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
49 |
6 | 50 for(i=0, on_num=0; i<6; buf++) { |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
51 if (!valid_digit_char(*buf) && on_num) { |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
52 on_num = 0; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
53 i++; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
54 } else if (valid_digit_char(*buf) && !on_num) |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
55 on_num = 1; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
56 } |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
57 |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
58 return buf; |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
59 } |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
60 |
0 | 61 void draw_poly(char* buf) |
62 { | |
6 | 63 float c1, c2, c3, f1, f2, f3; |
0 | 64 |
65 buf += 5; | |
66 | |
19
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
67 glPushMatrix(); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
68 glRotatef(cam_ax, 1.0, 0.0, 0.0); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
69 glRotatef(cam_ay, 0.0, 1.0, 0.0); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
70 glRotatef(cam_az, 0.0, 0.0, 1.0); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
71 glTranslatef(cam_x, cam_y, cam_z); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
72 |
0 | 73 glBegin(GL_POLYGON); |
74 while(1) { | |
6 | 75 if (sscanf(buf, "%f %f %f %f %f %f", &c1, &c2, &c3, &f1, &f2, &f3) != 6) |
0 | 76 break; |
6 | 77 glColor3f(c1, c2, c3); |
0 | 78 glVertex3f(f1, f2, f3); |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
79 buf = update_ptr(buf); |
0 | 80 } |
81 glEnd(); | |
19
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
82 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
83 glPopMatrix(); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
84 } |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
85 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
86 void rot_cam(char* buf) |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
87 { |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
88 float x,y,z; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
89 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
90 buf += 7; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
91 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
92 if (sscanf(buf, "%f %f %f", &x, &y, &z) != 3) |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
93 return; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
94 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
95 cam_ax += x; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
96 cam_ay += y; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
97 cam_az += z; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
98 } |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
99 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
100 void trans_cam(char* buf) |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
101 { |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
102 float x,y,z; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
103 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
104 buf += 9; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
105 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
106 if (sscanf(buf, "%f %f %f", &x, &y, &z) != 3) |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
107 return; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
108 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
109 cam_x += x; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
110 cam_y += y; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
111 cam_z += z; |
0 | 112 } |
113 | |
11 | 114 void __key(int c, int x, int y) |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
115 { |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
116 printf("key pressed: %c, mouse at (%d,%d)\n", c, x, y); |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
117 |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
118 switch(c) { |
11 | 119 case GLUT_KEY_LEFT+256: |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
120 write(outfd, "left", 4); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
121 break; |
11 | 122 case GLUT_KEY_RIGHT+256: |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
123 write(outfd, "right", 5); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
124 break; |
11 | 125 case GLUT_KEY_UP+256: |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
126 write(outfd, "up", 2); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
127 break; |
11 | 128 case GLUT_KEY_DOWN+256: |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
129 write(outfd, "down", 4); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
130 break; |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
131 case ' ': |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
132 write(outfd, "space", 5); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
133 break; |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
134 default: |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
135 write(outfd, &c, 1); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
136 break; |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
137 } |
11 | 138 write(outfd, "\n", 1); |
139 } | |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
140 |
11 | 141 void key(unsigned char c, int x, int y) |
142 { | |
143 __key((int)c, x, y); | |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
144 } |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
145 |
11 | 146 void special(int k, int x, int y) |
7 | 147 { |
11 | 148 __key(k+256, x, y); |
149 } | |
150 | |
151 void timer(int val) | |
152 { | |
153 glutPostRedisplay(); | |
154 glutTimerFunc(TIMER_PERIOD, timer, 0); | |
7 | 155 } |
156 | |
0 | 157 void display(void) |
158 { | |
159 ssize_t r; | |
160 | |
161 do { | |
162 if ((ptr) >= (buf + BUF_SIZE)) | |
163 break; | |
164 | |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
165 r = read(infd, ptr, 1); |
0 | 166 |
167 if ((r == -1) || (r == 0) || (*ptr == '\n')) { | |
168 *ptr = '\0'; | |
169 break; | |
170 } | |
171 | |
172 ptr += r; | |
173 } while(1); | |
12 | 174 #if 0 |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
175 if (strlen(buf)) { |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
176 printf("buf = \"%s\"\n", buf); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
177 fflush(stdout); |
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
178 } |
12 | 179 #endif |
7 | 180 if (!strncmp(buf, "CLEAR", 5)) { |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
181 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
7 | 182 } else if (!strncmp(buf, "FLUSH", 5)) { |
183 glFlush(); | |
184 glutSwapBuffers(); | |
185 } else if (!strncmp(buf, "POLY", 4)) | |
186 draw_poly(buf); | |
19
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
187 else if (!strncmp(buf, "ROTCAM", 6)) |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
188 rot_cam(buf); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
189 else if (!strncmp(buf, "TRANSCAM", 8)) |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
190 trans_cam(buf); |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
191 else if (strlen(buf)) { |
7 | 192 printf("unknown command\n"); |
193 fflush(stdout); | |
194 } | |
0 | 195 |
196 ptr = buf; | |
8 | 197 |
198 frames++; | |
0 | 199 } |
200 | |
201 void init() | |
202 { | |
203 /* set clear color to black */ | |
204 glClearColor (0.0, 0.0, 0.0, 0.0); | |
205 | |
206 /* set fill color to white */ | |
207 glColor3f(1.0, 1.0, 1.0); | |
208 | |
209 /* set up standard orthogonal view with clipping */ | |
210 /* box as cube of side 2 centered at origin */ | |
211 /* This is default view and these statement could be removed */ | |
212 glMatrixMode (GL_PROJECTION); | |
19
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
213 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
214 //sets up the projection matrix for a perspective transform |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
215 gluPerspective( 90, //view angle |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
216 1.0, //aspect ratio |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
217 0.0, //near clip |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
218 200.0); //far clip |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
219 glMatrixMode(GL_MODELVIEW); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
220 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
221 /*glLoadIdentity (); |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
222 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);*/ |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
223 |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
224 cam_x = 0.0; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
225 cam_y = 0.0; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
226 cam_z = 0.0; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
227 cam_ax = 0.0; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
228 cam_ay = 0.0; |
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
229 cam_az = 0.0; |
0 | 230 } |
231 | |
232 #define die() __die(__FILE__, __LINE__); | |
233 | |
234 void __die(char* f, int l) | |
235 { | |
236 fprintf(stderr, "Error encountered in %s:%d: %s (%d)\n", f, l, strerror(errno), errno); | |
237 } | |
238 | |
8 | 239 void goodbye() |
240 { | |
241 struct timespec end; | |
242 double delta; | |
243 | |
244 clock_gettime(CLOCK_REALTIME, &end); | |
245 | |
246 delta = ((double) end.tv_sec + 1000000000.0/(double)end.tv_nsec) | |
247 - ((double) start.tv_sec + 1000000000.0/(double)start.tv_nsec); | |
248 | |
249 printf("Displayed %d frames in %.4lf seconds = %.4lf fps\n", frames, delta, frames/delta); | |
250 | |
251 close(infd); | |
252 close(outfd); | |
253 } | |
254 | |
0 | 255 int main(int argc, char** argv) |
256 { | |
8 | 257 frames = 0; |
0 | 258 |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
259 unlink(PIPE_IN); |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
260 unlink(PIPE_OUT); |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
261 |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
262 if ((buf = (char*) malloc(sizeof(char)*BUF_SIZE)) == NULL) |
0 | 263 die(); |
264 ptr = buf; | |
265 | |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
266 if (mkfifo(PIPE_IN, 0777) == -1) |
0 | 267 die(); |
268 | |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
269 if (mkfifo(PIPE_OUT, 0777) == -1) |
0 | 270 die(); |
271 | |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
272 if ((infd = open(PIPE_IN, O_RDWR | O_NONBLOCK | O_NDELAY)) == -1) |
0 | 273 die(); |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
274 |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
275 if ((outfd = open(PIPE_OUT, O_RDWR | O_NONBLOCK | O_NDELAY)) == -1) |
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
276 die(); |
0 | 277 |
8 | 278 atexit(goodbye); |
279 | |
0 | 280 glutInit(&argc,argv); |
19
4722afb8751c
Added rotation and translation
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
12
diff
changeset
|
281 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB); |
11 | 282 glutInitWindowSize(800,800); |
0 | 283 glutInitWindowPosition(0,0); |
284 glutCreateWindow("3D Engine"); | |
9
d325e84a13dd
some cleanups/performance improvements
jsipek@huey.fsl.cs.sunysb.edu
parents:
8
diff
changeset
|
285 glEnable(GL_DEPTH_TEST); |
0 | 286 glutDisplayFunc(display); |
1
88acf3d645e3
Draws a triangle from sample.scn!
jsipek@huey.fsl.cs.sunysb.edu
parents:
0
diff
changeset
|
287 glutKeyboardFunc(key); |
11 | 288 glutSpecialFunc(special); |
0 | 289 init(); |
8 | 290 |
291 clock_gettime(CLOCK_REALTIME, &start); | |
292 | |
11 | 293 //glutIdleFunc(idle); |
294 glutTimerFunc(TIMER_PERIOD, timer, 0); | |
0 | 295 glutMainLoop(); |
296 | |
297 | |
298 return 0; | |
299 } | |
300 |