From 4f0a1df3c1b49bb9325cd528233ac77ff779a328 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 2 Jan 2013 16:48:13 +0900 Subject: [PATCH] Implement sky tracing. Again, this is from Jardrup's light tool. Sun data is not yet parsed, nor are any sun lighting calculations done. --- tools/qflight/include/light.h | 1 + tools/qflight/source/trace.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/qflight/include/light.h b/tools/qflight/include/light.h index 436a660b7..184883746 100644 --- a/tools/qflight/include/light.h +++ b/tools/qflight/include/light.h @@ -96,6 +96,7 @@ extern float minlights[MAX_MAP_FACES]; void LoadNodes (const char *file); qboolean TestLine (lightinfo_t *l, vec3_t start, vec3_t stop); +qboolean TestSky (lightinfo_t *l, vec3_t start, vec3_t stop); void LightFace (lightinfo_t *l, int surfnum); void LightLeaf (dleaf_t *leaf); diff --git a/tools/qflight/source/trace.c b/tools/qflight/source/trace.c index 39d17ceb0..68f06f852 100644 --- a/tools/qflight/source/trace.c +++ b/tools/qflight/source/trace.c @@ -142,8 +142,8 @@ MakeTnodes (dmodel_t *bm) #define TESTLINESTATE_EMPTY 1 #define TESTLINESTATE_SOLID 2 -qboolean -TestLine (lightinfo_t *l, vec3_t start, vec3_t end) +static qboolean +TestLineOrSky (lightinfo_t *l, vec3_t start, vec3_t end, qboolean sky_test) { vec_t front, back; vec3_t frontpt, backpt; @@ -161,6 +161,8 @@ TestLine (lightinfo_t *l, vec3_t start, vec3_t end) while (1) { while (node < 0) { + if (sky_test && node == CONTENTS_SKY) + return true; if (node != CONTENTS_SOLID) empty = 1; else if (empty) { @@ -171,7 +173,7 @@ TestLine (lightinfo_t *l, vec3_t start, vec3_t end) // pop up the stack for a back side if (tstack-- == tracestack) - return true; + return !sky_test; // set the hit point for this plane VectorCopy (backpt, frontpt); @@ -219,3 +221,17 @@ TestLine (lightinfo_t *l, vec3_t start, vec3_t end) node = tnode->children[side]; } } + +qboolean +TestLine (lightinfo_t *l, vec3_t start, vec3_t stop) +{ + return TestLineOrSky (l, start, stop, false); +} + +qboolean +TestSky (lightinfo_t *l, vec3_t start, vec3_t dir) +{ + vec3_t stop; + VectorAdd (dir, start, stop); + return TestLineOrSky (l, start, stop, true); +}