/** * @file 3d.h * @brief Fixed-point 3D graphics engine * * Provides matrix-based 3D transformations and rendering primitives * for the Channel3 video output. Uses 256 = 1.0 fixed-point math. * * Original Copyright 2015 <>< Charles Lohr * ESP32 Port 2024 */ #ifndef _3D_H #define _3D_H #include #include "video_broadcast.h" // External references extern int gframe; extern uint8_t *frontframe; extern int16_t ProjectionMatrix[16]; extern int16_t ModelviewMatrix[16]; extern int CNFGPenX, CNFGPenY; extern uint8_t CNFGBGColor; extern uint8_t CNFGLastColor; extern uint8_t CNFGDialogColor; // Drawing primitives void CNFGTackSegment(int x0, int y0, int x1, int y1); int LABS(int x); // Pixel plotting function pointer (set by CNFGColor) extern void (*CNFGTackPixel)(int x, int y); // Coordinate transformation void LocalToScreenspace(int16_t *coords_3v, int16_t *o1, int16_t *o2); // Trigonometry (lookup table based) int16_t tdSIN(uint8_t iv); int16_t tdCOS(uint8_t iv); /** * @brief Set drawing color * @param col Color value: * 0-15: Standard density colors * 16: Black, double-density * 17: White, double-density */ void CNFGColor(uint8_t col); // Matrix operations void tdTranslate(int16_t *f, int16_t x, int16_t y, int16_t z); void tdScale(int16_t *f, int16_t x, int16_t y, int16_t z); void tdRotateEA(int16_t *f, int16_t x, int16_t y, int16_t z); void tdMultiply(int16_t *fin1, int16_t *fin2, int16_t *fout); void tdPTransform(int16_t *pin, int16_t *f, int16_t *pout); void td4Transform(int16_t *pin, int16_t *f, int16_t *pout); void MakeTranslate(int x, int y, int z, int16_t *out); void Perspective(int fovx, int aspect, int zNear, int zFar, int16_t *out); void tdIdentity(int16_t *matrix); void MakeYRotationMatrix(uint8_t angle, int16_t *f); void MakeXRotationMatrix(uint8_t angle, int16_t *f); // High-level drawing void DrawGeoSphere(void); void Draw3DSegment(int16_t *c1, int16_t *c2); void CNFGDrawText(const char *text, int scale); void CNFGDrawBox(int x1, int y1, int x2, int y2); void CNFGTackRectangle(short x1, short y1, short x2, short y2); // Perlin noise int16_t tdPerlin2D(int16_t x, int16_t y); int16_t tdFLerp(int16_t a, int16_t b, int16_t t); int16_t tdNoiseAt(int16_t x, int16_t y); #endif // _3D_H