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