This commit is contained in:
Frater 2026-05-09 21:53:45 +02:00
commit eae91de89d
8 changed files with 641 additions and 280 deletions

View file

@ -1,3 +1,6 @@
#ifndef DEFINE_H
#define DEFINE_H
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
@ -5,4 +8,99 @@
#include <stdio.h>
#include <conio.h>
typedef int32_t fixed;
#define MODE_WIRE 0 // Transparent totalv_cache
#define MODE_HIDDEN 1 // Fil de fer avec surfaces cachées
#define MODE_SOLID 2 // Plein (Gouraud)
#define MAX_VERTEX 5000
#define MAX_FACES 8000
typedef int32_t fixed;
#define f_to_int(a) ((a) >> 16)
#define int_to_f(a) ((a) << 16)
// #define f_mul(a, b) ((fixed)(((int64_t)(a) * (b)) >> 16))
// --- Remplacement des inlines ---
static __inline fixed f_mul(fixed a, fixed b) { return (fixed)(((int64_t)a * b) >> 16); }
static __inline fixed f_div(fixed a, fixed b) { if (b == 0) return 0; return (fixed)(((int64_t)a << 16) / b); }
// Matrice 3x3 pour la rotation des normales et des sommets
typedef struct {
fixed m[3][3];
} Matrix3;
typedef struct {
fixed x, y, z;
} Vector3;
typedef struct {
int a, b, c;
uint8_t color;
uint8_t force_wire;
} Face;
typedef struct {
int x, y;
fixed z;
int intensity;
} Point2D;
typedef struct {
Vector3 *verts;
Vector3 *v_normals;
Face *faces;
int num_verts, num_faces;
} Mesh;
typedef struct {
Mesh *mesh; // Pointeur vers le modèle 3D (partagé si plusieurs sphères)
Vector3 position; // Position dans le monde
Matrix3 rotation; // Rotation locale de l'objet
} Object3D;
typedef struct { uint8_t r, g, b; } RGB;
// --- Ajout des déclarations de tables ---
extern fixed sintab[360];
extern fixed costab[360];
extern fixed inv_table[321];
extern Point2D v_cache[MAX_VERTEX];
extern uint8_t *backbuffer;
extern uint16_t *zbuffer;
extern uint8_t *vga;
// Engine.C
void init_engine_math();
void normalize(Vector3 *v);
void mat3_rotate_x(Matrix3 *m, int angle);
void mat3_rotate_y(Matrix3 *m, int angle);
void mat3_mul(Matrix3 *res, Matrix3 *a, Matrix3 *b);
// geometry.c
void add_face(Mesh *m, int a, int b, int c, uint8_t col, uint8_t wire);
void add_sphere(Mesh *m, fixed x, fixed y, fixed z, fixed r, int det, uint8_t col, uint8_t wire);
void add_cylinder(Mesh *m, fixed x, fixed y, fixed z, fixed r, fixed h, int det, uint8_t col, uint8_t wire);
void save_mesh(Mesh *m, const char *fn);
Mesh* load_mesh(const char *fname);
void free_mesh(Mesh *m);
void render_scene(Mesh *m, Matrix3 *rot, int global_mode);
// Raster.c
void draw_line_z(Point2D *p1, Point2D *p2, uint8_t col, int z_test);
void swap_pt(Point2D **a, Point2D **b);
void fill_triangle_gouraud(Point2D *p1, Point2D *p2, Point2D *p3, uint8_t base_color);
void fill_triangle_zonly(Point2D *p1, Point2D *p2, Point2D *p3);
// Graph.c
void init_vga();
void clear_buffers(uint8_t color);
void flip();
void close_vga();
// Math.c
void mat3_identity(Matrix3 *mat);
void init_engine_math();
void normalize(Vector3 *v);
#endif // DEFINE_H