Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

textures.c File Reference

#include "qbsp.h"
#include "l_bsp_q2.h"

Include dependency graph for textures.c:

Include dependency graph

Go to the source code of this file.

Functions

int FindMiptex (char *name)
int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin)
void TextureAxisFromPlane (plane_t *pln, vec3_t xv, vec3_t yv)

Variables

vec3_t baseaxis [18]
int nummiptex
textureref_t textureref [MAX_MAP_TEXTURES]


Function Documentation

int FindMiptex char *  name  ) 
 

Definition at line 35 of file textures.c.

References textureref_t::animname, textureref_t::contents, Error(), textureref_t::flags, FreeMemory(), gamedir, i, LittleLong(), miptex_t, name, nummiptex, sprintf(), strcmp(), strcpy(), textureref, TryLoadFile(), and textureref_t::value.

Referenced by Q2_ParseBrush(), and TexinfoForBrushTexture().

00036 {
00037     int i;
00038     char path[1024];
00039     miptex_t    *mt;
00040 
00041     for (i = 0; i < nummiptex; i++)
00042     {
00043         if (!strcmp (name, textureref[i].name))
00044         {
00045             return i;
00046         } //end if
00047     } //end for
00048     if (nummiptex == MAX_MAP_TEXTURES)
00049         Error ("MAX_MAP_TEXTURES");
00050     strcpy (textureref[i].name, name);
00051 
00052     // load the miptex to get the flags and values
00053     sprintf (path, "%stextures/%s.wal", gamedir, name);
00054     if (TryLoadFile (path, (void **)&mt) != -1)
00055     {
00056         textureref[i].value = LittleLong (mt->value);
00057         textureref[i].flags = LittleLong (mt->flags);
00058         textureref[i].contents = LittleLong (mt->contents);
00059         strcpy (textureref[i].animname, mt->animname);
00060         FreeMemory(mt);
00061     } //end if
00062     nummiptex++;
00063 
00064     if (textureref[i].animname[0])
00065         FindMiptex (textureref[i].animname);
00066 
00067     return i;
00068 } //end of the function FindMipTex

Here is the call graph for this function:

int TexinfoForBrushTexture plane_t plane,
brush_texture_t bt,
vec3_t  origin
 

Definition at line 113 of file textures.c.

References textureref_t::animname, cos(), DotProduct, FindMiptex(), texinfo_s::flags, brush_texture_t::flags, i, j, k, memset(), brush_texture_t::name, texinfo_s::nexttexinfo, numtexinfo, brush_texture_t::rotate, brush_texture_t::scale, brush_texture_t::shift, shift, sin(), strcmp(), strcpy(), sv, texinfo_t, texinfo_s::texture, TextureAxisFromPlane(), textureref, tv(), texinfo_s::value, brush_texture_t::value, vec3_t, vec_t, texinfo_s::vecs, and vecs.

Referenced by Q2_ParseBrush(), and Q2_ParseMapEntity().

00114 {
00115     vec3_t  vecs[2];
00116     int     sv, tv;
00117     vec_t   ang, sinv, cosv;
00118     vec_t   ns, nt;
00119     texinfo_t   tx, *tc;
00120     int     i, j, k;
00121     float   shift[2];
00122     brush_texture_t     anim;
00123     int             mt;
00124 
00125     if (!bt->name[0])
00126         return 0;
00127 
00128     memset (&tx, 0, sizeof(tx));
00129     strcpy (tx.texture, bt->name);
00130 
00131     TextureAxisFromPlane(plane, vecs[0], vecs[1]);
00132 
00133     shift[0] = DotProduct (origin, vecs[0]);
00134     shift[1] = DotProduct (origin, vecs[1]);
00135 
00136     if (!bt->scale[0])
00137         bt->scale[0] = 1;
00138     if (!bt->scale[1])
00139         bt->scale[1] = 1;
00140 
00141 
00142 // rotate axis
00143     if (bt->rotate == 0)
00144         { sinv = 0 ; cosv = 1; }
00145     else if (bt->rotate == 90)
00146         { sinv = 1 ; cosv = 0; }
00147     else if (bt->rotate == 180)
00148         { sinv = 0 ; cosv = -1; }
00149     else if (bt->rotate == 270)
00150         { sinv = -1 ; cosv = 0; }
00151     else
00152     {   
00153         ang = bt->rotate / 180 * Q_PI;
00154         sinv = sin(ang);
00155         cosv = cos(ang);
00156     }
00157 
00158     if (vecs[0][0])
00159         sv = 0;
00160     else if (vecs[0][1])
00161         sv = 1;
00162     else
00163         sv = 2;
00164                 
00165     if (vecs[1][0])
00166         tv = 0;
00167     else if (vecs[1][1])
00168         tv = 1;
00169     else
00170         tv = 2;
00171                     
00172     for (i=0 ; i<2 ; i++)
00173     {
00174         ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
00175         nt = sinv * vecs[i][sv] +  cosv * vecs[i][tv];
00176         vecs[i][sv] = ns;
00177         vecs[i][tv] = nt;
00178     }
00179 
00180     for (i=0 ; i<2 ; i++)
00181         for (j=0 ; j<3 ; j++)
00182             tx.vecs[i][j] = vecs[i][j] / bt->scale[i];
00183 
00184     tx.vecs[0][3] = bt->shift[0] + shift[0];
00185     tx.vecs[1][3] = bt->shift[1] + shift[1];
00186     tx.flags = bt->flags;
00187     tx.value = bt->value;
00188 
00189     //
00190     // find the texinfo
00191     //
00192     tc = texinfo;
00193     for (i=0 ; i<numtexinfo ; i++, tc++)
00194     {
00195         if (tc->flags != tx.flags)
00196             continue;
00197         if (tc->value != tx.value)
00198             continue;
00199         for (j=0 ; j<2 ; j++)
00200         {
00201             if (strcmp (tc->texture, tx.texture))
00202                 goto skip;
00203             for (k=0 ; k<4 ; k++)
00204             {
00205                 if (tc->vecs[j][k] != tx.vecs[j][k])
00206                     goto skip;
00207             }
00208         }
00209         return i;
00210 skip:;
00211     }
00212     *tc = tx;
00213     numtexinfo++;
00214 
00215     // load the next animation
00216     mt = FindMiptex (bt->name);
00217     if (textureref[mt].animname[0])
00218     {
00219         anim = *bt;
00220         strcpy (anim.name, textureref[mt].animname);
00221         tc->nexttexinfo = TexinfoForBrushTexture (plane, &anim, origin);
00222     }
00223     else
00224         tc->nexttexinfo = -1;
00225 
00226 
00227     return i;
00228 } //end of the function TexinfoForBrushTexture

Here is the call graph for this function:

void TextureAxisFromPlane plane_t pln,
vec3_t  xv,
vec3_t  yv
 

Definition at line 85 of file textures.c.

00086 {
00087     int     bestaxis;
00088     vec_t   dot,best;
00089     int     i;
00090     
00091     best = 0;
00092     bestaxis = 0;
00093     
00094     for (i=0 ; i<6 ; i++)
00095     {
00096         dot = DotProduct (pln->normal, baseaxis[i*3]);
00097         if (dot > best)
00098         {
00099             best = dot;
00100             bestaxis = i;
00101         }
00102     }
00103     
00104     VectorCopy (baseaxis[bestaxis*3+1], xv);
00105     VectorCopy (baseaxis[bestaxis*3+2], yv);
00106 } //end of the function TextureAxisFromPlane


Variable Documentation

vec3_t baseaxis[18]
 

Initial value:

{
{0,0,1}, {1,0,0}, {0,-1,0},     
{0,0,-1}, {1,0,0}, {0,-1,0},        
{1,0,0}, {0,1,0}, {0,0,-1},     
{-1,0,0}, {0,1,0}, {0,0,-1},        
{0,1,0}, {1,0,0}, {0,0,-1},     
{0,-1,0}, {1,0,0}, {0,0,-1}     
}

Definition at line 75 of file textures.c.

Referenced by TextureAxisFromPlane().

int nummiptex
 

Definition at line 26 of file textures.c.

Referenced by FindMiptex(), and Q1_PrintBSPFileSizes().

textureref_t textureref[MAX_MAP_TEXTURES]
 

Definition at line 27 of file textures.c.

Referenced by FindMiptex(), Q2_ParseBrush(), and TexinfoForBrushTexture().


Generated on Thu Aug 25 13:09:32 2005 for Quake III Arena by  doxygen 1.3.9.1