X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fmain.c;fp=src%2Fmain.c;h=f95428fc2bf37d86b282a4b7a0c995db303cb94b;hb=f376a88158f9f99d738a51e306d137de62124569;hp=195f4a62f52b11d4efae03476c5e20e3c128ecb6;hpb=5b98299a1aa716cc17cb5f70498c8e23cac945cb;p=gba_blender diff --git a/src/main.c b/src/main.c index 195f4a6..f95428f 100644 --- a/src/main.c +++ b/src/main.c @@ -25,6 +25,7 @@ along with this program. If not, see . #include "xgl.h" #include "polyfill.h" #include "debug.h" +#include "meshdata.h" #define MENU_HEIGHT 17 #define TRACK_HEIGHT 18 @@ -35,25 +36,15 @@ static void handle_keys(void); extern struct { unsigned char r, g, b; } bgimg_cmap[]; extern unsigned char bgimg_pixels[]; -struct xvertex varr[] = { - {0, -0xd000}, - {-0x8000, 0x7000}, - {0x8000, 0x7000} -}; +static int32_t cam_theta, cam_phi; int main(void) { int i; unsigned int nframes = 0, backbuf; - unsigned long tm0, tm; uint16_t *cptr; unsigned char r, g, b; unsigned char *fbptr[2], *fb; - struct pvertex benchv[3] = { - {120 << 8, 8 << 8}, - {75 << 8, 110 << 8}, - {164 << 8, 80 << 8} - }; intr_init(); reset_msec_timer(); @@ -86,18 +77,11 @@ int main(void) xgl_init(); xgl_viewport(0, MENU_HEIGHT, 240, VP_HEIGHT); - /* benchmark */ - polyfill_framebuffer(fbptr[0] + 240 * MENU_HEIGHT, 240, VP_HEIGHT); - tm0 = timer_msec; - for(i=0; i<2048; i++) { - polyfill_flat(benchv, 3, 128 + (i & 0x7f)); - } - tm = timer_msec - tm0; - emuprint("benchmark: %lu ms\n", tm); - - /*key_repeat(500, 75, KEY_LEFT | KEY_RIGHT | KEY_DOWN | KEY_UP);*/ + key_repeat(75, 75, KEY_LEFT | KEY_RIGHT | KEY_DOWN | KEY_UP); for(;;) { + handle_keys(); + backbuf = ++nframes & 1; fb = fbptr[backbuf] + 240 * MENU_HEIGHT; @@ -105,8 +89,10 @@ int main(void) memset(fb, 14, 240 * VP_HEIGHT); xgl_load_identity(); - xgl_rotate_z(nframes << 8); - xgl_draw(XGL_TRIANGLES, varr, 3); + xgl_translate(0, 0, 5 << 16); + xgl_rotate_x(cam_phi); + xgl_rotate_y(cam_theta); + xgl_draw(XGL_QUADS, cube, sizeof cube / sizeof *cube); wait_vblank(); present(backbuf); @@ -120,11 +106,17 @@ static void handle_keys(void) update_keyb(); if(KEYPRESS(KEY_UP)) { + cam_phi += 0x2000; + if(cam_phi > X_HPI) cam_phi = X_HPI; } if(KEYPRESS(KEY_DOWN)) { + cam_phi -= 0x2000; + if(cam_phi < -X_HPI) cam_phi = -X_HPI; } if(KEYPRESS(KEY_LEFT)) { + cam_theta += 0x2000; } if(KEYPRESS(KEY_RIGHT)) { + cam_theta -= 0x2000; } }