]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/brush_primit.c
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / tools / quake3 / q3map2 / brush_primit.c
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \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
11 \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
16 \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
20 \r
21 ----------------------------------------------------------------------------------\r
22 \r
23 This code has been altered significantly from its original form, to support\r
24 several games based on the Quake III Arena engine, in the form of "Q3Map2."\r
25 \r
26 ------------------------------------------------------------------------------- */\r
27 \r
28 \r
29 \r
30 /* marker */\r
31 #define BRUSH_PRIMIT_C\r
32 \r
33 \r
34 \r
35 /* dependencies */\r
36 #include "q3map2.h"\r
37 \r
38 \r
39 \r
40 /* -------------------------------------------------------------------------------\r
41 \r
42 functions\r
43 \r
44 ------------------------------------------------------------------------------- */\r
45 \r
46 /*\r
47 ComputeAxisBase()\r
48 computes the base texture axis for brush primitive texturing\r
49 note: ComputeAxisBase here and in editor code must always BE THE SAME!\r
50 warning: special case behaviour of atan2( y, x ) <-> atan( y / x ) might not be the same everywhere when x == 0\r
51 rotation by (0,RotY,RotZ) assigns X to normal\r
52 */\r
53 \r
54 void ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY )\r
55 {\r
56         vec_t   RotY, RotZ;\r
57         \r
58         \r
59         /* do some cleaning */\r
60         if( fabs( normal[ 0 ] ) < 1e-6 )\r
61                 normal[ 0 ]= 0.0f;\r
62         if( fabs( normal[ 1 ] ) < 1e-6 )\r
63                 normal[ 1 ]=0.0f;\r
64         if( fabs( normal[ 2 ] ) < 1e-6 )\r
65                 normal[ 2 ] = 0.0f;\r
66         \r
67         /* compute the two rotations around y and z to rotate x to normal */\r
68         RotY = -atan2( normal[ 2 ], sqrt( normal[ 1 ] * normal[ 1 ] + normal[ 0 ] * normal[ 0 ]) );\r
69         RotZ = atan2( normal[ 1 ], normal[ 0 ] );\r
70         \r
71         /* rotate (0,1,0) and (0,0,1) to compute texX and texY */\r
72         texX[ 0 ] = -sin( RotZ );\r
73         texX[ 1 ] = cos( RotZ );\r
74         texX[ 2 ] = 0;\r
75         \r
76         /* the texY vector is along -z (t texture coorinates axis) */\r
77         texY[ 0 ] = -sin( RotY ) * cos( RotZ );\r
78         texY[ 1 ] = -sin( RotY ) * sin( RotZ );\r
79         texY[ 2 ] = -cos( RotY );\r
80 }\r