1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * 3d Library 7 * 8 * PHP versions 5 9 * 10 * LICENSE: 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with this library; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 * @category Image 26 * @package Image_3D 27 * @author Kore Nordmann <3d@kore-nordmann.de> 28 * @copyright 1997-2005 Kore Nordmann 29 * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 30 * @version CVS: $Id$ 31 * @link http://pear.php.net/package/PackageName 32 * @since File available since Release 0.1.0 33 */ 34 35 36/** 37 * Image_3D_Light 38 * 39 * @category Image 40 * @package Image_3D 41 * @author Kore Nordmann <3d@kore-nordmann.de> 42 * @copyright 1997-2005 Kore Nordmann 43 * @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1 44 * @version Release: @package_version@ 45 * @link http://pear.php.net/package/PackageName 46 * @since Class available since Release 0.1.0 47 */ 48class Image_3D_Light_Spotlight extends Image_3D_Light { 49 50 protected $_direction; 51 protected $_angle; 52 protected $_float; 53 54 public function __construct($x, $y, $z, $parameter) { 55 parent::__construct($x, $y, $z); 56 57 $aim = new Image_3D_Vector($parameter['aim'][0], $parameter['aim'][1], $parameter['aim'][2]); 58 $light = new Image_3D_Vector($this->_x, $this->_y, $this->_z); 59 $light->sub($aim); 60 $this->_direction = $light; 61 $this->_direction->unify(); 62 63 $this->_angle = deg2rad($parameter['angle']) / 2; 64 $this->_float = (int) $parameter['float']; 65 } 66 67 public function getColor(Image_3D_Interface_Enlightenable $polygon) 68 { 69 $color = clone ($polygon->getColor()); 70 71 $light = new Image_3D_Vector($this->_x, $this->_y, $this->_z); 72 $light->sub($polygon->getPosition()); 73 $light->unify(); 74 75 $angle = $light->getAngle($this->_direction); 76 if ($angle > $this->_angle) return $color; 77 78 if ($this->_float) { 79 $factor = 1 - pow($angle / $this->_angle, $this->_float); 80 } else { 81 $factor = 1; 82 } 83 84 $light->add(new Image_3D_Vector(0, 0, -1)); 85 $normale = $polygon->getNormale(); 86 87 $angle = abs(1 - $normale->getAngle($light)); 88 89 $color->addLight($this->_color, $angle * $factor); 90 return $color; 91 } 92} 93 94