nuclear@14: #include nuclear@14: #include nuclear@14: #include nuclear@14: #include nuclear@14: #include nuclear@14: #include "vga.h" nuclear@14: #include "mingl.h" nuclear@14: #include "timer.h" nuclear@14: #include "mouse.h" nuclear@14: #include "texture.h" nuclear@14: #include "palman.h" nuclear@14: #include "scene.h" nuclear@14: nuclear@14: #define DEG2RAD(x) (M_PI * (x) / 180.0) nuclear@14: nuclear@14: static int init(void); nuclear@14: static void shutdown(void); nuclear@14: static void redraw(void); nuclear@14: static int proc_events(void); nuclear@14: static int keyb(int key); nuclear@14: static void mouse_button(int bn, int x, int y); nuclear@14: static void mouse_motion(int x, int y); nuclear@14: static void sighandler(int s); nuclear@14: nuclear@14: nuclear@14: static float cam_x, cam_y, cam_z = 10; nuclear@14: static float cam_theta, cam_phi; nuclear@14: nuclear@14: static float walk_speed = 0.1; nuclear@14: static float look_speed = 1.0; nuclear@14: static int mouse_look = 0; nuclear@14: nuclear@14: static void *fbuf; nuclear@14: static struct scene scn; nuclear@14: nuclear@14: nuclear@14: int main(void) nuclear@14: { nuclear@14: if(init() == -1) { nuclear@14: return 1; nuclear@14: } nuclear@14: nuclear@14: while(proc_events()) { nuclear@14: redraw(); nuclear@14: } nuclear@14: nuclear@14: shutdown(); nuclear@14: return 0; nuclear@14: } nuclear@14: nuclear@14: nuclear@14: static int init(void) nuclear@14: { nuclear@14: init_timer(100); nuclear@14: nuclear@14: set_video_mode(0x13); nuclear@14: nuclear@14: signal(SIGINT, sighandler); nuclear@14: signal(SIGSEGV, sighandler); nuclear@14: signal(SIGFPE, sighandler); nuclear@14: signal(SIGILL, sighandler); nuclear@14: signal(SIGABRT, sighandler); nuclear@14: nuclear@14: if(mgl_init(320, 200) == -1) { nuclear@14: fprintf(stderr, "mgl init failed\n"); nuclear@14: return -1; nuclear@14: } nuclear@14: fbuf = mgl_framebuffer(); nuclear@14: nuclear@14: mgl_enable(MGL_CULL_FACE); nuclear@14: mgl_enable(MGL_SMOOTH); nuclear@14: mgl_enable(MGL_LIGHTING); nuclear@14: mgl_enable(MGL_DEPTH_TEST); nuclear@14: nuclear@14: mgl_matrix_mode(MGL_PROJECTION); nuclear@14: mgl_load_identity(); nuclear@14: mgl_perspective(45.0, 320.0 / 200.0, 0.5, 200.0); nuclear@14: nuclear@14: /* setup palette */ nuclear@14: palm_add_color(255, 255, 255); nuclear@14: nuclear@14: scn_init(&scn); nuclear@14: if(scn_load(&scn, "data/hall.obj") == -1) { nuclear@14: return -1; nuclear@14: } nuclear@14: nuclear@14: palm_build(); nuclear@14: { nuclear@14: int i, palsz = palm_palette_size(); nuclear@14: struct palm_color *pal = palm_palette(); nuclear@14: nuclear@14: for(i=0; i 90) { nuclear@14: cam_phi = 90; nuclear@14: } nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: static void sighandler(int s) nuclear@14: { nuclear@14: set_video_mode(3); nuclear@14: nuclear@14: switch(s) { nuclear@14: case SIGABRT: nuclear@14: fprintf(stderr, "abort\n"); nuclear@14: break; nuclear@14: nuclear@14: case SIGILL: nuclear@14: fprintf(stderr, "illegal operation\n"); nuclear@14: break; nuclear@14: nuclear@14: case SIGSEGV: nuclear@14: fprintf(stderr, "segmentation fault\n"); nuclear@14: break; nuclear@14: nuclear@14: case SIGINT: nuclear@14: fprintf(stderr, "interrupted\n"); nuclear@14: break; nuclear@14: nuclear@14: case SIGFPE: nuclear@14: fprintf(stderr, "floating point exception\n"); nuclear@14: break; nuclear@14: nuclear@14: default: nuclear@14: fprintf(stderr, "unexpected signal\n"); nuclear@14: } nuclear@14: nuclear@14: exit(1); nuclear@14: }