2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 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 GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 textureref_t textureref[MAX_MAP_TEXTURES];
27 //==========================================================================
30 int FindMiptex (char *name)
38 for (i=0 ; i<nummiptex ; i++)
39 if (!strcmp (name, textureref[i].name))
43 if (nummiptex == MAX_MAP_TEXTURES)
44 Error ("MAX_MAP_TEXTURES");
45 strcpy (textureref[i].name, name);
47 // load the miptex to get the flags and values
48 if ( !strcmp( game, "heretic2" ) )
50 sprintf (path, "%stextures/%s.m32", gamedir, name);
51 if (TryLoadFile (path, (void **)&mt_m32) != -1)
53 textureref[i].value = LittleLong (mt_m32->value);
54 textureref[i].flags = LittleLong (mt_m32->flags);
55 textureref[i].contents = LittleLong (mt_m32->contents);
56 strcpy (textureref[i].animname, mt_m32->animname);
60 sprintf (path, "%stextures/%s.m8", gamedir, name);
62 if (TryLoadFile (path, (void **)&mt_m8) != -1)
64 textureref[i].value = LittleLong (mt_m8->value);
65 textureref[i].flags = LittleLong (mt_m8->flags);
66 textureref[i].contents = LittleLong (mt_m8->contents);
67 strcpy (textureref[i].animname, mt_m8->animname);
73 sprintf (path, "%stextures/%s.wal", gamedir, name);
74 if (TryLoadFile (path, (void **)&mt) != -1)
76 textureref[i].value = LittleLong (mt->value);
77 textureref[i].flags = LittleLong (mt->flags);
78 textureref[i].contents = LittleLong (mt->contents);
79 strcpy (textureref[i].animname, mt->animname);
86 if (textureref[i].animname[0])
87 FindMiptex (textureref[i].animname);
100 {0,0,1}, {1,0,0}, {0,-1,0}, // floor
101 {0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling
102 {1,0,0}, {0,1,0}, {0,0,-1}, // west wall
103 {-1,0,0}, {0,1,0}, {0,0,-1}, // east wall
104 {0,1,0}, {1,0,0}, {0,0,-1}, // south wall
105 {0,-1,0}, {1,0,0}, {0,0,-1} // north wall
108 void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv)
117 for (i=0 ; i<6 ; i++)
119 dot = DotProduct (pln->normal, baseaxis[i*3]);
127 VectorCopy (baseaxis[bestaxis*3+1], xv);
128 VectorCopy (baseaxis[bestaxis*3+2], yv);
134 int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, vec3_t origin)
138 vec_t ang, sinv, cosv;
143 brush_texture_t anim;
149 memset (&tx, 0, sizeof(tx));
150 strcpy (tx.texture, bt->name);
152 TextureAxisFromPlane(plane, vecs[0], vecs[1]);
154 shift[0] = DotProduct (origin, vecs[0]);
155 shift[1] = DotProduct (origin, vecs[1]);
165 { sinv = 0 ; cosv = 1; }
166 else if (bt->rotate == 90)
167 { sinv = 1 ; cosv = 0; }
168 else if (bt->rotate == 180)
169 { sinv = 0 ; cosv = -1; }
170 else if (bt->rotate == 270)
171 { sinv = -1 ; cosv = 0; }
174 ang = bt->rotate / 180 * Q_PI;
193 for (i=0 ; i<2 ; i++)
195 ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
196 nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
201 for (i=0 ; i<2 ; i++)
202 for (j=0 ; j<3 ; j++)
203 tx.vecs[i][j] = vecs[i][j] / bt->scale[i];
205 tx.vecs[0][3] = bt->shift[0] + shift[0];
206 tx.vecs[1][3] = bt->shift[1] + shift[1];
207 tx.flags = bt->flags;
208 tx.value = bt->value;
214 for (i=0 ; i<numtexinfo ; i++, tc++)
216 if (tc->flags != tx.flags)
218 if (tc->value != tx.value)
220 for (j=0 ; j<2 ; j++)
222 if (strcmp (tc->texture, tx.texture))
224 for (k=0 ; k<4 ; k++)
226 if (tc->vecs[j][k] != tx.vecs[j][k])
236 // load the next animation
237 mt = FindMiptex (bt->name);
238 if (textureref[mt].animname[0])
241 strcpy (anim.name, textureref[mt].animname);
242 tc->nexttexinfo = TexinfoForBrushTexture (plane, &anim, origin);
245 tc->nexttexinfo = -1;