1000) { $img_width = 1000; } if($img_height == '') { $img_height = 750; } if($img_height < 350) { $img_height = 350; } if($img_height > 1000) { $img_height = 1000; } if($focal == '') { $focal = 300; } if($focal < 90) { $focal = 90; }*/ if($model == '') { $model = 'house'; } //3D rendering $img = imagecreatetruecolor($img_width, $img_height); // Allow for transperancy if($alpha == true) { imagesavealpha($img, true); $trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127); imagefill($img, 0, 0, $trans_colour); } $xml = simplexml_load_file('models/'.$model.'.xml'); // Allocate some colors $blue = imagecolorallocate($img, 0, 0, 255); $red = imagecolorallocate($img, 255, 0, 0); if(!$xml->colors->color) { $blue = imagecolorallocate($img, 0, 0, 255); $red = imagecolorallocate($img, 255, 0, 0); } else { foreach($xml->colors->color as $c) { $name = strval($c['name']); if(strval($c['a']) == 0) { $$name = imagecolorallocate($img, strval($c['r']), strval($c['g']), strval($c['b'])); } else { $$name = imagecolorallocatealpha($img, strval($c['r']), strval($c['g']), strval($c['b']), strval($c['a'])); } } } //Set AA imageantialias($img, true); // Set points in space $points = array(); foreach($xml->points->point as $p) { $points[] = make3DPoint($p['x'], $p['y'], $p['z']); } //Set rotation $x_rad = ( $x_rotate / (180/pi()) ); $y_rad = ( $y_rotate / (180/pi()) ); $z_rad = ( $z_rotate / (180/pi()) ); $cubeAxisRotations = make3DPoint($x_rad, $y_rad, $z_rad); $pointarray = Transform2Dto3D($points, $cubeAxisRotations, $focal, ($img_width/2), ($img_height/2)); //Description $disclaimer = 'Gerben Geijteman | '.date('r', time()); imagestring($img, 2, 15, 10, "Viewport 1 (w".$img_width."px, h".$img_height."px) F/".$focal.", X ".$x_rotate."°, Y ".$y_rotate."°, Z ".$z_rotate."°", $blue); imagestring($img, 2, 15, 25, $disclaimer, $blue); //$ip = gethostbyaddr($_SERVER['REMOTE_ADDR']).' ('.$_SERVER['REMOTE_ADDR'].')'; //imagestring($img , 2, 10, $img_height-18, $ip, $blue); //Borders /*imageline($img, 0, 0, $img_width, 0, $red); imageline($img, 0, 0, 0, $img_height, $red); imageline($img, 0, $img_height-1, $img_width, $img_height-1, $red); imageline($img, $img_width-1, 0, $img_width-1, $img_height-1, $red);*/ //Point numbers! $c = (count($pointarray)-1); foreach($pointarray as $p) { $x = $p['x']; $y = $p['y']; //imagestring($img, 2, $x, $y, $c, $blue); //imagestring($img, 2, $x, $y, '.', $blue); $c--; } //Lines if($xml->lines->line) { foreach($xml->lines->line as $l) { imageline($img, $pointarray[strval($l['xy0'])]['x'], $pointarray[strval($l['xy0'])]['y'], $pointarray[strval($l['xy1'])]['x'], $pointarray[strval($l['xy1'])]['y'], $$l['color']); //imagelinethick($img, $pointarray[strval($l['xy0'])]['x'], $pointarray[strval($l['xy0'])]['y'], $pointarray[strval($l['xy1'])]['x'], $pointarray[strval($l['xy1'])]['y'], $$l['color'], 2); } } //Filling if($xml->polygons->polygon) { foreach($xml->polygons->polygon as $p) { $values = array(); foreach($p->outline as $o) { $values[] = $pointarray[strval($o['x'])]['x']; $values[] = $pointarray[strval($o['y'])]['y']; } imagefilledpolygon($img, $values, count($values)/2, $$p['color']); } } //Publishing if($debug) { echo '
';
		var_dump($values);
		var_dump($pointarray);
		echo '
'; } else { header("Content-type: image/png"); imagepng($img); imagedestroy($img); } function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1) { /* this way it works well only for orthogonal lines imagesetthickness($image, $thick); return imageline($image, $x1, $y1, $x2, $y2, $color); */ if ($thick == 1) { return imageline($image, $x1, $y1, $x2, $y2, $color); } $t = $thick / 2 - 0.5; if ($x1 == $x2 || $y1 == $y2) { return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color); } $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q $a = $t / sqrt(1 + pow($k, 2)); $points = array( round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a), round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a), round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a), round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a), ); imagefilledpolygon($image, $points, 4, $color); return imagepolygon($image, $points, 4, $color); } ?>