#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK); // Fast I2C / TWI
int progress = 0;
void setup() {
u8g.setColorIndex(1);
}
int points[8][2];
int orig_points [8][3] = {
{-1,-1,1},
{1,-1,1},
{1,1,1},
{-1,1,1},
{-1,-1,-1},
{1,-1,-1},
{1,1,-1},
{-1,1,-1}
};
float rotated_3d_points[8][3];
float angle_deg = 30.0;
float z_offset = -4.0;
float cube_size = 70.0;
float time_frame;
void loop() {
time_frame++;
if (angle_deg< 90-5) {
angle_deg = angle_deg + 5;
} else {
angle_deg = 0;
}
for (int i=0; i<8; i++){
rotated_3d_points[i][0] = orig_points[i][0] * cos(radians(angle_deg)) - orig_points[i][2] * sin(radians(angle_deg));
rotated_3d_points[i][1] = orig_points[i][1];
rotated_3d_points[i][2] = orig_points[i][0] * sin(radians(angle_deg)) + orig_points[i][2] * cos(radians(angle_deg)) + z_offset;
points[i][0] = round(64 + rotated_3d_points[i][0] / rotated_3d_points[i][2] * cube_size);
points[i][1] = round(32 + rotated_3d_points[i][1] / rotated_3d_points[i][2] * cube_size);
}
u8g.firstPage();
do {
u8g.drawLine(points[0][0],points[0][1],points[1][0],points[1][1]);
u8g.drawLine(points[1][0],points[1][1],points[2][0],points[2][1]);
u8g.drawLine(points[2][0],points[2][1],points[3][0],points[3][1]);
u8g.drawLine(points[3][0],points[3][1],points[0][0],points[0][1]);
u8g.drawLine(points[4][0],points[4][1],points[5][0],points[5][1]);
u8g.drawLine(points[5][0],points[5][1],points[6][0],points[6][1]);
u8g.drawLine(points[6][0],points[6][1],points[7][0],points[7][1]);
u8g.drawLine(points[7][0],points[7][1],points[4][0],points[4][1]);
u8g.drawLine(points[0][0],points[0][1],points[4][0],points[4][1]);
u8g.drawLine(points[1][0],points[1][1],points[5][0],points[5][1]);
u8g.drawLine(points[2][0],points[2][1],points[6][0],points[6][1]);
u8g.drawLine(points[3][0],points[3][1],points[7][0],points[7][1]);
//u8g.drawLine(7,10,40,55);
} while ( u8g.nextPage() );
}