Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB

  1. #! perl
  2. use Math::Trig;
  3. # generate a table of vectors to use for the k dop basis. We will add
  4. # the 3 basic vectors and then add more vectors until we get to the
  5. # target of 16 directions.
  6. srand(31456);
  7. print <<END
  8. //========= Copyright 1996-2006, Valve Corporation, All rights reserved. ============//
  9. //
  10. // Purpose: static vector table for 32-plane kdops
  11. //
  12. // \$Workfile: \$
  13. // \$NoKeywords: \$
  14. //=============================================================================//
  15. //
  16. // **** DO NOT EDIT THIS FILE. GENERATED BY genvectors.PL ****
  17. //
  18. END
  19. ;
  20. my $nNumVectors = 3;
  21. for( $i = 0; $i < 3; $i++ )
  22. {
  23. push @XC, &ZeroOne( $i == 0 );
  24. push @YC, &ZeroOne( $i == 1 );
  25. push @ZC, &ZeroOne( $i == 2 );
  26. }
  27. # now, generate a bunch of random vectors and keep whichever is farthest away from all vectors chosen thus far
  28. while( $#XC < 15 )
  29. {
  30. my $mindot = 2.0;
  31. for( $t = 0; $t < 1000*100; $t++ )
  32. {
  33. my $closest_comp_dot = 0;
  34. $z=rand(2)-1;
  35. $phi=rand(2.0*3.141592654);
  36. $theta=asin($z);
  37. $x = cos($theta)*cos($phi);
  38. $y = cos($theta)*sin($phi);
  39. for( $c = 0; $c <= $#XC; $c++ )
  40. {
  41. my $dot = abs( $x * $XC[$c] + $y * $YC[$c] + $z * $ZC[$c] );
  42. $closest_comp_dot = $dot if ( $closest_comp_dot < $dot );
  43. }
  44. if ( $closest_comp_dot < $mindot )
  45. {
  46. $mindot = $closest_comp_dot;
  47. $bestx = $x;
  48. $besty = $y;
  49. $bestz = $z;
  50. }
  51. }
  52. #print "dot = $mindot ($bestx, $besty, $bestz)\n";
  53. push @XC, $bestx;
  54. push @YC, $besty;
  55. push @ZC, $bestz;
  56. }
  57. # output
  58. foreach $_ ( ( 'X', 'Y', 'Z' ) )
  59. {
  60. print "const fltx4 g_KDop32$_"."Dirs[] =\n{\n";
  61. for( $i = 0; $i <= $#XC; $i++ )
  62. {
  63. print "\t{ " if ( ( $i & 3 ) == 0 );
  64. $vname= $_."C";
  65. printf "%f, ",$$vname[$i];
  66. print " },\n" if ( ( $i & 3 ) == 3 );
  67. }
  68. print "};\n\n";
  69. }
  70. sub ZeroOne
  71. {
  72. my $n = pop(@_);
  73. return 0 unless( $n );
  74. return 1;
  75. }