X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fpolytest.c;h=afe20069968f53a34c0ab917d0c859a529d38dbb;hp=8d81262196a5cea3b542f4105b7cce3388282ea9;hb=77e0277af0c00dae78c7a739b2ca70cc19fd041a;hpb=32ff3cf2d7d7a5ae82f5ca400b320c67e6984ad6 diff --git a/src/polytest.c b/src/polytest.c index 8d81262..afe2006 100644 --- a/src/polytest.c +++ b/src/polytest.c @@ -23,7 +23,8 @@ static struct screen scr = { init, destroy, start, 0, - draw + draw, + 0 }; static float cam_theta, cam_phi = 25; @@ -33,6 +34,8 @@ static struct bsptree torus_bsp; static struct pimage tex; +static int use_bsp = 1; + #define LOWRES_SCALE 10 static uint16_t *lowres_pixels; static int lowres_width, lowres_height; @@ -102,6 +105,9 @@ static void update(void) static void draw(void) { + float vdir[3]; + const float *mat; + update(); memset(fb_pixels, 0, fb_width * fb_height * 2); @@ -118,13 +124,22 @@ static void draw(void) g3d_light_pos(0, -10, 10, 20); - zsort_mesh(&torus); - g3d_mtl_diffuse(0.4, 0.7, 1.0); g3d_set_texture(tex.width, tex.height, tex.pixels); - draw_mesh(&torus); - /*draw_bsp(&torus_bsp);*/ + if(use_bsp) { + /* calc world-space view direction */ + mat = g3d_get_matrix(G3D_MODELVIEW, 0); + /* transform (0, 0, -1) with transpose(mat3x3) */ + vdir[0] = -mat[2]; + vdir[1] = -mat[6]; + vdir[2] = -mat[10]; + + draw_bsp(&torus_bsp, vdir[0], vdir[1], vdir[2]); + } else { + zsort_mesh(&torus); + draw_mesh(&torus); + } /*draw_mesh(&cube);*/ swap_buffers(fb_pixels);