… | |
… | |
16 | CGcontext cgc; |
16 | CGcontext cgc; |
17 | CGprogram vsh, fsh; |
17 | CGprogram vsh, fsh; |
18 | CGparameter mv, mvp, lightpos; |
18 | CGparameter mv, mvp, lightpos; |
19 | CGprofile vsh_profile, fsh_profile; |
19 | CGprofile vsh_profile, fsh_profile; |
20 | |
20 | |
21 | static void CheckCgError(void) |
21 | static void CheckCgError (void) |
22 | { |
22 | { |
23 | CGerror err = cgGetError(); |
23 | CGerror err = cgGetError (); |
24 | |
24 | |
25 | if (err != CG_NO_ERROR) |
25 | if (err != CG_NO_ERROR) |
26 | { |
26 | { |
27 | printf("CG error: %s\n", cgGetErrorString(err)); |
27 | printf("CG error: %s\n", cgGetErrorString (err)); |
28 | exit(1); |
28 | exit(1); |
29 | } |
29 | } |
30 | } |
30 | } |
31 | |
31 | |
32 | /**********************************************************************/ |
32 | /**********************************************************************/ |
33 | |
33 | |
34 | view camera; |
34 | view camera; |
35 | vec3 camera_velocity; |
35 | vec3 camera_velocity; |
36 | float camera_angle = 0, camera_velocity_angle; |
36 | float camera_angle, camera_angle2, camera_velocity_angle, camera_velocity_angle2; |
37 | float camera_velocity_factor = 20; |
37 | float camera_velocity_factor = 80; |
38 | |
38 | |
39 | void |
39 | void |
40 | HotKey_ToggleFullScreen (void) |
40 | HotKey_ToggleFullScreen (void) |
41 | { |
41 | { |
42 | SDL_Surface *screen; |
42 | SDL_Surface *screen; |
… | |
… | |
101 | |
101 | |
102 | printf ("focus\n"); |
102 | printf ("focus\n"); |
103 | break; |
103 | break; |
104 | |
104 | |
105 | case SDL_KEYDOWN: |
105 | case SDL_KEYDOWN: |
106 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
106 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z--; |
107 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; |
107 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z++; |
108 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x--; |
|
|
109 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x++; |
108 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle++; |
|
|
109 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle--; |
|
|
110 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2++; |
|
|
111 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2--; |
110 | if (event->key.keysym.sym == SDLK_a) camera_velocity.y--; |
112 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y--; |
111 | if (event->key.keysym.sym == SDLK_s) camera_velocity.y++; |
113 | if (event->key.keysym.sym == SDLK_q) camera_velocity.y++; |
112 | if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; |
114 | if (event->key.keysym.sym == SDLK_v) camera_velocity_factor *= 1.5; |
113 | if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5; |
115 | if (event->key.keysym.sym == SDLK_b) camera_velocity_factor /= 1.5; |
114 | if (event->key.keysym.sym == SDLK_e) camera_velocity_angle++; |
|
|
115 | if (event->key.keysym.sym == SDLK_q) camera_velocity_angle--; |
|
|
116 | |
116 | |
117 | if (event->key.keysym.sym == SDLK_ESCAPE) |
117 | if (event->key.keysym.sym == SDLK_ESCAPE) |
118 | done = 1; |
118 | done = 1; |
119 | |
119 | |
120 | if ((event->key.keysym.sym == SDLK_g) && |
120 | if ((event->key.keysym.sym == SDLK_g) && |
… | |
… | |
132 | break; |
132 | break; |
133 | |
133 | |
134 | case SDL_KEYUP: |
134 | case SDL_KEYUP: |
135 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
135 | if (event->key.keysym.sym == SDLK_UP) camera_velocity.z++; |
136 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
136 | if (event->key.keysym.sym == SDLK_DOWN) camera_velocity.z--; |
137 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity.x++; |
137 | if (event->key.keysym.sym == SDLK_LEFT) camera_velocity_angle++; |
138 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity.x--; |
138 | if (event->key.keysym.sym == SDLK_RIGHT) camera_velocity_angle--; |
|
|
139 | if (event->key.keysym.sym == SDLK_PAGEUP) camera_velocity_angle2--; |
|
|
140 | if (event->key.keysym.sym == SDLK_PAGEDOWN) camera_velocity_angle2++; |
139 | if (event->key.keysym.sym == SDLK_a) camera_velocity.y++; |
141 | if (event->key.keysym.sym == SDLK_e) camera_velocity.y++; |
140 | if (event->key.keysym.sym == SDLK_s) camera_velocity.y--; |
142 | if (event->key.keysym.sym == SDLK_q) camera_velocity.y--; |
141 | if (event->key.keysym.sym == SDLK_e) camera_velocity_angle--; |
|
|
142 | if (event->key.keysym.sym == SDLK_q) camera_velocity_angle++; |
|
|
143 | break; |
143 | break; |
144 | |
144 | |
145 | case SDL_QUIT: |
145 | case SDL_QUIT: |
146 | done = 1; |
146 | done = 1; |
147 | break; |
147 | break; |
148 | } |
148 | } |
149 | |
149 | |
150 | return (done); |
150 | return (done); |
|
|
151 | } |
|
|
152 | |
|
|
153 | void draw_floor (int size, int dx, int dy, int dz) |
|
|
154 | { |
|
|
155 | int x, z, ry; |
|
|
156 | |
|
|
157 | for (x = 0; x < 100; x++) |
|
|
158 | { |
|
|
159 | for (z = 0; z < 100; z++) |
|
|
160 | { |
|
|
161 | vector<vertex2d> pts; |
|
|
162 | pts.push_back (vertex2d (point ( 0, 0, 0), vec3 (0, 1, 0), texc (0, 0))); |
|
|
163 | pts.push_back (vertex2d (point ( 0, 0, size), vec3 (0, 1, 0), texc (0, 1))); |
|
|
164 | pts.push_back (vertex2d (point (size, 0, size), vec3 (0, 1, 0), texc (1, 1))); |
|
|
165 | pts.push_back (vertex2d (point (size, 0, 0), vec3 (0, 1, 0), texc (1, 0))); |
|
|
166 | |
|
|
167 | geometry_quads *q = new geometry_quads; |
|
|
168 | q->set (pts); |
|
|
169 | entity *e = new entity (q); |
|
|
170 | e->move (vec3 (dx + x * size, dy, dz + z * size)); |
|
|
171 | e->show (); |
|
|
172 | } |
|
|
173 | } |
|
|
174 | } |
|
|
175 | |
|
|
176 | void draw_test_nurb () |
|
|
177 | { |
|
|
178 | geometry_nurbs *q = new geometry_nurbs; |
|
|
179 | q->set (); |
|
|
180 | entity *e = new entity (q); |
|
|
181 | e->move (vec3 (10, 3, -4)); |
|
|
182 | e->show (); |
151 | } |
183 | } |
152 | |
184 | |
153 | int |
185 | int |
154 | RunGLTest (int argc, char *argv[], |
186 | RunGLTest (int argc, char *argv[], |
155 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
187 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
… | |
… | |
264 | |
296 | |
265 | /* Set the gamma for the window */ |
297 | /* Set the gamma for the window */ |
266 | if (gamma != 0.0) |
298 | if (gamma != 0.0) |
267 | SDL_SetGamma (gamma, gamma, gamma); |
299 | SDL_SetGamma (gamma, gamma, gamma); |
268 | |
300 | |
269 | for (int i = 0; i < 70; i++) |
301 | for (int i = 0; i < 1; i++) |
270 | { |
302 | { |
271 | // load a entity |
303 | // load a entity |
272 | txtprt_parser p; |
304 | txtprt_parser p; |
273 | entity *e; |
305 | geometry *g; |
274 | try |
306 | try |
275 | { |
307 | { |
276 | e = p.read ("test.blasc"); |
308 | g = p.read ("test.blasc"); |
277 | } |
309 | } |
278 | catch (txtprt_i_exception & e) |
310 | catch (txtprt_i_exception & e) |
279 | { |
311 | { |
280 | cout << "ERR: " << e.msg << endl; |
312 | cout << "ERR: " << e.msg << endl; |
281 | } |
313 | } |
282 | |
314 | |
283 | entity_transform *f = new entity_transform; |
315 | entity *e = new entity (g); |
284 | f->set (e); |
316 | e->move (vec3 (i*5, -3, -i*10)); |
285 | f->update (matrix::translation (vec3 (i*5, -3, -i*10))); |
|
|
286 | f->show (); |
317 | e->show (); |
287 | } |
318 | } |
288 | draw_some_random_funky_floor_dance_music (10, -500, -10, -1000); |
319 | |
|
|
320 | draw_floor (10, -500, -10, -1000); |
|
|
321 | //draw_test_nurb (); |
|
|
322 | |
289 | camera.orig.x = camera.orig.y = camera.orig.z = 0; |
323 | camera.orig.x = camera.orig.y = camera.orig.z = 0; |
290 | camera.p = point (0, 0, 10); |
324 | camera.p = point (0, 0, 10); |
291 | camera.d = vec3 (0, 0, -1); |
325 | camera.d = vec3 (0, 0, -1); |
292 | camera.u = vec3 (0, 1, 0); |
326 | camera.u = vec3 (0, 1, 0); |
293 | camera.w = w; camera.h = h; |
327 | camera.w = w; camera.h = h; |
294 | camera.fov = 80; |
328 | camera.fov = 35; |
|
|
329 | camera.near = 1.; |
|
|
330 | camera.far = 10.; |
295 | |
331 | |
296 | glMatrixMode (GL_MODELVIEW); |
332 | glMatrixMode (GL_MODELVIEW); |
297 | glLoadIdentity (); |
333 | glLoadIdentity (); |
298 | |
334 | |
299 | glEnable (GL_CULL_FACE); |
335 | glEnable (GL_CULL_FACE); |
… | |
… | |
345 | while (!done) |
381 | while (!done) |
346 | { |
382 | { |
347 | char *sdl_error; |
383 | char *sdl_error; |
348 | SDL_Event event; |
384 | SDL_Event event; |
349 | |
385 | |
350 | camera.p.x += camera_velocity_factor * camera_velocity.x * timer.diff; |
|
|
351 | camera.p.y += camera_velocity_factor * camera_velocity.y * timer.diff; |
|
|
352 | camera.p.z += camera_velocity_factor * camera_velocity.z * timer.diff; |
|
|
353 | |
|
|
354 | camera_angle += camera_velocity_factor * camera_velocity_angle * timer.diff; |
386 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
355 | camera.d.z = -cos (camera_angle * 12 / 180.); |
387 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
356 | camera.d.x = sin (camera_angle * 12 / 180.); |
388 | |
|
|
389 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
|
|
390 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
|
|
391 | |
|
|
392 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
|
|
393 | camera.u = cross (camera.d, right); |
|
|
394 | |
|
|
395 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
|
|
396 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
357 | |
397 | |
358 | cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); |
398 | cgGLSetParameter4f (lightpos, camera.p.x, camera.p.y, camera.p.z, 1); |
359 | |
399 | |
360 | glBindTexture (GL_TEXTURE_2D, t.texture); |
400 | glBindTexture (GL_TEXTURE_2D, t.texture); |
361 | cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter |
401 | cgGLEnableTextureParameter (g_Texture); // Enable the texture parameter |
… | |
… | |
388 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
428 | fprintf (stderr, "testgl: SDL error '%s'\n", sdl_error); |
389 | SDL_ClearError (); |
429 | SDL_ClearError (); |
390 | } |
430 | } |
391 | |
431 | |
392 | /* Allow the user to see what's happening */ |
432 | /* Allow the user to see what's happening */ |
393 | //SDL_Delay (20); |
433 | //SDL_Delay (40); |
394 | |
434 | |
395 | /* Check if there's a pending event. */ |
435 | /* Check if there's a pending event. */ |
396 | while (SDL_PollEvent (&event)) |
436 | while (SDL_PollEvent (&event)) |
397 | done = HandleEvent (&event); |
437 | done = HandleEvent (&event); |
398 | |
438 | |