Moved modified HL SDK to trunk
This commit is contained in:
228
hlsdk/utils/light/light.c
Normal file
228
hlsdk/utils/light/light.c
Normal file
@ -0,0 +1,228 @@
|
||||
//========= Copyright <20> 1996-2002, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
// lighting.c
|
||||
|
||||
#include "light.h"
|
||||
|
||||
/*
|
||||
|
||||
NOTES
|
||||
-----
|
||||
|
||||
*/
|
||||
|
||||
float scaledist = 1.0;
|
||||
float scalecos = 0.5;
|
||||
float rangescale = 0.5;
|
||||
|
||||
byte *filebase, *file_p, *file_end;
|
||||
|
||||
dmodel_t *bspmodel;
|
||||
|
||||
vec3_t bsp_origin;
|
||||
|
||||
qboolean extrasamples;
|
||||
qboolean hicolor;
|
||||
qboolean clamp192 = true;
|
||||
|
||||
float minlights[MAX_MAP_FACES];
|
||||
|
||||
lightentity_t lightentities[MAX_MAP_ENTITIES];
|
||||
int numlightentities;
|
||||
|
||||
|
||||
/*
|
||||
==================
|
||||
LoadEntities
|
||||
==================
|
||||
*/
|
||||
void LoadEntities (void)
|
||||
{
|
||||
char *s, *s2;
|
||||
entity_t *e;
|
||||
lightentity_t *le;
|
||||
int i, j;
|
||||
|
||||
ParseEntities ();
|
||||
|
||||
// go through all the entities
|
||||
for (i=1 ; i<num_entities ; i++)
|
||||
{
|
||||
e = &entities[i];
|
||||
|
||||
s = ValueForKey (e, "classname");
|
||||
if (strncmp (s, "light", 5))
|
||||
continue;
|
||||
|
||||
le = &lightentities[numlightentities];
|
||||
numlightentities++;
|
||||
|
||||
strcpy (le->classname, s);
|
||||
s = ValueForKey( e, "_light" );
|
||||
if( s )
|
||||
{
|
||||
double v1, v2, v3;
|
||||
|
||||
v1 = v2 = v3 = 0;
|
||||
if( sscanf( s, "%lf %lf %lf", &v1, &v2, &v3) != 3 )
|
||||
v2 = v3 = v1;
|
||||
|
||||
le->light[0] = v1;
|
||||
le->light[1] = v2;
|
||||
le->light[2] = v3;
|
||||
}
|
||||
else
|
||||
{
|
||||
le->light[0] = DEFAULTLIGHTLEVEL;
|
||||
le->light[1] = DEFAULTLIGHTLEVEL;
|
||||
le->light[2] = DEFAULTLIGHTLEVEL;
|
||||
}
|
||||
|
||||
le->style = FloatForKey (e, "style");
|
||||
le->angle = FloatForKey (e, "angle");
|
||||
GetVectorForKey (e, "origin", le->origin);
|
||||
|
||||
s = ValueForKey (e, "target");
|
||||
if (!s[0])
|
||||
continue;
|
||||
|
||||
// find matching targetname
|
||||
for (j=1 ; j<num_entities ; j++)
|
||||
{
|
||||
s2 = ValueForKey (&entities[j], "targetname");
|
||||
if (!strcmp (s, s2))
|
||||
{
|
||||
le->targetent = true;
|
||||
GetVectorForKey (&entities[j], "origin", le->targetorigin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == num_entities)
|
||||
printf ("WARNING: entity %i has unmatched target %s\n", i, s);
|
||||
}
|
||||
|
||||
qprintf ("%d lightentities\n", numlightentities);
|
||||
|
||||
}
|
||||
|
||||
|
||||
byte *GetFileSpace (int size)
|
||||
{
|
||||
byte *buf;
|
||||
|
||||
ThreadLock();
|
||||
file_p = (byte *)(((long)file_p + 3)&~3);
|
||||
buf = file_p;
|
||||
file_p += size;
|
||||
ThreadUnlock();
|
||||
if (file_p > file_end)
|
||||
Error ("GetFileSpace: overrun");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
LightWorld
|
||||
=============
|
||||
*/
|
||||
void LightWorld (void)
|
||||
{
|
||||
filebase = file_p = dlightdata;
|
||||
file_end = filebase + MAX_MAP_LIGHTING;
|
||||
|
||||
RunThreadsOnIndividual (numfaces, true, LightFace);
|
||||
|
||||
lightdatasize = file_p - filebase;
|
||||
|
||||
printf ("lightdatasize: %i\n", lightdatasize);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
========
|
||||
main
|
||||
|
||||
light modelfile
|
||||
========
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
double start, end;
|
||||
char source[1024];
|
||||
|
||||
printf("Light.exe Version 1.3 Id Software and valve (%s)\n", __DATE__ );
|
||||
printf ("----- LightFaces ----\n");
|
||||
|
||||
// default to 24-bit light info
|
||||
hicolor = true;
|
||||
|
||||
for (i=1 ; i<argc ; i++)
|
||||
{
|
||||
if (!strcmp(argv[i],"-threads"))
|
||||
{
|
||||
numthreads = atoi (argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if (!strcmp(argv[i],"-extra"))
|
||||
{
|
||||
extrasamples = true;
|
||||
printf ("extra sampling enabled\n");
|
||||
}
|
||||
else if (!strcmp(argv[i],"-dist"))
|
||||
{
|
||||
scaledist = atof (argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if (!strcmp(argv[i],"-range"))
|
||||
{
|
||||
rangescale = atof (argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if (!strcmp(argv[i],"-lowcolor"))
|
||||
{
|
||||
hicolor = false;
|
||||
}
|
||||
else if (!strcmp( argv[ i ], "-noclamp" ) )
|
||||
{
|
||||
clamp192 = false;
|
||||
}
|
||||
else if (argv[i][0] == '-')
|
||||
Error ("Unknown option \"%s\"", argv[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (i != argc - 1)
|
||||
Error ("usage: light [-threads num] [-extra] [-lowcolor] bspfile");
|
||||
|
||||
ThreadSetDefault ();
|
||||
|
||||
start = I_FloatTime ();
|
||||
|
||||
strcpy (source, argv[i]);
|
||||
StripExtension (source);
|
||||
DefaultExtension (source, ".bsp");
|
||||
|
||||
LoadBSPFile (source);
|
||||
LoadEntities ();
|
||||
|
||||
MakeTnodes (&dmodels[0]);
|
||||
|
||||
LightWorld ();
|
||||
|
||||
WriteBSPFile (source);
|
||||
|
||||
end = I_FloatTime ();
|
||||
printf ("%5.1f seconds elapsed\n", end-start);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
61
hlsdk/utils/light/light.h
Normal file
61
hlsdk/utils/light/light.h
Normal file
@ -0,0 +1,61 @@
|
||||
//========= Copyright <20> 1996-2002, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "mathlib.h"
|
||||
#include "bspfile.h"
|
||||
#include "threads.h"
|
||||
|
||||
|
||||
#define DEFAULTLIGHTLEVEL 300
|
||||
|
||||
typedef struct entity_s
|
||||
{
|
||||
char classname[64];
|
||||
vec3_t origin;
|
||||
float angle;
|
||||
vec3_t light;
|
||||
int style;
|
||||
qboolean targetent;
|
||||
vec3_t targetorigin;
|
||||
} lightentity_t;
|
||||
|
||||
extern lightentity_t lightentities[MAX_MAP_ENTITIES];
|
||||
extern int numlightentities;
|
||||
|
||||
#undef ON_EPSILON
|
||||
#define ON_EPSILON 0.1
|
||||
|
||||
#define MAXLIGHTS 1024
|
||||
|
||||
void LoadNodes (char *file);
|
||||
qboolean TestLine (vec3_t start, vec3_t stop);
|
||||
|
||||
void LightFace (int surfnum);
|
||||
void LightLeaf (dleaf_t *leaf);
|
||||
|
||||
void MakeTnodes (dmodel_t *bm);
|
||||
|
||||
extern float scaledist;
|
||||
extern float scalecos;
|
||||
extern float rangescale;
|
||||
|
||||
extern int c_culldistplane, c_proper;
|
||||
|
||||
byte *GetFileSpace (int size);
|
||||
extern byte *filebase;
|
||||
|
||||
extern vec3_t bsp_origin;
|
||||
extern vec3_t bsp_xvector;
|
||||
extern vec3_t bsp_yvector;
|
||||
|
||||
void TransformSample (vec3_t in, vec3_t out);
|
||||
void RotateSample (vec3_t in, vec3_t out);
|
||||
|
||||
extern qboolean extrasamples;
|
||||
|
||||
extern float minlights[MAX_MAP_FACES];
|
688
hlsdk/utils/light/ltface.c
Normal file
688
hlsdk/utils/light/ltface.c
Normal file
@ -0,0 +1,688 @@
|
||||
//========= Copyright <20> 1996-2002, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#include "light.h"
|
||||
|
||||
extern qboolean hicolor;
|
||||
extern qboolean clamp192;
|
||||
|
||||
/*
|
||||
============
|
||||
CastRay
|
||||
|
||||
Returns the distance between the points, or -1 if blocked
|
||||
=============
|
||||
*/
|
||||
vec_t CastRay (vec3_t p1, vec3_t p2)
|
||||
{
|
||||
int i;
|
||||
vec_t t;
|
||||
qboolean trace;
|
||||
|
||||
trace = TestLine (p1, p2);
|
||||
|
||||
if (!trace)
|
||||
return -1; // ray was blocked
|
||||
|
||||
t = 0;
|
||||
for (i=0 ; i< 3 ; i++)
|
||||
t += (p2[i]-p1[i]) * (p2[i]-p1[i]);
|
||||
|
||||
if (t == 0)
|
||||
t = 1; // don't blow up...
|
||||
return sqrt(t);
|
||||
}
|
||||
|
||||
/*
|
||||
===============================================================================
|
||||
|
||||
SAMPLE POINT DETERMINATION
|
||||
|
||||
void SetupBlock (dface_t *f) Returns with surfpt[] set
|
||||
|
||||
This is a little tricky because the lightmap covers more area than the face.
|
||||
If done in the straightforward fashion, some of the
|
||||
sample points will be inside walls or on the other side of walls, causing
|
||||
false shadows and light bleeds.
|
||||
|
||||
To solve this, I only consider a sample point valid if a line can be drawn
|
||||
between it and the exact midpoint of the face. If invalid, it is adjusted
|
||||
towards the center until it is valid.
|
||||
|
||||
(this doesn't completely work)
|
||||
|
||||
===============================================================================
|
||||
*/
|
||||
|
||||
#define SINGLEMAP (18*18*4)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3_t lightmaps[MAXLIGHTMAPS][SINGLEMAP];
|
||||
int numlightstyles;
|
||||
vec_t *light;
|
||||
vec_t facedist;
|
||||
vec3_t facenormal;
|
||||
|
||||
int numsurfpt;
|
||||
vec3_t surfpt[SINGLEMAP];
|
||||
|
||||
vec3_t texorg;
|
||||
vec3_t worldtotex[2]; // s = (world - texorg) . worldtotex[0]
|
||||
vec3_t textoworld[2]; // world = texorg + s * textoworld[0]
|
||||
|
||||
vec_t exactmins[2], exactmaxs[2];
|
||||
|
||||
int texmins[2], texsize[2];
|
||||
int lightstyles[256];
|
||||
int surfnum;
|
||||
dface_t *face;
|
||||
} lightinfo_t;
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
CalcFaceVectors
|
||||
|
||||
Fills in texorg, worldtotex. and textoworld
|
||||
================
|
||||
*/
|
||||
void CalcFaceVectors (lightinfo_t *l)
|
||||
{
|
||||
texinfo_t *tex;
|
||||
int i, j;
|
||||
vec3_t texnormal;
|
||||
float distscale;
|
||||
vec_t dist, len;
|
||||
|
||||
tex = &texinfo[l->face->texinfo];
|
||||
|
||||
// convert from float to vec_t
|
||||
for (i=0 ; i<2 ; i++)
|
||||
for (j=0 ; j<3 ; j++)
|
||||
l->worldtotex[i][j] = tex->vecs[i][j];
|
||||
|
||||
// calculate a normal to the texture axis. points can be moved along this
|
||||
// without changing their S/T
|
||||
texnormal[0] = tex->vecs[1][1]*tex->vecs[0][2]
|
||||
- tex->vecs[1][2]*tex->vecs[0][1];
|
||||
texnormal[1] = tex->vecs[1][2]*tex->vecs[0][0]
|
||||
- tex->vecs[1][0]*tex->vecs[0][2];
|
||||
texnormal[2] = tex->vecs[1][0]*tex->vecs[0][1]
|
||||
- tex->vecs[1][1]*tex->vecs[0][0];
|
||||
VectorNormalize (texnormal);
|
||||
|
||||
// flip it towards plane normal
|
||||
distscale = DotProduct (texnormal, l->facenormal);
|
||||
if (!distscale)
|
||||
Error ("Texture axis perpendicular to face");
|
||||
if (distscale < 0)
|
||||
{
|
||||
distscale = -distscale;
|
||||
VectorSubtract (vec3_origin, texnormal, texnormal);
|
||||
}
|
||||
|
||||
// distscale is the ratio of the distance along the texture normal to
|
||||
// the distance along the plane normal
|
||||
distscale = 1/distscale;
|
||||
|
||||
for (i=0 ; i<2 ; i++)
|
||||
{
|
||||
len = VectorLength (l->worldtotex[i]);
|
||||
dist = DotProduct (l->worldtotex[i], l->facenormal);
|
||||
dist *= distscale;
|
||||
VectorMA (l->worldtotex[i], -dist, texnormal, l->textoworld[i]);
|
||||
VectorScale (l->textoworld[i], (1/len)*(1/len), l->textoworld[i]);
|
||||
}
|
||||
|
||||
|
||||
// calculate texorg on the texture plane
|
||||
for (i=0 ; i<3 ; i++)
|
||||
l->texorg[i] = -tex->vecs[0][3]* l->textoworld[0][i] - tex->vecs[1][3] * l->textoworld[1][i];
|
||||
|
||||
// project back to the face plane
|
||||
dist = DotProduct (l->texorg, l->facenormal) - l->facedist - 1;
|
||||
dist *= distscale;
|
||||
VectorMA (l->texorg, -dist, texnormal, l->texorg);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
CalcFaceExtents
|
||||
|
||||
Fills in s->texmins[] and s->texsize[]
|
||||
also sets exactmins[] and exactmaxs[]
|
||||
================
|
||||
*/
|
||||
void CalcFaceExtents (lightinfo_t *l)
|
||||
{
|
||||
dface_t *s;
|
||||
vec_t mins[2], maxs[2], val;
|
||||
int i,j, e;
|
||||
dvertex_t *v;
|
||||
texinfo_t *tex;
|
||||
|
||||
s = l->face;
|
||||
|
||||
mins[0] = mins[1] = 999999;
|
||||
maxs[0] = maxs[1] = -99999;
|
||||
|
||||
tex = &texinfo[s->texinfo];
|
||||
|
||||
for (i=0 ; i<s->numedges ; i++)
|
||||
{
|
||||
e = dsurfedges[s->firstedge+i];
|
||||
if (e >= 0)
|
||||
v = dvertexes + dedges[e].v[0];
|
||||
else
|
||||
v = dvertexes + dedges[-e].v[1];
|
||||
|
||||
for (j=0 ; j<2 ; j++)
|
||||
{
|
||||
val = v->point[0] * tex->vecs[j][0] +
|
||||
v->point[1] * tex->vecs[j][1] +
|
||||
v->point[2] * tex->vecs[j][2] +
|
||||
tex->vecs[j][3];
|
||||
if (val < mins[j])
|
||||
mins[j] = val;
|
||||
if (val > maxs[j])
|
||||
maxs[j] = val;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0 ; i<2 ; i++)
|
||||
{
|
||||
l->exactmins[i] = mins[i];
|
||||
l->exactmaxs[i] = maxs[i];
|
||||
|
||||
mins[i] = floor(mins[i]/16);
|
||||
maxs[i] = ceil(maxs[i]/16);
|
||||
|
||||
l->texmins[i] = mins[i];
|
||||
l->texsize[i] = maxs[i] - mins[i];
|
||||
if (l->texsize[i] > 17)
|
||||
Error ("Bad surface extents");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
CalcPoints
|
||||
|
||||
For each texture aligned grid point, back project onto the plane
|
||||
to get the world xyz value of the sample point
|
||||
=================
|
||||
*/
|
||||
int c_bad;
|
||||
void CalcPoints (lightinfo_t *l)
|
||||
{
|
||||
int i;
|
||||
int s, t, j;
|
||||
int w, h, step;
|
||||
vec_t starts, startt, us, ut;
|
||||
vec_t *surf;
|
||||
vec_t mids, midt;
|
||||
vec3_t facemid, move;
|
||||
|
||||
//
|
||||
// fill in surforg
|
||||
// the points are biased towards the center of the surface
|
||||
// to help avoid edge cases just inside walls
|
||||
//
|
||||
surf = l->surfpt[0];
|
||||
mids = (l->exactmaxs[0] + l->exactmins[0])/2;
|
||||
midt = (l->exactmaxs[1] + l->exactmins[1])/2;
|
||||
|
||||
for (j=0 ; j<3 ; j++)
|
||||
facemid[j] = l->texorg[j] + l->textoworld[0][j]*mids + l->textoworld[1][j]*midt;
|
||||
|
||||
if (extrasamples)
|
||||
{ // extra filtering
|
||||
h = (l->texsize[1]+1)*2;
|
||||
w = (l->texsize[0]+1)*2;
|
||||
starts = (l->texmins[0]-0.5)*16;
|
||||
startt = (l->texmins[1]-0.5)*16;
|
||||
step = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
h = l->texsize[1]+1;
|
||||
w = l->texsize[0]+1;
|
||||
starts = l->texmins[0]*16;
|
||||
startt = l->texmins[1]*16;
|
||||
step = 16;
|
||||
}
|
||||
|
||||
l->numsurfpt = w * h;
|
||||
for (t=0 ; t<h ; t++)
|
||||
{
|
||||
for (s=0 ; s<w ; s++, surf+=3)
|
||||
{
|
||||
us = starts + s*step;
|
||||
ut = startt + t*step;
|
||||
|
||||
// if a line can be traced from surf to facemid, the point is good
|
||||
for (i=0 ; i<6 ; i++)
|
||||
{
|
||||
// calculate texture point
|
||||
for (j=0 ; j<3 ; j++)
|
||||
surf[j] = l->texorg[j] + l->textoworld[0][j]*us
|
||||
+ l->textoworld[1][j]*ut;
|
||||
|
||||
if (CastRay (facemid, surf) != -1)
|
||||
break; // got it
|
||||
if (i & 1)
|
||||
{
|
||||
if (us > mids)
|
||||
{
|
||||
us -= 8;
|
||||
if (us < mids)
|
||||
us = mids;
|
||||
}
|
||||
else
|
||||
{
|
||||
us += 8;
|
||||
if (us > mids)
|
||||
us = mids;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ut > midt)
|
||||
{
|
||||
ut -= 8;
|
||||
if (ut < midt)
|
||||
ut = midt;
|
||||
}
|
||||
else
|
||||
{
|
||||
ut += 8;
|
||||
if (ut > midt)
|
||||
ut = midt;
|
||||
}
|
||||
}
|
||||
|
||||
// move surf 8 pixels towards the center
|
||||
VectorSubtract (facemid, surf, move);
|
||||
VectorNormalize (move);
|
||||
VectorMA (surf, 8, move, surf);
|
||||
}
|
||||
if (i == 2)
|
||||
c_bad++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============================================================================
|
||||
|
||||
FACE LIGHTING
|
||||
|
||||
===============================================================================
|
||||
*/
|
||||
|
||||
int c_culldistplane, c_proper;
|
||||
|
||||
/*
|
||||
================
|
||||
SingleLightFace
|
||||
================
|
||||
*/
|
||||
void SingleLightFace (lightentity_t *light, lightinfo_t *l)
|
||||
{
|
||||
vec_t dist;
|
||||
vec3_t incoming;
|
||||
vec_t angle;
|
||||
vec_t add;
|
||||
vec_t *surf;
|
||||
qboolean hit;
|
||||
int mapnum;
|
||||
int size;
|
||||
int c, i;
|
||||
vec3_t rel;
|
||||
vec3_t spotvec;
|
||||
vec_t falloff;
|
||||
vec3_t *lightsamp;
|
||||
float intensity;
|
||||
|
||||
VectorSubtract (light->origin, bsp_origin, rel);
|
||||
dist = scaledist * (DotProduct (rel, l->facenormal) - l->facedist);
|
||||
|
||||
// don't bother with lights behind the surface
|
||||
if (dist <= 0)
|
||||
return;
|
||||
|
||||
// don't bother with light too far away
|
||||
intensity = ( light->light[ 0 ] + light->light[ 1 ] + light->light[ 2 ] ) / 3.0;
|
||||
if( dist > intensity )
|
||||
{
|
||||
c_culldistplane++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (light->targetent)
|
||||
{
|
||||
VectorSubtract (light->targetorigin, light->origin, spotvec);
|
||||
VectorNormalize (spotvec);
|
||||
if (!light->angle)
|
||||
falloff = -cos(20*Q_PI/180);
|
||||
else
|
||||
falloff = -cos(light->angle/2*Q_PI/180);
|
||||
}
|
||||
else
|
||||
falloff = 0; // shut up compiler warnings
|
||||
|
||||
mapnum = 0;
|
||||
for (mapnum=0 ; mapnum<l->numlightstyles ; mapnum++)
|
||||
if (l->lightstyles[mapnum] == light->style)
|
||||
break;
|
||||
lightsamp = l->lightmaps[mapnum];
|
||||
if (mapnum == l->numlightstyles)
|
||||
{ // init a new light map
|
||||
if (mapnum == MAXLIGHTMAPS)
|
||||
{
|
||||
printf ("WARNING: Too many light styles on a face\n");
|
||||
return;
|
||||
}
|
||||
size = (l->texsize[1]+1)*(l->texsize[0]+1);
|
||||
for (i=0 ; i<size ; i++)
|
||||
{
|
||||
lightsamp[i][0] = 0;
|
||||
lightsamp[i][1] = 0;
|
||||
lightsamp[i][2] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// check it for real
|
||||
//
|
||||
hit = false;
|
||||
c_proper++;
|
||||
|
||||
surf = l->surfpt[0];
|
||||
for (c=0 ; c<l->numsurfpt ; c++, surf+=3)
|
||||
{
|
||||
dist = CastRay(light->origin, surf)*scaledist;
|
||||
if (dist < 0)
|
||||
continue; // light doesn't reach
|
||||
|
||||
VectorSubtract (light->origin, surf, incoming);
|
||||
VectorNormalize (incoming);
|
||||
angle = DotProduct (incoming, l->facenormal);
|
||||
if (light->targetent)
|
||||
{ // spotlight cutoff
|
||||
if (DotProduct (spotvec, incoming) > falloff)
|
||||
continue;
|
||||
}
|
||||
|
||||
angle = (1.0-scalecos) + scalecos*angle;
|
||||
for( i=0; i<3; i++ )
|
||||
{
|
||||
add = light->light[i] - dist;
|
||||
add *= angle;
|
||||
if (add < 0)
|
||||
continue;
|
||||
|
||||
lightsamp[c][i] += add;
|
||||
}
|
||||
|
||||
// check intensity
|
||||
intensity = ( lightsamp[ c ][ 0 ] + lightsamp[ c ][ 1 ] + lightsamp[ c ][ 2 ] ) / 3.0;
|
||||
if( intensity > 1 ) // ignore real tiny lights
|
||||
hit = true;
|
||||
}
|
||||
|
||||
if (mapnum == l->numlightstyles && hit)
|
||||
{
|
||||
l->lightstyles[mapnum] = light->style;
|
||||
l->numlightstyles++; // the style has some real data now
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
FixMinlight
|
||||
============
|
||||
*/
|
||||
void FixMinlight (lightinfo_t *l)
|
||||
{
|
||||
int i, j;
|
||||
float minlight;
|
||||
|
||||
minlight = minlights[l->surfnum];
|
||||
|
||||
// if minlight is set, there must be a style 0 light map
|
||||
if (!minlight)
|
||||
return;
|
||||
|
||||
for (i=0 ; i< l->numlightstyles ; i++)
|
||||
{
|
||||
if (l->lightstyles[i] == 0)
|
||||
break;
|
||||
}
|
||||
if (i == l->numlightstyles)
|
||||
{
|
||||
if (l->numlightstyles == MAXLIGHTMAPS)
|
||||
return; // oh well..
|
||||
|
||||
for (j=0 ; j<l->numsurfpt ; j++)
|
||||
{
|
||||
l->lightmaps[i][j][0] = minlight;
|
||||
l->lightmaps[i][j][1] = minlight;
|
||||
l->lightmaps[i][j][2] = minlight;
|
||||
}
|
||||
|
||||
l->lightstyles[i] = 0;
|
||||
l->numlightstyles++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=0 ; j<l->numsurfpt ; j++)
|
||||
{
|
||||
float intensity = ( l->lightmaps[i][j][0] + l->lightmaps[i][j][1] + l->lightmaps[i][j][2] ) / 3.0;
|
||||
|
||||
if ( intensity < minlight )
|
||||
{
|
||||
l->lightmaps[i][j][0] = minlight;
|
||||
l->lightmaps[i][j][1] = minlight;
|
||||
l->lightmaps[i][j][2] = minlight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
LightFace
|
||||
============
|
||||
*/
|
||||
void LightFace (int surfnum)
|
||||
{
|
||||
dface_t *f;
|
||||
lightinfo_t l;
|
||||
int s, t;
|
||||
int i,j,c;
|
||||
vec3_t total;
|
||||
int size;
|
||||
int lightmapwidth, lightmapsize;
|
||||
byte *out;
|
||||
vec3_t *light;
|
||||
int w, h;
|
||||
int clamp = 192;
|
||||
float clampfactor = 0.75;
|
||||
|
||||
if ( !clamp192 )
|
||||
{
|
||||
clamp = 255;
|
||||
clampfactor = 1.0;
|
||||
}
|
||||
|
||||
f = dfaces + surfnum;
|
||||
|
||||
//
|
||||
// some surfaces don't need lightmaps
|
||||
//
|
||||
f->lightofs = -1;
|
||||
for (j=0 ; j<MAXLIGHTMAPS ; j++)
|
||||
f->styles[j] = 255;
|
||||
|
||||
if ( texinfo[f->texinfo].flags & TEX_SPECIAL)
|
||||
{ // non-lit texture
|
||||
return;
|
||||
}
|
||||
|
||||
memset (&l, 0, sizeof(l));
|
||||
l.surfnum = surfnum;
|
||||
l.face = f;
|
||||
|
||||
//
|
||||
// rotate plane
|
||||
//
|
||||
VectorCopy (dplanes[f->planenum].normal, l.facenormal);
|
||||
l.facedist = dplanes[f->planenum].dist;
|
||||
if (f->side)
|
||||
{
|
||||
VectorSubtract (vec3_origin, l.facenormal, l.facenormal);
|
||||
l.facedist = -l.facedist;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CalcFaceVectors (&l);
|
||||
CalcFaceExtents (&l);
|
||||
CalcPoints (&l);
|
||||
|
||||
lightmapwidth = l.texsize[0]+1;
|
||||
|
||||
size = lightmapwidth*(l.texsize[1]+1);
|
||||
if (size > SINGLEMAP)
|
||||
Error ("Bad lightmap size");
|
||||
|
||||
for (i=0 ; i<MAXLIGHTMAPS ; i++)
|
||||
l.lightstyles[i] = 255;
|
||||
|
||||
//
|
||||
// cast all lights
|
||||
//
|
||||
l.numlightstyles = 0;
|
||||
for (i=0 ; i<numlightentities ; i++)
|
||||
SingleLightFace (&lightentities[i], &l);
|
||||
|
||||
FixMinlight (&l);
|
||||
|
||||
if (!l.numlightstyles)
|
||||
{ // no light hitting it
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// save out the values
|
||||
//
|
||||
for (i=0 ; i <MAXLIGHTMAPS ; i++)
|
||||
f->styles[i] = l.lightstyles[i];
|
||||
|
||||
if( hicolor )
|
||||
lightmapsize = size*l.numlightstyles*3;
|
||||
else
|
||||
lightmapsize = size * l.numlightstyles;
|
||||
|
||||
out = GetFileSpace (lightmapsize);
|
||||
f->lightofs = out - filebase;
|
||||
|
||||
// extra filtering
|
||||
h = (l.texsize[1]+1)*2;
|
||||
w = (l.texsize[0]+1)*2;
|
||||
|
||||
for (i=0 ; i< l.numlightstyles ; i++)
|
||||
{
|
||||
if (l.lightstyles[i] == 0xff)
|
||||
Error ("Wrote empty lightmap");
|
||||
light = l.lightmaps[i];
|
||||
c = 0;
|
||||
for (t=0 ; t<=l.texsize[1] ; t++)
|
||||
{
|
||||
for (s=0 ; s<=l.texsize[0] ; s++, c++)
|
||||
{
|
||||
if (extrasamples)
|
||||
{
|
||||
#ifdef OLD_CODE
|
||||
// filtered sample
|
||||
VectorCopy( light[t*2*w+s*2], total );
|
||||
VectorAdd( total, light[t*2*w+s*2+1], total );
|
||||
VectorAdd( total, light[(t*2+1)*w+s*2], total );
|
||||
VectorAdd( total, light[(t*2+1)*w+s*2+1], total );
|
||||
VectorScale( total, 0.25, total );
|
||||
#else
|
||||
int u, v;
|
||||
float weight[3][3] =
|
||||
{
|
||||
{ 5, 9, 5 },
|
||||
{ 9, 16, 9 },
|
||||
{ 5, 9, 5 },
|
||||
};
|
||||
float divisor = 0.0;
|
||||
VectorFill(total,0);
|
||||
for ( u = 0; u < 3; u++ )
|
||||
{
|
||||
for ( v = 0; v < 3; v++ )
|
||||
{
|
||||
if ( s+u-2>=0 && t+v-1>=0 && s+u-1 <= w && t+v-1 <= h)
|
||||
{
|
||||
vec3_t sample;
|
||||
VectorScale( light[((t*2)+(v-1))*w + ((s*2)+(u-1))], weight[u][v], sample );
|
||||
divisor += weight[u][v];
|
||||
VectorAdd( total, sample, total );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if ( divisor > 1.0 )
|
||||
VectorScale( total, 1/divisor, total );
|
||||
total[0] = max(total[0],0.0);
|
||||
total[1] = max(total[1],0.0);
|
||||
total[2] = max(total[2],0.0);
|
||||
}
|
||||
else
|
||||
VectorCopy( light[ c ], total );
|
||||
|
||||
// Scale
|
||||
VectorScale( total, rangescale, total );
|
||||
|
||||
// Clamp
|
||||
if( hicolor )
|
||||
{
|
||||
for( j=0; j<3; j++ )
|
||||
{
|
||||
total[ j ] *= clampfactor;
|
||||
|
||||
if( total[j] > clamp)
|
||||
total[j] = clamp;
|
||||
else if (total[j] < 0)
|
||||
Error ("light < 0");
|
||||
|
||||
*out++ = (byte) total[j];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int intensity = total[ 0 ] + total[ 1 ] + total[ 2 ];
|
||||
if( intensity > 255 )
|
||||
intensity = 255;
|
||||
else if( intensity < 0 )
|
||||
Error( "light < 0" );
|
||||
|
||||
*out++ = (byte) intensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
132
hlsdk/utils/light/msvc6/light.dsp
Normal file
132
hlsdk/utils/light/msvc6/light.dsp
Normal file
@ -0,0 +1,132 @@
|
||||
# Microsoft Developer Studio Project File - Name="light" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=light - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "light.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "light.mak" CFG="light - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "light - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "light - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "light - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir ".\Release"
|
||||
# PROP BASE Intermediate_Dir ".\Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir ".\Release"
|
||||
# PROP Intermediate_Dir ".\Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
|
||||
# ADD CPP /nologo /GX /O2 /I "..\..\common" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "light - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir ".\Debug"
|
||||
# PROP BASE Intermediate_Dir ".\Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir ".\Debug"
|
||||
# PROP Intermediate_Dir ".\Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /YX /c
|
||||
# ADD CPP /nologo /Gm /GX /ZI /Od /I "..\..\common" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /FR /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "light - Win32 Release"
|
||||
# Name "light - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\common\bspfile.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\common\cmdlib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\light.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\ltface.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\common\mathlib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\common\scriplib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\common\threads.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\trace.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\light.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
312
hlsdk/utils/light/msvc7/light.vcproj
Normal file
312
hlsdk/utils/light/msvc7/light.vcproj
Normal file
@ -0,0 +1,312 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="light"
|
||||
ProjectGUID="{44EB71E1-F1E7-4A77-92AB-22E054865619}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\common"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="4"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderFile=".\Release/light.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile=".\Release/light.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
ProgramDatabaseFile=".\Release/light.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/light.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\common"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
RuntimeLibrary="5"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderFile=".\Debug/light.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
BrowseInformation="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile=".\Debug/light.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\Debug/light.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Debug/light.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90">
|
||||
<File
|
||||
RelativePath="..\..\common\bspfile.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\cmdlib.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\light.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ltface.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\mathlib.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\scriplib.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\threads.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\trace.c">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;fi;fd">
|
||||
<File
|
||||
RelativePath="..\light.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
418
hlsdk/utils/light/msvc8/light.vcproj
Normal file
418
hlsdk/utils/light/msvc8/light.vcproj
Normal file
@ -0,0 +1,418 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="light"
|
||||
ProjectGUID="{44EB71E1-F1E7-4A77-92AB-22E054865619}"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/light.tlb"
|
||||
HeaderFileName=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="..\..\common"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Release/light.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
SuppressStartupBanner="true"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile=".\Release/light.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
ProgramDatabaseFile=".\Release/light.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Debug/light.tlb"
|
||||
HeaderFileName=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\common"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
PrecompiledHeaderFile=".\Debug/light.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
BrowseInformation="1"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile=".\Debug/light.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile=".\Debug/light.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\common\bspfile.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\cmdlib.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\light.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ltface.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\mathlib.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\scriplib.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\common\threads.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\trace.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BrowseInformation="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;fi;fd"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\light.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
206
hlsdk/utils/light/trace.c
Normal file
206
hlsdk/utils/light/trace.c
Normal file
@ -0,0 +1,206 @@
|
||||
//========= Copyright <20> 1996-2002, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
// trace.c
|
||||
|
||||
#include "light.h"
|
||||
|
||||
typedef struct tnode_s
|
||||
{
|
||||
int type;
|
||||
vec3_t normal;
|
||||
float dist;
|
||||
int children[2];
|
||||
int pad;
|
||||
} tnode_t;
|
||||
|
||||
tnode_t *tnodes, *tnode_p;
|
||||
|
||||
/*
|
||||
==============
|
||||
MakeTnode
|
||||
|
||||
Converts the disk node structure into the efficient tracing structure
|
||||
==============
|
||||
*/
|
||||
void MakeTnode (int nodenum)
|
||||
{
|
||||
tnode_t *t;
|
||||
dplane_t *plane;
|
||||
int i;
|
||||
dnode_t *node;
|
||||
|
||||
t = tnode_p++;
|
||||
|
||||
node = dnodes + nodenum;
|
||||
plane = dplanes + node->planenum;
|
||||
|
||||
t->type = plane->type;
|
||||
VectorCopy (plane->normal, t->normal);
|
||||
t->dist = plane->dist;
|
||||
|
||||
for (i=0 ; i<2 ; i++)
|
||||
{
|
||||
if (node->children[i] < 0)
|
||||
t->children[i] = dleafs[-node->children[i] - 1].contents;
|
||||
else
|
||||
{
|
||||
t->children[i] = tnode_p - tnodes;
|
||||
MakeTnode (node->children[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
MakeTnodes
|
||||
|
||||
Loads the node structure out of a .bsp file to be used for light occlusion
|
||||
=============
|
||||
*/
|
||||
void MakeTnodes (dmodel_t *bm)
|
||||
{
|
||||
if (!numnodes)
|
||||
Error ("Map has no nodes\n");
|
||||
tnode_p = tnodes = malloc(numnodes * sizeof(tnode_t));
|
||||
|
||||
MakeTnode (0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
LINE TRACING
|
||||
|
||||
The major lighting operation is a point to point visibility test, performed
|
||||
by recursive subdivision of the line by the BSP tree.
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3_t backpt;
|
||||
int side;
|
||||
int node;
|
||||
} tracestack_t;
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
TestLine
|
||||
==============
|
||||
*/
|
||||
qboolean TestLine (vec3_t start, vec3_t stop)
|
||||
{
|
||||
int node;
|
||||
float front, back;
|
||||
tracestack_t *tstack_p;
|
||||
int side;
|
||||
float frontx,fronty, frontz, backx, backy, backz;
|
||||
tracestack_t tracestack[64];
|
||||
tnode_t *tnode;
|
||||
|
||||
frontx = start[0];
|
||||
fronty = start[1];
|
||||
frontz = start[2];
|
||||
backx = stop[0];
|
||||
backy = stop[1];
|
||||
backz = stop[2];
|
||||
|
||||
tstack_p = tracestack;
|
||||
node = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (node < 0 && node != CONTENTS_SOLID)
|
||||
{
|
||||
// pop up the stack for a back side
|
||||
tstack_p--;
|
||||
if (tstack_p < tracestack)
|
||||
return true;
|
||||
node = tstack_p->node;
|
||||
|
||||
// set the hit point for this plane
|
||||
|
||||
frontx = backx;
|
||||
fronty = backy;
|
||||
frontz = backz;
|
||||
|
||||
// go down the back side
|
||||
|
||||
backx = tstack_p->backpt[0];
|
||||
backy = tstack_p->backpt[1];
|
||||
backz = tstack_p->backpt[2];
|
||||
|
||||
node = tnodes[tstack_p->node].children[!tstack_p->side];
|
||||
}
|
||||
|
||||
if (node == CONTENTS_SOLID)
|
||||
return false; // DONE!
|
||||
|
||||
tnode = &tnodes[node];
|
||||
|
||||
switch (tnode->type)
|
||||
{
|
||||
case PLANE_X:
|
||||
front = frontx - tnode->dist;
|
||||
back = backx - tnode->dist;
|
||||
break;
|
||||
case PLANE_Y:
|
||||
front = fronty - tnode->dist;
|
||||
back = backy - tnode->dist;
|
||||
break;
|
||||
case PLANE_Z:
|
||||
front = frontz - tnode->dist;
|
||||
back = backz - tnode->dist;
|
||||
break;
|
||||
default:
|
||||
front = (frontx*tnode->normal[0] + fronty*tnode->normal[1] + frontz*tnode->normal[2]) - tnode->dist;
|
||||
back = (backx*tnode->normal[0] + backy*tnode->normal[1] + backz*tnode->normal[2]) - tnode->dist;
|
||||
break;
|
||||
}
|
||||
|
||||
if (front > -ON_EPSILON && back > -ON_EPSILON)
|
||||
// if (front > 0 && back > 0)
|
||||
{
|
||||
node = tnode->children[0];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (front < ON_EPSILON && back < ON_EPSILON)
|
||||
// if (front <= 0 && back <= 0)
|
||||
{
|
||||
node = tnode->children[1];
|
||||
continue;
|
||||
}
|
||||
|
||||
side = front < 0;
|
||||
|
||||
front = front / (front-back);
|
||||
|
||||
tstack_p->node = node;
|
||||
tstack_p->side = side;
|
||||
tstack_p->backpt[0] = backx;
|
||||
tstack_p->backpt[1] = backy;
|
||||
tstack_p->backpt[2] = backz;
|
||||
|
||||
tstack_p++;
|
||||
|
||||
backx = frontx + front*(backx-frontx);
|
||||
backy = fronty + front*(backy-fronty);
|
||||
backz = frontz + front*(backz-frontz);
|
||||
|
||||
node = tnode->children[side];
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user