1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
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.
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.
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
22 ----------------------------------------------------------------------------------
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."
27 ------------------------------------------------------------------------------- */
32 #define BRUSH_PRIMIT_C
41 /* -------------------------------------------------------------------------------
45 ------------------------------------------------------------------------------- */
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
55 void ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY ){
59 /* do some cleaning */
60 if ( fabs( normal[ 0 ] ) < 1e-6 ) {
63 if ( fabs( normal[ 1 ] ) < 1e-6 ) {
66 if ( fabs( normal[ 2 ] ) < 1e-6 ) {
70 /* compute the two rotations around y and z to rotate x to normal */
71 RotY = -atan2( normal[ 2 ], sqrt( normal[ 1 ] * normal[ 1 ] + normal[ 0 ] * normal[ 0 ] ) );
72 RotZ = atan2( normal[ 1 ], normal[ 0 ] );
74 /* rotate (0,1,0) and (0,0,1) to compute texX and texY */
75 texX[ 0 ] = -sin( RotZ );
76 texX[ 1 ] = cos( RotZ );
79 /* the texY vector is along -z (t texture coorinates axis) */
80 texY[ 0 ] = -sin( RotY ) * cos( RotZ );
81 texY[ 1 ] = -sin( RotY ) * sin( RotZ );
82 texY[ 2 ] = -cos( RotY );