light: factor out WorldToTexCoord as a serparte function

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-03-09 16:36:57 +10:30
parent 63393eee8e
commit ea440c6da0
1 changed files with 30 additions and 29 deletions

View File

@ -209,6 +209,18 @@ TexCoordToWorld(vec_t s, vec_t t, const texorg_t *texorg, vec3_t world)
Solve3(&texorg->transform, rhs, world); Solve3(&texorg->transform, rhs, world);
} }
static void
WorldToTexCoord(const vec3_t world, const texinfo_t *tex, vec_t coord[2])
{
int i;
for (i = 0; i < 2; i++)
coord[i] =
world[0] * tex->vecs[i][0] +
world[1] * tex->vecs[i][1] +
world[2] * tex->vecs[i][2] + tex->vecs[i][3];
}
/* /*
* Functions to aid in calculation of polygon centroid * Functions to aid in calculation of polygon centroid
*/ */
@ -283,49 +295,38 @@ FaceCentroid(const dface_t *f, vec3_t out)
static void static void
CalcFaceExtents(const dface_t *face, const vec3_t offset, lightinfo_t *l) CalcFaceExtents(const dface_t *face, const vec3_t offset, lightinfo_t *l)
{ {
vec_t mins[2], maxs[2], val; vec_t mins[2], maxs[2], texcoord[2];
vec3_t centroid; vec3_t world, centroid;
int i, j, e; int i, j, edge, vert;
dvertex_t *v; const dvertex_t *dvertex;
texinfo_t *tex; const texinfo_t *tex;
mins[0] = mins[1] = 999999; mins[0] = mins[1] = VECT_MAX;
maxs[0] = maxs[1] = -99999; maxs[0] = maxs[1] = -VECT_MAX;
tex = &texinfo[face->texinfo]; tex = &texinfo[face->texinfo];
for (i = 0; i < face->numedges; i++) { for (i = 0; i < face->numedges; i++) {
e = dsurfedges[face->firstedge + i]; edge = dsurfedges[face->firstedge + i];
if (e >= 0) vert = (edge >= 0) ? dedges[edge].v[0] : dedges[-edge].v[1];
v = dvertexes + dedges[e].v[0]; dvertex = &dvertexes[vert];
else
v = dvertexes + dedges[-e].v[1];
VectorAdd(dvertex->point, offset, world);
WorldToTexCoord(world, tex, texcoord);
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
// This is world->tex with world offset... if (texcoord[j] < mins[j])
val = (v->point[0] + offset[0]) * tex->vecs[j][0] mins[j] = texcoord[j];
+ (v->point[1] + offset[1]) * tex->vecs[j][1] if (texcoord[j] > maxs[j])
+ (v->point[2] + offset[2]) * tex->vecs[j][2] maxs[j] = texcoord[j];
+ tex->vecs[j][3];
if (val < mins[j])
mins[j] = val;
if (val > maxs[j])
maxs[j] = val;
} }
} }
FaceCentroid(face, centroid); FaceCentroid(face, centroid);
VectorAdd(centroid, offset, world);
WorldToTexCoord(world, tex, l->exactmid);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
l->exactmid[i] =
(centroid[0] + offset[0]) * tex->vecs[i][0]
+ (centroid[1] + offset[1]) * tex->vecs[i][1]
+ (centroid[2] + offset[2]) * tex->vecs[i][2]
+ tex->vecs[i][3];
mins[i] = floor(mins[i] / 16); mins[i] = floor(mins[i] / 16);
maxs[i] = ceil(maxs[i] / 16); maxs[i] = ceil(maxs[i] / 16);
l->texmins[i] = mins[i]; l->texmins[i] = mins[i];
l->texsize[i] = maxs[i] - mins[i]; l->texsize[i] = maxs[i] - mins[i];
if (l->texsize[i] > 17) if (l->texsize[i] > 17)