Exemplo n.º 1
0
 protected function _raytrace()
 {
     // Create basic ray ... modify direction later
     $ray = new Image_3D_Line($this->_camera->getX(), $this->_camera->getY(), $this->_camera->getZ(), new Image_3D_Vector(0, 0, 1));
     // Colorarray for resulting image
     $canvas = array();
     // Iterate over viewplane
     for ($x = -$this->_size[0]; $x < $this->_size[0]; ++$x) {
         for ($y = -$this->_size[1]; $y < $this->_size[1]; ++$y) {
             $canvas[$x + $this->_size[0]][$y + $this->_size[1]] = array();
             // Iterate over rays for one pixel
             $inPixelRayDiff = 1 / ($this->_rays + 1);
             for ($i = 0; $i < $this->_rays; ++$i) {
                 for ($j = 0; $j < $this->_rays; ++$j) {
                     // Modify ray
                     $ray->setDirection(new Image_3D_Vector($x + $i * $inPixelRayDiff - $this->_camera->getX(), $y + $j * $inPixelRayDiff - $this->_camera->getY(), -$this->_camera->getZ()));
                     // Get color for ray
                     $color = $this->_sendRay($ray, $this->_depth);
                     if ($color !== false) {
                         $canvas[$x + $this->_size[0]][$y + $this->_size[1]][] = $color;
                     } else {
                         $canvas[$x + $this->_size[0]][$y + $this->_size[1]][] = $this->_background;
                     }
                 }
             }
         }
     }
     return $canvas;
 }