#include #include #include #include #include float x, y, z; float step = 0.05; float zbuffer[24][80]; float A = 0.0; float B = 0.0; char market[24][80]; int main() { system("clear"); while (1) { memset(market, ' ', sizeof(market)); memset(zbuffer, 0, sizeof(zbuffer)); for (float u = -1.0; u <= 1.0; u += step) { for (float v = -1.0; v <= 1.0; v += step) { float faces[6][3] = { { u, v, 1.0 }, // z = 1 { u, v, -1.0 }, // z = -1 { u, 1.0, v }, // y = 1 { u, -1.0, v }, // y = -1 { 1.0, u, v }, // x = 1 { -1.0, u, v } //x = -1 }; for (int f = 0; f < 6; f++) { float x = faces[f][0]; float y = faces[f][1]; float z = faces[f][2]; float y1 = y * cos(A) - z * sin(A); float z1 = y * sin(A) + z * cos(A); float x_rot = x * cos(B) - z1 * sin(B); float z_rot = x * sin(B) + z1 * cos(B); float dis = 3.5; float ooZ = 1.0 / (z_rot + dis); int xp = (int)(40 + 40 * x_rot * ooZ); int yp = (int)(12 + 20 * y1 * ooZ); if (yp >= 0 && xp <= 80 && yp >= 0 && yp < 24 && xp >= 0) { if (ooZ > zbuffer[yp][xp]) { zbuffer[yp][xp] = ooZ; market[yp][xp] = '*'; } } } } } printf("\x1b[H"); for (int y = 0; y < 24; y++) { for (int x = 0; x < 80; x++) { putchar(market[y][x]); } putchar('\n'); } A += 0.02; B += 0.02; usleep(11000); } }