rendered paste body<?php
//a normal is x/total length, y/length, z/length
//normal is also cos($ang) for x and sin($ang) for y *(no need fro the radius.)
//a circle:
$divisions=32;
$slices=16;
$radius=10;
$ang=deg2rad((360/$divisions));
$zang=deg2rad(360/$slices);
$v=0;
$xshift=100;
$xn=array();
$x=array();
$yn=array();
$y=array();
$zn=array();
$z=array();
$zindex=array();
for($i=0;$i<=$slices/2;$i++){
$zcoord=$i*2*$radius/$slices;
$znorm=-cos($i*$zang);
$zpos=$radius*$znorm+$radius;
$zradius=$radius*sin($i*$zang);
$zindex[]=$v;
//add an if statement here
for($j=0;$j<=$divisions;$j++){
$xn[$v]=round(cos($ang*$j),4);
$x[$v]=round(($zradius*$xn[$v])+$xshift,4);
$xt[$v]=round(($j+8)/$divisions,4);
$yn[$v]=round(sin($ang*$j),4);
$y[$v]=round($zradius*$yn[$v],4);
$yt[$v]=round($i/$slices*2,4); //why is this *2?? I do not know
$zn[$v]=round($znorm,4);
$z[$v]=round($zpos,4);
$v++;
}
}
echo "material
name texture
texture pacman
alphathresh .5
end\n";
echo "material
name black
texture pacmanguts
end";
echo "\ndefine sphere\nmesh\n";
unset($value,$key);
foreach($x as $key => $value){
echo "vertex $value $y[$key] $z[$key] #$key\n";
}unset($value,$key);
foreach($xn as $key => $value){
echo "normal $value $yn[$key] $zn[$key] #$key\n";
}unset($value,$key);
foreach($xt as $key => $value){
echo "texcoord $value $yt[$key] #$key\n";
}unset($value,$key);
/*foreach($zindex as $slice){
for($i=$slice;$i<=$slice+$divisions;$i++){
echo "\nmatref texture";
echo "\nface";
echo "\n\tvertices $i ".($i+1)." ".($i+$divisions+1)." ".($i+$divisions);
echo "\nnormals $i ".($i+1)." ".($i+$divisions+1)." ".($i+$divisions);
echo "\ntexcoords $i ".($i+1)." ".($i+$divisions+1)." ".($i+$divisions);
echo "\nendface";
}
}
*/
echo "\ndrawInfo\nangvel 30\nsphere 0 0 ".($radius)." ".($radius+$xshift)." \nextents ".(-$radius-$xshift)." ".(-$radius-$xshift)." 0 ".($radius+$xshift)." ".($radius+$xshift)." ".(2*$radius)."\n";
foreach($x as $key => $value){
echo "corner $key $key $key\n";
}unset($value,$key);
echo "lod\nLengthPerPixel 0\nmatref texture\n";
foreach($zindex as $key=>$slice){
if($key == $slices/2){
}else{
echo "\n\tquads ";
for($i=$slice;$i<$slice+$divisions;$i++){
echo "$i ".($i+1)." ".($i+$divisions+2)." ".($i+$divisions+1)." ";
}
}
}unset($key,$slice);
echo "\nend #matref\nmatref black\n";
foreach($zindex as $key=>$slice){
if($key == $slices/2){
}else{
echo "\n\tquads ";
for($i=$slice;$i<$slice+$divisions;$i++){
echo($i+$divisions+1)." ".($i+$divisions+2)." ". ($i+1)." ".($i)." ";
}
}
}
echo "\nend\nend #lod\nend #drawinfo\nend #mesh";
echo "\nenddef\n";
echo "group sphere\n shift 0 0 10\nspin -45 0 0 1\nend\n";
?>