parametrage de math_surf

This commit is contained in:
Frater 2026-05-10 13:37:52 +02:00
commit b1c8be9dd6
3 changed files with 69 additions and 32 deletions

View file

@ -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;