parametrage de math_surf
This commit is contained in:
parent
a45540412c
commit
b1c8be9dd6
3 changed files with 69 additions and 32 deletions
|
|
@ -87,6 +87,10 @@ extern uint16_t *zbuffer;
|
|||
extern uint8_t *vga;
|
||||
|
||||
/* Prototypes */
|
||||
|
||||
/* Type pour les fonctions de génération de surface : reçoit x, z et renvoie y */
|
||||
typedef fixed (*SurfaceFunc)(fixed x, fixed z);
|
||||
|
||||
void init_engine_math(void);
|
||||
void mat3_identity(Matrix3 *mat);
|
||||
void mat3_rotate_x(Matrix3 *m, int angle);
|
||||
|
|
@ -103,8 +107,10 @@ Object3D* add_sphere (Universe *uni, fixed x, fixed y, fixed z, fixed r,
|
|||
Object3D* add_cylinder (Universe *uni, fixed x, fixed y, fixed z, fixed r, fixed h, int det, uint8_t col, uint8_t wire);
|
||||
Object3D* add_cone (Universe *uni, fixed x, fixed y, fixed z, fixed r, fixed h, int det, uint8_t col, uint8_t wire);
|
||||
Object3D* add_plane (Universe *uni, fixed x, fixed y, fixed z, fixed w, fixed d, int seg_x, int seg_z, uint8_t col, uint8_t wire);
|
||||
Object3D* add_math_surface(Universe *uni, fixed x, fixed y, fixed z, fixed w, fixed d, int seg_x, int seg_z, uint8_t col, uint8_t wire);
|
||||
Object3D* add_torus (Universe *uni, fixed x, fixed y, fixed z, fixed r_main, fixed r_tube, int seg_main, int seg_tube, uint8_t col, uint8_t wire);
|
||||
Object3D* add_math_surface(Universe *uni, fixed x, fixed y, fixed z,
|
||||
fixed w, fixed d, int seg_x, int seg_z,
|
||||
uint8_t col, uint8_t wire, SurfaceFunc func);
|
||||
|
||||
void render_universe(Universe *uni, Camera *cam, int mode);
|
||||
|
||||
|
|
|
|||
|
|
@ -245,7 +245,9 @@ Object3D *add_plane(Universe *uni, fixed x, fixed y, fixed z, fixed w, fixed d,
|
|||
return obj;
|
||||
}
|
||||
|
||||
Object3D *add_math_surface(Universe *uni, fixed x, fixed y, fixed z, fixed w, fixed d, int seg_x, int seg_z, uint8_t col, uint8_t wire) {
|
||||
Object3D *add_math_surface(Universe *uni, fixed x, fixed y, fixed z,
|
||||
fixed w, fixed d, int seg_x, int seg_z,
|
||||
uint8_t col, uint8_t wire, SurfaceFunc func) {
|
||||
int i, j, v_base;
|
||||
Object3D *obj;
|
||||
fixed h_w = w / 2, h_d = d / 2;
|
||||
|
|
@ -256,28 +258,22 @@ Object3D *add_math_surface(Universe *uni, fixed x, fixed y, fixed z, fixed w, fi
|
|||
if (uni->num_verts + (seg_x + 1) * (seg_z + 1) > MAX_VERTEX) return NULL;
|
||||
if (uni->num_faces + seg_x * seg_z * 2 > MAX_FACES) return NULL;
|
||||
|
||||
obj = alloc_object(uni); obj->color = col; v_base = uni->num_verts;
|
||||
step_x = w / seg_x; step_z = d / seg_z;
|
||||
obj = alloc_object(uni);
|
||||
obj->color = col;
|
||||
v_base = uni->num_verts;
|
||||
step_x = w / seg_x;
|
||||
step_z = d / seg_z;
|
||||
|
||||
for (j = 0; j <= seg_z; j++) {
|
||||
for (i = 0; i <= seg_x; i++) {
|
||||
fixed vx = x - h_w + i * step_x;
|
||||
fixed vz = z - h_d + j * step_z;
|
||||
|
||||
/* --- Application de la formule mathématique --- */
|
||||
/* 1. Conversion en flottant pour éviter les débordements avec x*x */
|
||||
double dx = (double)(vx - x) / 65536.0;
|
||||
double dz = (double)(vz - z) / 65536.0;
|
||||
|
||||
/* 2. La formule : Y = Amplitude * sin(Fréquence * sqrt(X^2 + Z^2)) */
|
||||
double dist = sqrt(dx * dx + dz * dz);
|
||||
double fy = 20.0 * sin(dist / 10.0); /* 20.0 = amplitude, 10.0 = étalement */
|
||||
|
||||
uni->verts[uni->num_verts].x = vx;
|
||||
uni->verts[uni->num_verts].y = y + (fixed)(fy * 65536.0);
|
||||
/* Appel de la fonction passée en paramètre pour obtenir la hauteur */
|
||||
uni->verts[uni->num_verts].y = y + func(vx, vz);
|
||||
uni->verts[uni->num_verts].z = vz;
|
||||
|
||||
/* Normale provisoire vers le haut */
|
||||
uni->v_normals[uni->num_verts].x = 0;
|
||||
uni->v_normals[uni->num_verts].y = int_to_f(1);
|
||||
uni->v_normals[uni->num_verts].z = 0;
|
||||
|
|
@ -285,7 +281,6 @@ Object3D *add_math_surface(Universe *uni, fixed x, fixed y, fixed z, fixed w, fi
|
|||
}
|
||||
}
|
||||
|
||||
/* Génération des faces (identique au plan) */
|
||||
for (j = 0; j < seg_z; j++) {
|
||||
for (i = 0; i < seg_x; i++) {
|
||||
int a = v_base + j * (seg_x + 1) + i;
|
||||
|
|
|
|||
Loading…
Reference in a new issue