fixed
This commit is contained in:
parent
eae91de89d
commit
c6d6f787f7
8 changed files with 667 additions and 485 deletions
|
|
@ -8,99 +8,89 @@
|
|||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
#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 MODE_WIRE 0
|
||||
#define MODE_HIDDEN 1
|
||||
#define MODE_SOLID 2
|
||||
|
||||
#define MAX_VERTEX 5000
|
||||
#define MAX_FACES 8000
|
||||
#define MAX_VERTEX 5000
|
||||
#define MAX_FACES 8000
|
||||
|
||||
typedef struct { uint8_t r, g, b; } RGB;
|
||||
|
||||
#define COLOR0 0 // 0: Noir
|
||||
#define COLOR1 1 // 1: Rouge vif
|
||||
#define COLOR2 2 // 2: Vert vif
|
||||
#define COLOR3 3 // 3: Bleu vif
|
||||
#define COLOR4 4 // 4: Jaune
|
||||
#define COLOR5 5 // 5: Magenta
|
||||
#define COLOR6 6 // 6: Cyan
|
||||
#define COLOR7 7 // 7: Blanc
|
||||
#define COLOR8 8 // 8: Rouge sombre
|
||||
#define COLOR9 9 // 9: Vert sombre
|
||||
#define COLOR10 10 // 10: Bleu sombre
|
||||
#define COLOR11 11 // 11: Gris
|
||||
#define COLOR12 12 // 12: Orange
|
||||
#define COLOR13 13 // 13: Citron vert
|
||||
#define COLOR14 14 // 14: Marron
|
||||
#define COLOR15 15 // 15: Bleu nuit
|
||||
|
||||
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 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 {
|
||||
fixed x, y, z;
|
||||
} Vector3;
|
||||
|
||||
/* Structure pour l'univers */
|
||||
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
|
||||
Mesh *mesh;
|
||||
Vector3 pos;
|
||||
Matrix3 rot;
|
||||
uint8_t color;
|
||||
} Object3D;
|
||||
|
||||
typedef struct { uint8_t r, g, b; } RGB;
|
||||
typedef struct {
|
||||
Vector3 pos;
|
||||
} Camera;
|
||||
|
||||
// --- Ajout des déclarations de tables ---
|
||||
extern fixed sintab[360];
|
||||
extern fixed costab[360];
|
||||
extern fixed inv_table[321];
|
||||
/* Globales */
|
||||
extern fixed sintab[360], costab[360];
|
||||
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);
|
||||
/* Prototypes */
|
||||
void init_engine_math(void);
|
||||
void mat3_identity(Matrix3 *mat);
|
||||
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);
|
||||
void render_universe(Object3D *objs, int num_objs, Camera *cam, int mode);
|
||||
|
||||
// Graph.c
|
||||
void init_vga();
|
||||
void init_vga(void);
|
||||
void clear_buffers(uint8_t color);
|
||||
void flip();
|
||||
void close_vga();
|
||||
void flip(void);
|
||||
void close_vga(void);
|
||||
|
||||
void fill_triangle_gouraud(Point2D *p1, Point2D *p2, Point2D *p3, uint8_t base_color);
|
||||
void draw_line_z(Point2D *p1, Point2D *p2, uint8_t col, int z_test);
|
||||
|
||||
// Math.c
|
||||
void mat3_identity(Matrix3 *mat);
|
||||
void init_engine_math();
|
||||
void normalize(Vector3 *v);
|
||||
void save_mesh(Mesh *m, const char *fn);
|
||||
Mesh *load_mesh(const char *fname);
|
||||
void free_mesh(Mesh *m);
|
||||
|
||||
#endif // DEFINE_H
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue