2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
26 textureref_t textureref[MAX_MAP_TEXTURES];
28 //==========================================================================
31 int FindMiptex (char *name)
37 for (i=0 ; i<nummiptex ; i++)
38 if (!strcmp (name, textureref[i].name))
42 if (nummiptex == MAX_MAP_TEXTURES)
43 Error ("MAX_MAP_TEXTURES");
44 strcpy (textureref[i].name, name);
46 // load the miptex to get the flags and values
47 sprintf (path, "%stextures/%s.wal", gamedir, name);
48 if (TryLoadFile (path, (void **)&mt) != -1)
50 textureref[i].value = LittleLong (mt->value);
51 textureref[i].flags = LittleLong (mt->flags);
52 textureref[i].contents = LittleLong (mt->contents);
53 strcpy (textureref[i].animname, mt->animname);
58 if (textureref[i].animname[0])
59 FindMiptex (textureref[i].animname);
72 {0,0,1}, {1,0,0}, {0,-1,0}, // floor
73 {0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling
74 {1,0,0}, {0,1,0}, {0,0,-1}, // west wall
75 {-1,0,0}, {0,1,0}, {0,0,-1}, // east wall
76 {0,1,0}, {1,0,0}, {0,0,-1}, // south wall
77 {0,-1,0}, {1,0,0}, {0,0,-1} // north wall
80 void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv)
91 dot = DotProduct (pln->normal, baseaxis[i*3]);
99 VectorCopy (baseaxis[bestaxis*3+1], xv);
100 VectorCopy (baseaxis[bestaxis*3+2], yv);
106 int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin)
110 vec_t ang, sinv, cosv;
115 brush_texture_t anim;
121 memset (&tx, 0, sizeof(tx));
122 strcpy (tx.texture, bt->name);
124 TextureAxisFromPlane(plane, vecs[0], vecs[1]);
126 shift[0] = DotProduct (origin, vecs[0]);
127 shift[1] = DotProduct (origin, vecs[1]);
137 { sinv = 0 ; cosv = 1; }
138 else if (bt->rotate == 90)
139 { sinv = 1 ; cosv = 0; }
140 else if (bt->rotate == 180)
141 { sinv = 0 ; cosv = -1; }
142 else if (bt->rotate == 270)
143 { sinv = -1 ; cosv = 0; }
146 ang = bt->rotate / 180 * Q_PI;
165 for (i=0 ; i<2 ; i++)
167 ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
168 nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
173 for (i=0 ; i<2 ; i++)
174 for (j=0 ; j<3 ; j++)
175 tx.vecs[i][j] = vecs[i][j] / bt->scale[i];
177 tx.vecs[0][3] = bt->shift[0] + shift[0];
178 tx.vecs[1][3] = bt->shift[1] + shift[1];
179 tx.flags = bt->flags;
180 tx.value = bt->value;
186 for (i=0 ; i<numtexinfo ; i++, tc++)
188 if (tc->flags != tx.flags)
190 if (tc->value != tx.value)
192 for (j=0 ; j<2 ; j++)
194 if (strcmp (tc->texture, tx.texture))
196 for (k=0 ; k<4 ; k++)
198 if (tc->vecs[j][k] != tx.vecs[j][k])
208 // load the next animation
209 mt = FindMiptex (bt->name);
210 if (textureref[mt].animname[0])
213 strcpy (anim.name, textureref[mt].animname);
214 tc->nexttexinfo = TexinfoForBrushTexture (plane, &anim, origin);
217 tc->nexttexinfo = -1;