public function getAngle(Image_3D_Vector $vector) { $length = $vector->length() * $this->length(); if ($length < 0.0001) { return 1; } return abs(acos($this->scalar($vector) / $length) / M_PI - 0.5) * 2; }
public function getColor(Image_3D_Interface_Enlightenable $polygon) { $color = clone $polygon->getColor(); $light = new Image_3D_Vector($this->_x, $this->_y, $this->_z); $light->sub($polygon->getPosition()); $distance = $light->length(); if ($distance > $this->_distance) { return $color; } $factor = 1 - pow($distance / $this->_distance, $this->_falloff); $light->unify(); $light->add(new Image_3D_Vector(0, 0, -1)); $normale = $polygon->getNormale(); $angle = abs(1 - $normale->getAngle($light)); $color->addLight($this->_color, $angle * $factor); return $color; }