All pastes #737876 Raw Edit

foliagedI3.php

public text v1 · immutable
·published 2007-10-15 20:12 UTC
rendered paste body
<?php
$webmaterial="http://cbg.bzflag.org/images/Panzer/trees/".$material.".png";


$ang=deg2rad($angle);
$hycoord=array();
$hxcoord=array();
$object=array();
for($i = 0; $i < (360/$angle); $i++){
//	$hxcoord[]=(mt_rand(90,105)/100)*($radius*cos($ang*$i));
//	$hycoord[]=(mt_rand(90,105)/100)*($radius*sin($ang*$i));
	$hxcoord[]=$radius*cos($ang*$i);
	$hycoord[]=$radius*sin($ang*$i);
}
$object=array("0 0 0","0 0 $height");
$count=2;
foreach($hycoord as $key => $y){
	$object[$count]=$hxcoord[$key]." $y 0";
	$count++;
	$object[$count]=$hxcoord[$key]." $y $height";
	$count++;
}unset($y);
if( in_array($material, $usedmat)){
$materialcount++;
$objectname=$material.$materialcount;	//arbitrary number, it doesn't really matter
}else{
	$usedmat[]=$material;
	echo "material\n\tname $material\n\tnolighting\n\tnolighting\n\talphathresh 0.74\n\tnoradar\n\tnoshadow\n\tnoculling\n\tnosorting\n\tnotexalpha\n\ttexture $webmaterial\nend\n";
}
echo "\ndefine $objectname\n";
echo "mesh\n";

foreach($object as $key => $hvert){
	echo "\tvertex $hvert\t#$key\n";
	}unset($key);

	echo "\n\tnormal 0 0 0\n\ttexcoord .5 0\n\ttexcoord .5 1\n\n\ttexcoord 0 0\n\ttexcoord 1 0\n\ttexcoord 1 1\n\ttexcoord 0 1\n\n";
if($trunk){
	echo "\n\tvertex 0 ".-(.25*$radius)." 0\n\tvertex ".(.25*$radius)." 0 0\n\tvertex 0 ".(.25*$radius)." 0\n\tvertex ".-(.25*$radius)." 0 0\n";

	for($i=((360/$angle)*2)+2;$i < ((360/$angle)*2+5);$i++){
		echo "face\n\tvertices $i ".($i+1)." 1\nendface\n";
	}	echo "face\n\tvertices ".((360/$angle)*2+5)." ".((360/$angle)*2+2)." 1\nendface\n";
}
/*	bottom face of trunk
echo "face\n\tvertices ";
for($i=2;$i < ((360/$angle)*2); $i+=2){
	echo"$i ";
}
echo "\nendface\n";
*/
echo "drawInfo\n";
echo"\tdlist\n";
echo "\t#angvel 120\t# uncomment this line to cause the object to spin at 120 degrees/second\n";
echo "\textents -$radius -$radius 0 $radius $radius $height\n";
echo "\tsphere 0 0 ".(.5*$height)." $radius\n"; 

	echo "\tcorner 0 0 0\n\tcorner 1 0 1\n"; 
for($i=2;$i<count($object);$i+=2){
	echo "\tcorner $i 0 3\n";
	echo "\tcorner ".($i+1)." 0 4\n";
	echo "\tcorner $i 0 2\n";
	echo "\tcorner ".($i+1)." 0 5\n";
}
echo "\n\tlod\n";
echo "\tlengthPerPixel 0\t#the distance from which the object appears (default 0)\n";
	echo "\t\tmatref $material\n";
	echo "\t\t\tquadstrip ";
for($i=2;$i < ((360/$angle)*4); $i+=4){
	echo "1 0 ".($i+1)." ".($i)." ".($i+3)." ".($i+2)." ";
}
echo "1 0";
echo "\n\t\tend\t# matref\n";
echo "\tend\t# lod\n\n";

if((90/$angle) >= 2){
	echo "\tlod\n";
	echo "\tlengthPerPixel .2\n";
		echo "\t\tmatref $material\n";
		echo "\t\t\tquadstrip ";
	for($i=2;$i < ((360/$angle)*4); $i+=12){
		echo "1 0 ".($i+1)." ".($i)." ".($i+3)." ".($i+2)." ";
	}
	echo "1 0";

	echo "\n\t\tend\t# matref\n";
	echo "\tend\t# lod\n\n";
}else{
	echo "\tlod\n";
	echo "\tlengthPerPixel .2\n";
	echo "\t\tmatref $material\n";
	echo "\t\t\tquadstrip ";
	for($i=2;$i < ((360/$angle)*4); $i+=8){
		echo "1 0 ".($i+1)." ".($i)." ".($i+3)." ".($i+2)." ";
	}
	echo "1 0";

	echo "\n\t\tend\t# matref\n";
	echo "\tend\t# lod\n\n";
}
echo "\tend\t# drawInfo\n";
echo "end #mesh\nenddef\n";
//echo "group $objectname\nend\n";
?>