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