Beispiel #1
0
    $angleZ = 15 + $nnn++ / 2;
    $angleY = -30 + +($nnn++ / 3);
    /* It will store transformed vertices. */
    $t = array();
    $l = array();
    /* Transform all the vertices. */
    foreach ($vertices as $v) {
        $rotated = $v->rotateX($angleX)->rotateY($angleY)->rotateZ($angleZ);
        $t[] = $rotated->project($img_width, $img_height, 256, 6);
        $l[] = $rotated->project($img_width, $img_height, 256, 9);
    }
    $avgZ = array();
    foreach ($faces as $index => $f) {
        $avgZ["{$index}"] = ($t[$f[0]]->z + $t[$f[1]]->z + $t[$f[2]]->z + $t[$f[3]]->z) / 4.0;
    }
    arsort($avgZ);
    foreach ($avgZ as $index => $z) {
        $f = $faces[$index];
        $points = array($l[$f[0]]->x, $l[$f[0]]->y, $l[$f[1]]->x, $l[$f[1]]->y, $l[$f[2]]->x, $l[$f[2]]->y, $l[$f[3]]->x, $l[$f[3]]->y);
        CLI\Graphics::line($l[$f[0]]->x, $l[$f[0]]->y, $l[$f[1]]->x, $l[$f[1]]->y, '.');
        CLI\Graphics::line($l[$f[1]]->x, $l[$f[1]]->y, $l[$f[2]]->x, $l[$f[2]]->y, '.');
        CLI\Graphics::line($l[$f[2]]->x, $l[$f[2]]->y, $l[$f[3]]->x, $l[$f[3]]->y, '.');
        CLI\Graphics::line($l[$f[3]]->x, $l[$f[3]]->y, $l[$f[0]]->x, $l[$f[0]]->y, '.');
        $points = array($t[$f[0]]->x, $t[$f[0]]->y, $t[$f[1]]->x, $t[$f[1]]->y, $t[$f[2]]->x, $t[$f[2]]->y, $t[$f[3]]->x, $t[$f[3]]->y);
        CLI\Graphics::line($t[$f[0]]->x, $t[$f[0]]->y, $t[$f[1]]->x, $t[$f[1]]->y);
        CLI\Graphics::line($t[$f[1]]->x, $t[$f[1]]->y, $t[$f[2]]->x, $t[$f[2]]->y);
        CLI\Graphics::line($t[$f[2]]->x, $t[$f[2]]->y, $t[$f[3]]->x, $t[$f[3]]->y);
        CLI\Graphics::line($t[$f[3]]->x, $t[$f[3]]->y, $t[$f[0]]->x, $t[$f[0]]->y);
    }
    usleep(50000);
}