level/light_face.c
/*	Fills in texorg, worldtotex. and textoworld
*/
Fills in texorg, worldtotex. and textoworld
Fills in texorg worldtotex . and textoworld
static void CalcFaceVectors( lightinfo_t *l, const vec3_t faceorg )
{
	int					i;
	BSPTextureInfo_t	*tex = &texinfo[l->face->iTexInfo];
	vec3_t				texnormal;
	vec_t				dist, len, distscale;
	VectorCopy( tex->v[0], l->worldtotex[0] );
	VectorCopy( tex->v[1], l->worldtotex[1] );
	CrossProduct( tex->v[1], tex->v[0], texnormal );
	VectorNormalize( texnormal );
	distscale = DotProduct( texnormal, l->facenormal );
	if( !distscale )
	{
		printf( "Texture axis perpendicular to face at location %f %f %f\n", l->facemid[0], l->facemid[1], l->facemid[2] );
		distscale = 1;
	}
	if( distscale < 0 )
	{
		distscale = -distscale;
		VectorNegate( texnormal, texnormal );
	}
	distscale = 1.0 / distscale;
	for( i = 0; i < 2; i++ )
	{
		len = 1.0 / VectorLength( l->worldtotex[i] );
		len *= len;
		dist = DotProduct( l->worldtotex[i], l->facenormal);
		dist *= distscale;
		VectorMA( l->worldtotex[i], -dist, texnormal, l->textoworld[i] );
		VectorScale( l->textoworld[i], len, l->textoworld[i] );
	}
	for( i = 0; i < 3; i++ )
		l->texorg[i] = -tex->v[0][3] * l->textoworld[0][i] - tex->v[1][3] * l->textoworld[1][i];
	VectorAdd( l->texorg, faceorg, l->texorg );
	dist = DotProduct( l->texorg, l->facenormal ) - l->facedist - 1;
	dist *= distscale;
	VectorMA( l->texorg, -dist, texnormal, l->texorg );
}
static void CalcFaceVectors ( lightinfo_t * l , const vec3_t faceorg ) { int i ; BSPTextureInfo_t * tex = & texinfo [ l -> face -> iTexInfo ] ; vec3_t texnormal ; vec_t dist , len , distscale ; VectorCopy ( tex -> v [ 0 ] , l -> worldtotex [ 0 ] ) ; VectorCopy ( tex -> v [ 1 ] , l -> worldtotex [ 1 ] ) ; CrossProduct ( tex -> v [ 1 ] , tex -> v [ 0 ] , texnormal ) ; VectorNormalize ( texnormal ) ; distscale = DotProduct ( texnormal , l -> facenormal ) ; if ( ! distscale ) { printf ( " \n " , l -> facemid [ 0 ] , l -> facemid [ 1 ] , l -> facemid [ 2 ] ) ; distscale = 1 ; } if ( distscale < 0 ) { distscale = - distscale ; VectorNegate ( texnormal , texnormal ) ; } distscale = 1.0 / distscale ; for ( i = 0 ; i < 2 ; i ++ ) { len = 1.0 / VectorLength ( l -> worldtotex [ i ] ) ; len *= len ; dist = DotProduct ( l -> worldtotex [ i ] , l -> facenormal ) ; dist *= distscale ; VectorMA ( l -> worldtotex [ i ] , - dist , texnormal , l -> textoworld [ i ] ) ; VectorScale ( l -> textoworld [ i ] , len , l -> textoworld [ i ] ) ; } for ( i = 0 ; i < 3 ; i ++ ) l -> texorg [ i ] = - tex -> v [ 0 ] [ 3 ] * l -> textoworld [ 0 ] [ i ] - tex -> v [ 1 ] [ 3 ] * l -> textoworld [ 1 ] [ i ] ; VectorAdd ( l -> texorg , faceorg , l -> texorg ) ; dist = DotProduct ( l -> texorg , l -> facenormal ) - l -> facedist - 1 ; dist *= distscale ; VectorMA ( l -> texorg , - dist , texnormal , l -> texorg ) ; }
Fills in texorg, worldtotex.
Fills in texorg worldtotex .
// convert from float to vec_t // calculate a normal to the texture axis. points can be moved along this // without changing their S/T // flip it towards plane normal // distscale is the ratio of the distance along the texture normal to // the distance along the plane normal // calculate texorg on the texture plane // project back to the face plane