Example #1
0
 public function renderSegment(Vertex $origin, Vertex $end)
 {
     $ox = round($origin->get_x());
     $oy = round($origin->get_y());
     $ex = round($end->get_x());
     $ey = round($end->get_y());
     $size = sqrt(pow($ex - $ox, 2) + pow($ey - $oy, 2));
     $dx = round($ox - $ex >= 0 ? $ox - $ex : $ex - $ox);
     $dy = round($oy - $ey >= 0 ? $oy - $ey : $ey - $oy);
     $sx = round($ox < $ex ? 1 : -1);
     $sy = round($oy < $ey ? 1 : -1);
     $errx = round($dx > $dy ? $dx : -$dy) / 2;
     while ($ox != $ex || $oy != $ey) {
         $current_size = sqrt(pow($ex - $ox, 2) + pow($ey - $oy, 2));
         $this->renderVertex(new Vertex(['x' => $ox, 'y' => $oy, 'z' => 1, 'color' => $origin->get_color()->sub($end->get_color())->mult(1 - $current_size / $size)]));
         $erry = $errx;
         if ($erry > -$dx) {
             $errx -= $dy;
             $ox += $sx;
         }
         if ($erry < $dy) {
             $errx += $dx;
             $oy += $sy;
         }
     }
     $this->renderVertex(new Vertex(['x' => $ox, 'y' => $oy, 'z' => 1, 'color' => $end->get_color()]));
     return;
 }
Example #2
0
 public function transformVertex(Vertex $v)
 {
     $x = $this->_matrix['x']['x'] * $v->get_x() + $this->_matrix['x']['y'] * $v->get_y();
     $x += $this->_matrix['x']['z'] * $v->get_z() + $this->_matrix['x']['w'] * $v->get_w();
     $y = $this->_matrix['y']['x'] * $v->get_x() + $this->_matrix['y']['y'] * $v->get_y();
     $y += $this->_matrix['y']['z'] * $v->get_z() + $this->_matrix['y']['w'] * $v->get_w();
     $z = $this->_matrix['z']['x'] * $v->get_x() + $this->_matrix['z']['y'] * $v->get_y();
     $z += $this->_matrix['z']['z'] * $v->get_z() + $this->_matrix['z']['w'] * $v->get_w();
     $w = $this->_matrix['w']['x'] * $v->get_x() + $this->_matrix['w']['y'] * $v->get_y();
     $w += $this->_matrix['w']['z'] * $v->get_z() + $this->_matrix['w']['w'] * $v->get_w();
     $res = new Vertex(array('x' => $x, 'y' => $y, 'z' => $z, 'w' => $w));
     return $res;
 }