commit cdc462d2ec155cfdaccb86bd5036ea912c463026
parent 93708e54e5cf9281f263036e3df594f49556ad80
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 24 Jul 2019 14:49:00 +0200
Update how the mesh cdf is computed
The mesh cdf was not normalized and corresponded to the cumulative of the
area of the triangles *multiplied by 2*. Actually, we do not multiplied
these areas by two but we directly obtained 2 times the triangle area by
computing the norm of the cross product of 2 triangle edges. We thus
simply avoided a multiplication by 0.5 that seemed useless.
However, "premature optimization is the root of all evil". Indeed, this
cdf can be completed with additionnal shapes that are not meshes, and
whose their own cumulative is computed from the area of their
primitives, not 2 times the area of these primitives. The resulting
cumulative was thus simply wrong.
This commit fixes this issue. The mesh cdf is still unnormalized but
is now computed from the area of each triangle.
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/s3d_mesh.c b/src/s3d_mesh.c
@@ -373,7 +373,7 @@ mesh_compute_cdf(struct mesh* mesh)
if(res != RES_OK) goto error;
FOR_EACH(itri, 0, ntris) {
- area += mesh_compute_triangle_2area(mesh, itri);
+ area += mesh_compute_triangle_2area(mesh, itri) * 0.5f;
darray_float_data_get(&mesh->cdf)[itri] = area;
}
exit: