#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define LARGURA 80
#define ALTURA 30
#define ESCALA 5
#define ASPECTO 2

typedef struct
{
    float x;
    float y;
    float z;
} ponto3D;

void limparTela(char tela[][LARGURA]);
void desenharPonto(char tela[][LARGURA], int x, int y, char c);
void desenharLinha(char tela[][LARGURA], int x1, int y1, int x2, int y2, char c);
void imprimirTela(char tela[][LARGURA]);
void projetar(ponto3D p, int *xTela, int *yTela);
void desenharCubo(char tela[][LARGURA], ponto3D vertices[], int arestas[][2]);
ponto3D rotacionar_em_Y(ponto3D p, float angulo);

int main(void)
{
    char tela[ALTURA][LARGURA];

    ponto3D vertices[8] =
    {
        {-1, -1, -1},
        { 1, -1, -1},
        { 1,  1, -1},
        {-1,  1, -1},

        {-1, -1,  1},
        { 1, -1,  1},
        { 1,  1,  1},
        {-1,  1,  1}
    };

    int arestas[12][2] =
    {
        {0,1}, {1,2}, {2,3}, {3,0},
        {4,5}, {5,6}, {6,7}, {7,4},
        {0,4}, {1,5}, {2,6}, {3,7}
    };

    limparTela(tela);
    desenharCubo(tela, vertices, arestas);
    imprimirTela(tela);

    return 0;
}

void limparTela(char tela[][LARGURA])
{
    for (int i = 0; i < ALTURA; i++)
    {
        for (int j = 0; j < LARGURA; j++)
        {
            tela[i][j] = ' ';
        }
    }
}

void desenharPonto(char tela[][LARGURA], int x, int y, char c)
{
    if (x >= 0 && x < LARGURA &&
        y >= 0 && y < ALTURA)
    {
        tela[y][x] = c;
    }
}

void desenharLinha(char tela[][LARGURA], int x1, int y1,int x2, int y2, char c){
    int dx = abs(x2 - x1);
    int dy = abs(y2 - y1);

    int passos = (dx > dy) ? dx : dy;

    if (passos == 0)
    {
        desenharPonto(tela, x1, y1, c);
        return;
    }

    for (int i = 0; i <= passos; i++)
    {
        float t = (float)i / passos;

        int x = x1 + (x2 - x1) * t;
        int y = y1 + (y2 - y1) * t;

        desenharPonto(tela, x, y, c);
    }
}

void imprimirTela(char tela[][LARGURA])
{
    for (int i = 0; i < ALTURA; i++)
    {
        for (int j = 0; j < LARGURA; j++)
        {
            printf("%c", tela[i][j]);
        }
        printf("\n");
    }
}

void projetar(ponto3D p, int *xTela, int *yTela)
{
    *xTela = LARGURA / 2 + p.x * ESCALA * ASPECTO;
    *yTela = ALTURA / 2 - p.y * ESCALA ;
}

void desenharCubo(char tela[][LARGURA], ponto3D vertices[], int arestas[][2]){
    for (int i = 0; i < 12; i++){

    int a = arestas[i][0];
    int b = arestas[i][1];

    int x1, y1, x2, y2;

    projetar(vertices[a], &x1, &y1);
    projetar(vertices[b], &x2, &y2);

    desenharLinha(tela, x1, y1, x2, y2, '*');
    }
}
ponto3D rotacionar_em_Y(ponto3D p, float angulo){
    
    ponto3D r;
    
    r.x =
    r.y =
    r.z =
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: