All pastes #771746 Raw Edit

bellcurve hill

public text v1 · immutable
·published 2007-11-13 05:50 UTC
rendered paste body
<?php
$res=4;
$ang=deg2rad(360/(4*$res));
$hycoord=array();
$hxcoord=array();
$hill=array();
$damage=0;
$radius=10;
$height=$radius*2.5;
$cutoff=.75;
$xscale=1;
$yscale=1;
$zscale=1;
$v=0;

function damage($d){
	$h=mt_rand((10000-($d/.02)),(10000+($d/.02)))/10000;
	return $h;
}  //function

$hzindex[]=$v;
//initial circle, slightly bigger than $radius, on ground level
//the hill starting at the lowest section, but cutting it vertically every 4*$res on x-axis
$zradius=$radius*2.25;
$zpos=0;
$divs=$res*4;
for($j=0;$j<=$divs;$j++){
	if($j == $divs){
		$xn[$v]=$xn[($v-$divs)];
		$x[$v]=$x[($v-$divs)];
		$yn[$v]=$yn[($v-$divs)];
		$y[$v]=$y[($v-$divs)];
		$zn[$v]=$zn[($v-$divs)];
		$z[$v]=$z[($v-$divs)];
		$v++;
	}else{
		$xn[$v]=$xscale*damage($damage)*round(cos($ang*$j),4);
		$x[$v]=round(($zradius*$xn[$v]), 4);
		$yn[$v]=$yscale*round(sin($ang*$j),4);
		$y[$v]=round($zradius*$yn[$v],4);
		$zn[$v]=$zscale*cos(-2*$height*$zradius/pow($radius,2)*exp(-pow($zradius,2)/pow($radius,2)));;
		$z[$v]=$zscale*$zpos;
		$v++;
	}
}$hzindex[]=$v;

$slices=2*$res;
for($i=$slices;$i>((1-$cutoff)*$slices);$i--){
	$zradius=$i*2*$radius/($slices);			//This is the x position at y=0
	$zpos=$height*exp((-pow($zradius,2))/pow($radius,2));
	
	for($j=0;$j<=($divs);$j++){
	if($j == $divs){
		$xn[$v]=$xn[($v-$divs)];
		$x[$v]=$x[($v-$divs)];
		$yn[$v]=$yn[($v-$divs)];
		$y[$v]=$y[($v-$divs)];
		$zn[$v]=$zn[($v-$divs)];
		$z[$v]=$z[($v-$divs)];
		$v++;
	}else{

		$xn[$v]=$xscale*damage($damage)*round(cos($ang*$j),4);
		$x[$v]=round(($zradius*$xn[$v]), 4);
		$yn[$v]=$yscale*damage($damage)*round(sin($ang*$j),4);
		$y[$v]=round($zradius*$yn[$v],4);
		$zn[$v]=$zscale*cos((-2*$height*$zradius/pow($radius,2))*exp(-pow($zradius,2)/pow($radius,2)));
		$z[$v]=$zscale*$zpos;
		$v++;
	}
	}$hzindex[]=$v;
}unset($i,$j);
//var_dump($x);
echo "\noptions
	-j
	+r
	-ms 20
	-set _noClimb 0
end
material
	name grass
	texture std_ground
	diffuse tan
end
\n";

echo"\nmesh\n";
for($i=0;$i<count($hzindex)-1; $i++){
	echo "\n#Z index ".($i);
	for($j=0;$j<$hzindex[1];$j++){
		echo "\nvertex ".$x[($hzindex[$i]+$j)]." ".$y[($hzindex[$i]+$j)]." ".$z[($hzindex[$i]+$j)]." \t#".($hzindex[$i]+$j);
	}
}echo "\n\tinside 0 0 1\n";
for($i=0;$i<count($hzindex)-1; $i++){
	echo "\n#Z index ".($i);
	for($j=0;$j<$hzindex[1];$j++){
		echo "\nnormal ".$xn[($hzindex[$i]+$j)]." ".$yn[($hzindex[$i]+$j)]." ".$zn[($hzindex[$i]+$j)]." \t#".($hzindex[$i]+$j);
	}
}

for($i=0;$i<count($hzindex)-1; $i++){
	echo "\n#z-index $i
	matref grass
	#smoothbounce\n";
	
	if($i==count($hzindex)-2){
		echo "\nface\nvertices ";
		for($j=0;$j<$hzindex[1]-1;$j++){
			echo ($hzindex[$i]+$j)." ";
		}echo "\nendface";
	
	}else{
		for($j=0;$j<$hzindex[1]-1;$j++){
			echo "\nface\n\tvertices ".($hzindex[$i]+$j)." ".($hzindex[$i]+$j+1)." ".($hzindex[($i+1)]+$j+1)." ".($hzindex[($i+1)]+$j);
			echo "\n\tnormals ".($hzindex[$i]+$j)." ".($hzindex[$i]+$j+1)." ".($hzindex[($i+1)]+$j+1)." ".($hzindex[($i+1)]+$j);	
			echo "\nendface";
		}
	}
}	


echo "\nend";

?>