projects
/
dosdemo
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
debugging the BSP
[dosdemo]
/
src
/
polytest.c
diff --git
a/src/polytest.c
b/src/polytest.c
index
85b3128
..
dfca5ef
100644
(file)
--- a/
src/polytest.c
+++ b/
src/polytest.c
@@
-9,6
+9,7
@@
#include "polyfill.h" /* just for struct pimage */
#include "cfgopt.h"
#include "mesh.h"
#include "polyfill.h" /* just for struct pimage */
#include "cfgopt.h"
#include "mesh.h"
+#include "bsptree.h"
static int init(void);
static void destroy(void);
static int init(void);
static void destroy(void);
@@
-28,6
+29,7
@@
static struct screen scr = {
static float cam_theta, cam_phi = 25;
static float cam_dist = 3;
static struct g3d_mesh cube, torus;
static float cam_theta, cam_phi = 25;
static float cam_dist = 3;
static struct g3d_mesh cube, torus;
+static struct bsptree torus_bsp;
static struct pimage tex;
static struct pimage tex;
@@
-52,6
+54,12
@@
static int init(void)
torus.varr[i].v *= 2.0;
}
torus.varr[i].v *= 2.0;
}
+ init_bsp(&torus_bsp);
+ if(bsp_add_mesh(&torus_bsp, &torus) == -1) {
+ fprintf(stderr, "failed to construct torus BSP tree\n");
+ return -1;
+ }
+
gen_texture(&tex, 128, 128);
#ifdef DEBUG_POLYFILL
gen_texture(&tex, 128, 128);
#ifdef DEBUG_POLYFILL
@@
-70,6
+78,7
@@
static void destroy(void)
free(cube.varr);
free(torus.varr);
free(torus.iarr);
free(cube.varr);
free(torus.varr);
free(torus.iarr);
+ destroy_bsp(&torus_bsp);
}
static void start(long trans_time)
}
static void start(long trans_time)
@@
-93,6
+102,9
@@
static void update(void)
static void draw(void)
{
static void draw(void)
{
+ float vdir[3];
+ float mat[16];
+
update();
memset(fb_pixels, 0, fb_width * fb_height * 2);
update();
memset(fb_pixels, 0, fb_width * fb_height * 2);
@@
-107,6
+119,14
@@
static void draw(void)
g3d_rotate(cam_theta, 0, 1, 0);
}
g3d_rotate(cam_theta, 0, 1, 0);
}
+ /* calc world-space view direction */
+ g3d_get_matrix(G3D_MODELVIEW, mat);
+ /* transform (0, 0, -1) with transpose(mat3x3) */
+ vdir[0] = -mat[2];
+ vdir[1] = -mat[6];
+ vdir[2] = -mat[10];
+
+
g3d_light_pos(0, -10, 10, 20);
zsort_mesh(&torus);
g3d_light_pos(0, -10, 10, 20);
zsort_mesh(&torus);
@@
-114,7
+134,8
@@
static void draw(void)
g3d_mtl_diffuse(0.4, 0.7, 1.0);
g3d_set_texture(tex.width, tex.height, tex.pixels);
g3d_mtl_diffuse(0.4, 0.7, 1.0);
g3d_set_texture(tex.width, tex.height, tex.pixels);
- draw_mesh(&torus);
+ /*draw_mesh(&torus);*/
+ draw_bsp(&torus_bsp, vdir[0], vdir[1], vdir[2]);
/*draw_mesh(&cube);*/
swap_buffers(fb_pixels);
/*draw_mesh(&cube);*/
swap_buffers(fb_pixels);