/*******************************************************************
ESP32 Cheap Yellow Display.
https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display
If you find what I do useful and would like to support me,
please consider becoming a sponsor on Github
https://github.com/sponsors/witnessmenow/
Written by Brian Lough
YouTube: https://www.youtube.com/brianlough
Twitter: https://twitter.com/witnessmenow
*******************************************************************/
// Make sure to copy the UserSetup.h file into the library as
// per the Github Instructions. The pins are defined in there.
// Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
// Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
// Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
// Note the following larger fonts are primarily numeric only!
// Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
// Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
// Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#include "User_Setup.h"
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
// Simple 3D point structure
struct Point3D {
float x, y, z;
};
// Example vertices representing a rough latitude/longitude grid or cube/sphere approximation
Point3D vertices[] = {
{-50, -50, -50}, {50, -50, -50}, {50, 50, -50}, {-50, 50, -50},
{-50, -50, 50}, {50, -50, 50}, {50, 50, 50}, {-50, 50, 50}
};
float angleX = 0;
float angleY = 0;
void setup() {
tft.init();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK);
}
void loop() {
tft.fillScreen(TFT_BLACK); // Clear screen for next frame
angleX += 0.03;
angleY += 0.05;
// Center of the 240x240 display is (120, 120)
int cx = 120;
int cy = 120;
for (int i = 0; i < 8; i++) {
// Rotate around X axis
float radX = angleX;
float y1 = vertices[i].y * cos(radX) - vertices[i].z * sin(radX);
float z1 = vertices[i].y * sin(radX) + vertices[i].z * cos(radX);
float x1 = vertices[i].x;
// Rotate around Y axis
float radY = angleY;
float x2 = x1 * cos(radY) + z1 * sin(radY);
float z2 = -x1 * sin(radY) + z1 * cos(radY);
float y2 = y1;
// Simple perspective projection
int screenX = cx + (x2 * 100) / (z2 + 200);
int screenY = cy + (y2 * 100) / (z2 + 200);
// Draw point/pixel
tft.fillCircle(screenX, screenY, 3, TFT_CYAN);
}
delay(30); // Control frame rate
}