brush_primit.c 1.9 KB

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