2 Copyright (C) 1999-2007 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 ){
37 for ( i = 0 ; i < nummiptex ; i++ )
38 if ( !strcmp( name, textureref[i].name ) ) {
41 if ( nummiptex == MAX_MAP_TEXTURES ) {
42 Error( "MAX_MAP_TEXTURES" );
44 strcpy( textureref[i].name, name );
46 // load the miptex to get the flags and values
47 if ( !strcmp( game, "heretic2" ) ) {
48 sprintf( path, "%stextures/%s.m32", gamedir, name );
49 if ( TryLoadFile( path, (void **)&mt_m32 ) != -1 ) {
50 textureref[i].value = LittleLong( mt_m32->value );
51 textureref[i].flags = LittleLong( mt_m32->flags );
52 textureref[i].contents = LittleLong( mt_m32->contents );
53 strcpy( textureref[i].animname, mt_m32->animname );
57 sprintf( path, "%stextures/%s.m8", gamedir, name );
60 if ( TryLoadFile( path, (void **)&mt_m8 ) != -1 ) {
61 textureref[i].value = LittleLong( mt_m8->value );
62 textureref[i].flags = LittleLong( mt_m8->flags );
63 textureref[i].contents = LittleLong( mt_m8->contents );
64 strcpy( textureref[i].animname, mt_m8->animname );
70 sprintf( path, "%stextures/%s.wal", gamedir, name );
71 if ( TryLoadFile( path, (void **)&mt ) != -1 ) {
72 textureref[i].value = LittleLong( mt->value );
73 textureref[i].flags = LittleLong( mt->flags );
74 textureref[i].contents = LittleLong( mt->contents );
75 strcpy( textureref[i].animname, mt->animname );
82 if ( textureref[i].animname[0] ) {
83 FindMiptex( textureref[i].animname );
97 {0,0,1}, {1,0,0}, {0,-1,0}, // floor
98 {0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling
99 {1,0,0}, {0,1,0}, {0,0,-1}, // west wall
100 {-1,0,0}, {0,1,0}, {0,0,-1}, // east wall
101 {0,1,0}, {1,0,0}, {0,0,-1}, // south wall
102 {0,-1,0}, {1,0,0}, {0,0,-1} // north wall
105 void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ){
113 for ( i = 0 ; i < 6 ; i++ )
115 dot = DotProduct( pln->normal, baseaxis[i * 3] );
122 VectorCopy( baseaxis[bestaxis * 3 + 1], xv );
123 VectorCopy( baseaxis[bestaxis * 3 + 2], yv );
129 int TexinfoForBrushTexture( plane_t *plane, brush_texture_t *bt, vec3_t origin ){
132 vec_t ang, sinv, cosv;
137 brush_texture_t anim;
140 if ( !bt->name[0] ) {
144 memset( &tx, 0, sizeof( tx ) );
145 strcpy( tx.texture, bt->name );
147 TextureAxisFromPlane( plane, vecs[0], vecs[1] );
149 shift[0] = DotProduct( origin, vecs[0] );
150 shift[1] = DotProduct( origin, vecs[1] );
152 if ( !bt->scale[0] ) {
155 if ( !bt->scale[1] ) {
161 if ( bt->rotate == 0 ) {
164 else if ( bt->rotate == 90 ) {
167 else if ( bt->rotate == 180 ) {
168 sinv = 0 ; cosv = -1;
170 else if ( bt->rotate == 270 ) {
171 sinv = -1 ; cosv = 0;
175 ang = bt->rotate / 180 * Q_PI;
183 else if ( vecs[0][1] ) {
193 else if ( vecs[1][1] ) {
200 for ( i = 0 ; i < 2 ; i++ )
202 ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
203 nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
208 for ( i = 0 ; i < 2 ; i++ )
209 for ( j = 0 ; j < 3 ; j++ )
210 tx.vecs[i][j] = vecs[i][j] / bt->scale[i];
212 tx.vecs[0][3] = bt->shift[0] + shift[0];
213 tx.vecs[1][3] = bt->shift[1] + shift[1];
214 tx.flags = bt->flags;
215 tx.value = bt->value;
221 for ( i = 0 ; i < numtexinfo ; i++, tc++ )
223 if ( tc->flags != tx.flags ) {
226 if ( tc->value != tx.value ) {
229 for ( j = 0 ; j < 2 ; j++ )
231 if ( strcmp( tc->texture, tx.texture ) ) {
234 for ( k = 0 ; k < 4 ; k++ )
236 if ( tc->vecs[j][k] != tx.vecs[j][k] ) {
247 // load the next animation
248 mt = FindMiptex( bt->name );
249 if ( textureref[mt].animname[0] ) {
251 strcpy( anim.name, textureref[mt].animname );
252 tc->nexttexinfo = TexinfoForBrushTexture( plane, &anim, origin );
255 tc->nexttexinfo = -1;