nuclear@27: #include nuclear@27: #include nuclear@27: #include nuclear@27: #include nuclear@27: #include nuclear@27: #include "wvga.h" nuclear@27: #include "mingl.h" nuclear@27: #include "timer.h" nuclear@33: #include "keyb.h" nuclear@27: #include "mouse.h" nuclear@27: #include "texture.h" nuclear@27: #include "palman.h" nuclear@27: #include "scene.h" nuclear@27: nuclear@27: #define DEG2RAD(x) (M_PI * (x) / 180.0) nuclear@27: nuclear@27: static int init(void); nuclear@27: static void shutdown(void); nuclear@34: static void update(unsigned long dtmsec); nuclear@27: static void redraw(void); nuclear@27: static int proc_events(void); nuclear@27: static void mouse_button(int bn, int x, int y); nuclear@27: static void mouse_motion(int x, int y); nuclear@27: static void sighandler(int s); nuclear@27: nuclear@27: nuclear@27: static float cam_x, cam_y, cam_z; nuclear@27: static float cam_theta, cam_phi; nuclear@27: nuclear@34: static float walk_speed = 6.0; nuclear@27: static float look_speed = 1.0; nuclear@33: nuclear@33: static int mouse_look = 1; nuclear@27: nuclear@27: static void *fbuf; nuclear@27: static struct scene scn; nuclear@27: nuclear@27: nuclear@27: int main(void) nuclear@27: { nuclear@34: unsigned long prev_msec = 0; nuclear@34: nuclear@27: if(init() == -1) { nuclear@27: return 1; nuclear@27: } nuclear@27: nuclear@34: for(;;) { nuclear@34: unsigned long msec = get_msec(); nuclear@34: unsigned long dt = msec - prev_msec; nuclear@34: prev_msec = msec; nuclear@34: nuclear@34: if(!proc_events()) { nuclear@34: break; nuclear@34: } nuclear@34: nuclear@34: update(dt); nuclear@27: redraw(); nuclear@27: } nuclear@27: nuclear@27: shutdown(); nuclear@27: return 0; nuclear@27: } nuclear@27: nuclear@27: nuclear@27: static int init(void) nuclear@27: { nuclear@34: float vfov, aspect; nuclear@28: nuclear@28: aspect = 320.0 / 200.0; nuclear@28: vfov = 60.0; nuclear@28: nuclear@27: init_timer(100); nuclear@33: kb_init(16); /* 16 characters input buffer */ nuclear@27: nuclear@27: set_video_mode(0x13); nuclear@27: nuclear@27: signal(SIGINT, sighandler); nuclear@27: signal(SIGSEGV, sighandler); nuclear@27: signal(SIGFPE, sighandler); nuclear@27: signal(SIGILL, sighandler); nuclear@27: signal(SIGABRT, sighandler); nuclear@27: nuclear@27: if(mgl_init(320, 200) == -1) { nuclear@27: fprintf(stderr, "mgl init failed\n"); nuclear@27: return -1; nuclear@27: } nuclear@27: fbuf = mgl_framebuffer(); nuclear@27: nuclear@27: mgl_enable(MGL_CULL_FACE); nuclear@27: mgl_enable(MGL_SMOOTH); nuclear@27: mgl_enable(MGL_LIGHTING); nuclear@27: mgl_enable(MGL_DEPTH_TEST); nuclear@27: nuclear@27: mgl_matrix_mode(MGL_PROJECTION); nuclear@27: mgl_load_identity(); nuclear@28: mgl_perspective(vfov, aspect, 0.5, 200.0); nuclear@28: nuclear@28: #if 0 nuclear@28: mgl_enable(MGL_CLIP_PLANE0); nuclear@28: mgl_enable(MGL_CLIP_PLANE1); nuclear@28: mgl_enable(MGL_CLIP_PLANE2); nuclear@28: mgl_enable(MGL_CLIP_PLANE3); nuclear@28: mgl_clip_plane(MGL_CLIP_PLANE0, -1, 0, -1, 0); /* positive X */ nuclear@28: mgl_clip_plane(MGL_CLIP_PLANE1, 1, 0, -1, 0); /* negative X */ nuclear@28: mgl_clip_plane(MGL_CLIP_PLANE2, 0, -1, -0.5, 0); /* positive Y */ nuclear@28: mgl_clip_plane(MGL_CLIP_PLANE3, 0, 1, -0.5, 0); /* negative Y */ nuclear@28: #endif nuclear@27: nuclear@27: /* setup palette */ nuclear@27: palm_add_color(255, 255, 255); nuclear@27: nuclear@27: scn_init(&scn); nuclear@27: if(scn_load(&scn, "data/hall.obj") == -1) { nuclear@27: return -1; nuclear@27: } nuclear@27: nuclear@27: palm_build(); nuclear@27: { nuclear@27: int i, palsz = palm_palette_size(); nuclear@27: struct palm_color *pal = palm_palette(); nuclear@27: nuclear@27: for(i=0; i 90) { nuclear@27: cam_phi = 90; nuclear@27: } nuclear@27: } nuclear@27: } nuclear@27: nuclear@27: static void sighandler(int s) nuclear@27: { nuclear@27: set_video_mode(3); nuclear@27: nuclear@27: switch(s) { nuclear@27: case SIGABRT: nuclear@27: fprintf(stderr, "abort\n"); nuclear@27: break; nuclear@27: nuclear@27: case SIGILL: nuclear@27: fprintf(stderr, "illegal operation\n"); nuclear@27: break; nuclear@27: nuclear@27: case SIGSEGV: nuclear@27: fprintf(stderr, "segmentation fault\n"); nuclear@27: break; nuclear@27: nuclear@27: case SIGINT: nuclear@27: fprintf(stderr, "interrupted\n"); nuclear@27: break; nuclear@27: nuclear@27: case SIGFPE: nuclear@27: fprintf(stderr, "floating point exception\n"); nuclear@27: break; nuclear@27: nuclear@27: default: nuclear@27: fprintf(stderr, "unexpected signal\n"); nuclear@27: } nuclear@27: nuclear@27: exit(1); nuclear@27: }