]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/brush_primit.c
fix two other bugs in the same function
[xonotic/netradiant.git] / tools / quake3 / q3map2 / brush_primit.c
1 /* -------------------------------------------------------------------------------
2
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6 This file is part of GtkRadiant.
7
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
22 ----------------------------------------------------------------------------------
23
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27 ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #define BRUSH_PRIMIT_C
33
34
35
36 /* dependencies */
37 #include "q3map2.h"
38
39
40
41 /* -------------------------------------------------------------------------------
42
43 functions
44
45 ------------------------------------------------------------------------------- */
46
47 /*
48 ComputeAxisBase()
49 computes the base texture axis for brush primitive texturing
50 note: ComputeAxisBase here and in editor code must always BE THE SAME!
51 warning: special case behaviour of atan2( y, x ) <-> atan( y / x ) might not be the same everywhere when x == 0
52 rotation by (0,RotY,RotZ) assigns X to normal
53 */
54
55 void ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY )
56 {
57         vec_t   RotY, RotZ;
58         
59         
60         /* do some cleaning */
61         if( fabs( normal[ 0 ] ) < 1e-6 )
62                 normal[ 0 ]= 0.0f;
63         if( fabs( normal[ 1 ] ) < 1e-6 )
64                 normal[ 1 ]=0.0f;
65         if( fabs( normal[ 2 ] ) < 1e-6 )
66                 normal[ 2 ] = 0.0f;
67         
68         /* compute the two rotations around y and z to rotate x to normal */
69         RotY = -atan2( normal[ 2 ], sqrt( normal[ 1 ] * normal[ 1 ] + normal[ 0 ] * normal[ 0 ]) );
70         RotZ = atan2( normal[ 1 ], normal[ 0 ] );
71         
72         /* rotate (0,1,0) and (0,0,1) to compute texX and texY */
73         texX[ 0 ] = -sin( RotZ );
74         texX[ 1 ] = cos( RotZ );
75         texX[ 2 ] = 0;
76         
77         /* the texY vector is along -z (t texture coorinates axis) */
78         texY[ 0 ] = -sin( RotY ) * cos( RotZ );
79         texY[ 1 ] = -sin( RotY ) * sin( RotZ );
80         texY[ 2 ] = -cos( RotY );
81 }