1 | #include <stdlib.h> |
1 | #include <stdlib.h> |
2 | #include <stdio.h> |
2 | #include <stdio.h> |
3 | #include <string.h> |
3 | #include <string.h> |
4 | #include <math.h> |
4 | #include <math.h> |
|
|
5 | #include <list> |
5 | |
6 | |
6 | #include "opengl.h" |
7 | #include "opengl.h" |
7 | |
8 | |
8 | #include "SDL.h" |
9 | #include "SDL.h" |
9 | #include "SDL_opengl.h" |
10 | #include "SDL_opengl.h" |
… | |
… | |
12 | static GLuint global_texture = 0; |
13 | static GLuint global_texture = 0; |
13 | |
14 | |
14 | #include "util.h" |
15 | #include "util.h" |
15 | #include "entity.h" |
16 | #include "entity.h" |
16 | #include "txtprt_import.h" |
17 | #include "txtprt_import.h" |
|
|
18 | #include "randlvl.h" |
|
|
19 | |
|
|
20 | bool doom3parse (const char *f); |
17 | |
21 | |
18 | #include "shader.h" |
22 | #include "shader.h" |
19 | |
23 | |
20 | /**********************************************************************/ |
24 | /**********************************************************************/ |
21 | |
25 | |
… | |
… | |
185 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
189 | fisch (center + vec3 (-r3, 0, 0), r2, depth); |
186 | } |
190 | } |
187 | } |
191 | } |
188 | |
192 | |
189 | extern void draw_level (); |
193 | extern void draw_level (); |
|
|
194 | |
|
|
195 | std::list<entity_moveable *> moveables; |
|
|
196 | |
|
|
197 | void perfom_moves () |
|
|
198 | { |
|
|
199 | for (std::list<entity_moveable *>::iterator i = moveables.begin (); i != moveables.end (); ++i) |
|
|
200 | { |
|
|
201 | (*i)->perform_step (timer.diff); |
|
|
202 | } |
|
|
203 | } |
|
|
204 | |
190 | int |
205 | int |
191 | RunGLTest (int argc, char *argv[], |
206 | RunGLTest (int argc, char *argv[], |
192 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
207 | int logo, int slowly, int bpp, float gamma, int noframe, int fsaa) |
193 | { |
208 | { |
194 | int i; |
209 | int i; |
… | |
… | |
302 | if (gamma != 0.0) |
317 | if (gamma != 0.0) |
303 | SDL_SetGamma (gamma, gamma, gamma); |
318 | SDL_SetGamma (gamma, gamma, gamma); |
304 | |
319 | |
305 | testmat = new test_material; |
320 | testmat = new test_material; |
306 | |
321 | |
307 | entity *planet = new entity (new geometry_sphere (testmat, 10)); |
322 | entity_moveable *planet = new entity_moveable (new geometry_sphere (testmat, 10)); |
308 | planet->move (vec3 (0, 0, -20)); |
323 | planet->move (vec3 (0, 0, -20)); |
309 | planet->show (); |
324 | planet->show (); |
|
|
325 | |
|
|
326 | planet->v = vec3 (10, 0, 0); |
|
|
327 | moveables.push_back (planet); |
|
|
328 | |
|
|
329 | doom3parse ("test.proc"); |
310 | |
330 | |
311 | for (int i = 0; i < 20; i++) |
331 | for (int i = 0; i < 20; i++) |
312 | { |
332 | { |
313 | // load a entity |
333 | // load a entity |
314 | txtprt_parser p; |
334 | txtprt_parser p; |
… | |
… | |
325 | entity *e = new entity (g); |
345 | entity *e = new entity (g); |
326 | e->move (vec3 (i*5, -3, -i*10)); |
346 | e->move (vec3 (i*5, -3, -i*10)); |
327 | e->show (); |
347 | e->show (); |
328 | } |
348 | } |
329 | |
349 | |
330 | { |
350 | { |
331 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
351 | fisch (vec3 (0, 0, -2e9), 1e9, 8); |
332 | //entity *planet = new entity (new geometry_sphere (1e9)); |
352 | //entity *planet = new entity (new geometry_sphere (1e9)); |
333 | //planet->move (vec3 (0, 0, -1.5e9)); |
353 | //planet->move (vec3 (0, 0, -1.5e9)); |
334 | //planet->show (); |
354 | //planet->show (); |
335 | } |
355 | } |
336 | |
356 | |
337 | { |
357 | { |
338 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
358 | entity *planet = new entity (new geometry_sphere (testmat, 4e15)); |
339 | planet->move (vec3 (0, 0, 1e17)); |
359 | planet->move (vec3 (0, 0, 1e17)); |
340 | planet->show (); |
360 | planet->show (); |
341 | } |
361 | } |
|
|
362 | |
|
|
363 | { |
|
|
364 | RandomBuilding r; |
|
|
365 | entity *randlvl = r.draw (1000, 1000, 200); |
|
|
366 | randlvl->move (vec3 (0, 0, 0)); |
|
|
367 | randlvl->show (); |
|
|
368 | |
|
|
369 | entity *randlvl2 = r.draw (1000, 10000, 1000); |
|
|
370 | randlvl2->move (vec3 (-20000, 0, 0)); |
|
|
371 | randlvl2->show (); |
|
|
372 | |
|
|
373 | entity *randlvl3 = r.draw (100, 30, 3); |
|
|
374 | randlvl3->move (vec3 (-1000, 0, 0)); |
|
|
375 | randlvl3->show (); |
|
|
376 | } |
342 | |
377 | |
343 | //draw_floor (10, -500, -10, -1000); |
378 | //draw_floor (10, -500, -10, -1000); |
344 | draw_level (); |
379 | draw_level (); |
345 | |
380 | |
346 | |
381 | #if 0 |
347 | { |
382 | { |
348 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
383 | geometry_heightfield *hf = new geometry_heightfield (100000., 100000.); |
349 | entity *e = new entity (hf); |
384 | entity *e = new entity (hf); |
350 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
385 | e->move (vec3 (-100000, -100000 * 0.01, -100000)); |
351 | e->show (); |
386 | e->show (); |
352 | } |
387 | } |
|
|
388 | #endif |
353 | |
389 | |
354 | //draw_test_nurb (); |
390 | //draw_test_nurb (); |
355 | |
391 | |
356 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
392 | //camera.orig.x = 108; camera.orig.y = 0; camera.orig.z = -368; |
357 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
393 | camera.orig.x = 0; camera.orig.y = 0; camera.orig.z = 0; |
… | |
… | |
359 | camera.d = vec3 (0, 0, -1); |
395 | camera.d = vec3 (0, 0, -1); |
360 | camera.u = vec3 (0, 1, 0); |
396 | camera.u = vec3 (0, 1, 0); |
361 | camera.w = w; camera.h = h; |
397 | camera.w = w; camera.h = h; |
362 | camera.fov = 40.; |
398 | camera.fov = 40.; |
363 | |
399 | |
364 | glEnable (GL_CULL_FACE); |
|
|
365 | glDisable (GL_ALPHA_TEST); |
400 | glDisable (GL_ALPHA_TEST); |
366 | glDisable (GL_BLEND); |
|
|
367 | |
401 | |
368 | /* Loop until done. */ |
402 | /* Loop until done. */ |
369 | frames = 0; |
403 | frames = 0; |
370 | |
404 | |
371 | linear_light mylight; |
405 | linear_light mylight, mylight2; |
|
|
406 | |
372 | mylight.radius = 100000; |
407 | mylight.radius = 100000; |
373 | mylight.c = colour (1., 1, 1, 1.); |
408 | mylight.c = colour (1., 1, 1, 1.); |
374 | mylight.intensity = 1.F; |
409 | mylight.intensity = 1.F; |
375 | |
410 | |
|
|
411 | mylight2.radius = 100000; |
|
|
412 | mylight2.c = colour (1., 0, 0, 1.); |
|
|
413 | mylight2.intensity = 1.F; |
|
|
414 | |
376 | pass pass_light (&mylight); |
415 | pass_data pass_light (&mylight); |
|
|
416 | pass_data pass_light2 (&mylight2); |
377 | |
417 | |
378 | while (!done) |
418 | while (!done) |
379 | { |
419 | { |
380 | char *sdl_error; |
420 | char *sdl_error; |
381 | SDL_Event event; |
421 | SDL_Event event; |
382 | |
422 | |
383 | camera_angle += 180 * camera_velocity_angle * timer.diff; |
423 | camera_angle += 90 * camera_velocity_angle * timer.diff; |
384 | camera_angle2 += 180 * camera_velocity_angle2 * timer.diff; |
424 | camera_angle2 += 90 * camera_velocity_angle2 * timer.diff; |
385 | |
425 | |
386 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
426 | vec3 geradeaus = matrix::rotation (-camera_angle, vec3 (0, 1, 0)) * vec3 (0, 0, -1); |
387 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
427 | vec3 right = matrix::rotation (90., vec3 (0, 1, 0)) * geradeaus; |
388 | |
428 | |
389 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
429 | camera.d = matrix::rotation (camera_angle2, right) * geradeaus; |
… | |
… | |
392 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
432 | camera.p = camera.p - camera.d * (camera_velocity_factor * timer.diff) * camera_velocity.z; |
393 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
433 | camera.p = camera.p - camera.u * (camera_velocity_factor * timer.diff) * camera_velocity.y; |
394 | |
434 | |
395 | mylight.orig = camera.orig; |
435 | mylight.orig = camera.orig; |
396 | mylight.p = camera.p; |
436 | mylight.p = camera.p; |
|
|
437 | |
|
|
438 | mylight2.orig = camera.orig; |
|
|
439 | mylight2.p = camera.p + vec3 (sin (timer.now * 2) * 100, 1, cos (timer.now * 2) * 100); |
397 | |
440 | |
398 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
441 | //mylight.intensity = max (sinf (timer.now) + 1.2F, 0.2F); |
399 | |
442 | |
400 | camera.begin (); |
443 | camera.begin (); |
401 | camera.render (view::DEPTH, pass_depth); |
444 | camera.render (pass_depth); |
402 | camera.render (view::POSTDEPTH, pass_depth); |
445 | camera.render (pass_postdepth); |
|
|
446 | camera.render (pass_light); |
403 | camera.render (view::LIGHTED, pass_light); |
447 | //camera.render (view::LIGHTED, pass_light2); |
404 | camera.end (); |
448 | camera.end (); |
|
|
449 | |
|
|
450 | perfom_moves (); |
405 | |
451 | |
406 | SDL_GL_SwapBuffers (); |
452 | SDL_GL_SwapBuffers (); |
407 | timer.frame (); |
453 | timer.frame (); |
408 | |
454 | |
409 | #if 0 |
455 | #if 0 |