75 lines
2.1 KiB
Perl
75 lines
2.1 KiB
Perl
|
#! perl
|
|||
|
use Text::Wrap;
|
|||
|
use Math::Trig;
|
|||
|
|
|||
|
# generate output data for noise generators
|
|||
|
|
|||
|
srand(31456);
|
|||
|
|
|||
|
print <<END
|
|||
|
//========= Copyright <EFBFBD> 1996-2006, Valve Corporation, All rights reserved. ============//
|
|||
|
//
|
|||
|
// Purpose: static data for noise() primitives.
|
|||
|
//
|
|||
|
// \$Workfile: \$
|
|||
|
// \$NoKeywords: \$
|
|||
|
//=============================================================================//
|
|||
|
//
|
|||
|
// **** DO NOT EDIT THIS FILE. GENERATED BY DATAGEN.PL ****
|
|||
|
//
|
|||
|
|
|||
|
END
|
|||
|
;
|
|||
|
|
|||
|
@perm_a=0..255;
|
|||
|
|
|||
|
&fisher_yates_shuffle(\@perm_a);
|
|||
|
|
|||
|
$Text::Wrap::Columns=78;
|
|||
|
$Text::Wrap::break=",";
|
|||
|
$Text::Wrap::separator=",\n";
|
|||
|
|
|||
|
print "static int perm_a[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
&fisher_yates_shuffle(\@perm_a);
|
|||
|
print "static int perm_b[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
&fisher_yates_shuffle(\@perm_a);
|
|||
|
print "static int perm_c[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
&fisher_yates_shuffle(\@perm_a);
|
|||
|
print "static int perm_d[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
|
|||
|
for ($i=0;$i<256;$i++)
|
|||
|
{
|
|||
|
$float_perm=(1.0/255.0)*$perm_a[$i];
|
|||
|
$perm_a[$i] = sprintf("%f",$float_perm);
|
|||
|
}
|
|||
|
&fisher_yates_shuffle(\@perm_a);
|
|||
|
print "static float impulse_xcoords[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
&fisher_yates_shuffle(\@perm_a);
|
|||
|
print "static float impulse_ycoords[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
&fisher_yates_shuffle(\@perm_a);
|
|||
|
print "static float impulse_zcoords[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
|
|||
|
|
|||
|
# now, generate 256 random gradient vectors
|
|||
|
for($i=0; $i < 256; $i++)
|
|||
|
{
|
|||
|
$z=rand(2)-1;
|
|||
|
$phi=rand(2.0*3.141592654);
|
|||
|
$theta=asin($z);
|
|||
|
$perm_a[$i]=sprintf("%f, %f, %f ", cos($theta)*cos($phi), cos($theat)*sin($phi), $z );
|
|||
|
}
|
|||
|
print "static float s_randomGradients[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n";
|
|||
|
|
|||
|
|
|||
|
# fisher_yates_shuffle( \@array ) : generate a random permutation
|
|||
|
# of @array in place
|
|||
|
sub fisher_yates_shuffle {
|
|||
|
my $array = shift;
|
|||
|
my $i;
|
|||
|
for ($i = @$array; --$i; ) {
|
|||
|
my $j = int rand ($i+1);
|
|||
|
next if $i == $j;
|
|||
|
@$array[$i,$j] = @$array[$j,$i];
|
|||
|
}
|
|||
|
}
|