Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

brush_primit.c (1907B)


      1 /*
      2 ===========================================================================
      3 Copyright (C) 1999-2005 Id Software, Inc.
      4 
      5 This file is part of Quake III Arena source code.
      6 
      7 Quake III Arena source code is free software; you can redistribute it
      8 and/or modify it under the terms of the GNU General Public License as
      9 published by the Free Software Foundation; either version 2 of the License,
     10 or (at your option) any later version.
     11 
     12 Quake III Arena source code is distributed in the hope that it will be
     13 useful, 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.
     16 
     17 You should have received a copy of the GNU General Public License
     18 along with Foobar; if not, write to the Free Software
     19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20 ===========================================================================
     21 */
     22 #include "qbsp.h"
     23 
     24 
     25 // global flag
     26 int	g_bBrushPrimit;
     27 
     28 // NOTE : ComputeAxisBase here and in editor code must always BE THE SAME !
     29 // WARNING : special case behaviour of atan2(y,x) <-> atan(y/x) might not be the same everywhere when x == 0
     30 // rotation by (0,RotY,RotZ) assigns X to normal
     31 void ComputeAxisBase(vec3_t normal,vec3_t texX,vec3_t texY)
     32 {
     33 	vec_t RotY,RotZ;
     34 	// do some cleaning
     35 	if (fabs(normal[0])<1e-6)
     36 		normal[0]=0.0f;
     37 	if (fabs(normal[1])<1e-6)
     38 		normal[1]=0.0f;
     39 	if (fabs(normal[2])<1e-6)
     40 		normal[2]=0.0f;
     41 	// compute the two rotations around Y and Z to rotate X to normal
     42 	RotY=-atan2(normal[2],sqrt(normal[1]*normal[1]+normal[0]*normal[0]));
     43 	RotZ=atan2(normal[1],normal[0]);
     44 	// rotate (0,1,0) and (0,0,1) to compute texX and texY
     45 	texX[0]=-sin(RotZ);
     46 	texX[1]=cos(RotZ);
     47 	texX[2]=0;
     48 	// the texY vector is along -Z ( T texture coorinates axis )
     49 	texY[0]=-sin(RotY)*cos(RotZ);
     50 	texY[1]=-sin(RotY)*sin(RotZ);
     51 	texY[2]=-cos(RotY);
     52 }