running ok
This commit is contained in:
parent
c6d6f787f7
commit
8e30b7692f
8 changed files with 371 additions and 356 deletions
|
|
@ -12,8 +12,13 @@
|
|||
#define MODE_HIDDEN 1
|
||||
#define MODE_SOLID 2
|
||||
|
||||
#define SCREEN_W 320
|
||||
#define SCREEN_H 200
|
||||
#define SCREEN_PIXELS (SCREEN_W * SCREEN_H)
|
||||
|
||||
#define MAX_VERTEX 5000
|
||||
#define MAX_FACES 8000
|
||||
#define MAX_OBJECTS 64
|
||||
|
||||
typedef struct { uint8_t r, g, b; } RGB;
|
||||
|
||||
|
|
@ -44,23 +49,36 @@ static __inline fixed f_div(fixed a, fixed b) { if (b == 0) return 0; return (fi
|
|||
|
||||
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 { int a, b, c; uint8_t force_wire; } Face;
|
||||
typedef struct { int x, y; fixed z; fixed intensity; } Point2D;
|
||||
|
||||
|
||||
/* Structure pour l'univers */
|
||||
/* Un objet dans l'univers : tranche du pool partagé + transform */
|
||||
typedef struct {
|
||||
Mesh *mesh;
|
||||
Vector3 pos;
|
||||
int vert_start, num_verts; /* indices dans Universe.verts/v_normals */
|
||||
int face_start, num_faces; /* indices dans Universe.faces */
|
||||
Vector3 pos; /* position monde courante (mise à jour par orbite) */
|
||||
Vector3 base_pos; /* offset par rapport au centre d'orbite */
|
||||
Matrix3 rot;
|
||||
uint8_t color;
|
||||
} Object3D;
|
||||
|
||||
/* Pool unique pour toute la scène */
|
||||
typedef struct {
|
||||
Vector3 verts[MAX_VERTEX];
|
||||
Vector3 v_normals[MAX_VERTEX];
|
||||
Face faces[MAX_FACES];
|
||||
int num_verts, num_faces;
|
||||
Object3D objects[MAX_OBJECTS];
|
||||
int num_objects;
|
||||
} Universe;
|
||||
|
||||
typedef struct {
|
||||
Vector3 pos;
|
||||
} Camera;
|
||||
|
||||
/* Mesh dynamique conservé pour save/load uniquement */
|
||||
typedef struct { Vector3 *verts; Vector3 *v_normals; Face *faces; int num_verts, num_faces; } Mesh;
|
||||
|
||||
/* Globales */
|
||||
extern fixed sintab[360], costab[360];
|
||||
extern Point2D v_cache[MAX_VERTEX];
|
||||
|
|
@ -75,12 +93,13 @@ 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);
|
||||
|
||||
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);
|
||||
/* Retournent un pointeur sur le nouvel Object3D, NULL si pool saturé */
|
||||
Object3D* add_sphere (Universe *uni, fixed x, fixed y, fixed z, fixed r, int det, uint8_t col, uint8_t wire);
|
||||
Object3D* add_cylinder(Universe *uni, fixed x, fixed y, fixed z, fixed r, fixed h, int det, uint8_t col, uint8_t wire);
|
||||
|
||||
void render_universe(Object3D *objs, int num_objs, Camera *cam, int mode);
|
||||
void render_universe(Universe *uni, Camera *cam, int mode);
|
||||
|
||||
void init_vga(void);
|
||||
int init_vga(void);
|
||||
void clear_buffers(uint8_t color);
|
||||
void flip(void);
|
||||
void close_vga(void);
|
||||
|
|
@ -88,7 +107,6 @@ 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);
|
||||
|
||||
void normalize(Vector3 *v);
|
||||
void save_mesh(Mesh *m, const char *fn);
|
||||
Mesh *load_mesh(const char *fname);
|
||||
void free_mesh(Mesh *m);
|
||||
|
|
|
|||
Loading…
Reference in a new issue