commit 0e4b832de7141b9996ad638295b7a79a8c635575
parent 1279c65ed70567198a98237457e91319247a1951
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 23 Oct 2015 20:46:00 +0200
Fix Schiff mesh issues
The position of the first vertex was not setup. The dump of the mesh
tried to open the destination file in read only mode. The dumped
mesh indices was not offseted of 1.
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/sbox_schiff_mesh.c b/src/sbox_schiff_mesh.c
@@ -80,8 +80,8 @@ sbox_schiff_mesh_init_sphere
darray_sincos_data_get(&sincos_thetas)[itheta].sinus = sin(theta);
darray_sincos_data_get(&sincos_thetas)[itheta].cosine = cos(theta);
}
- FOR_EACH(iphi, 1, nphis) {
- const double phi = -PI/2 + (double)iphi * step_phi;
+ FOR_EACH(iphi, 0, nphis-1) {
+ const double phi = -PI/2 + (double)(iphi + 1) * step_phi;
darray_sincos_data_get(&sincos_phis)[iphi].sinus = sin(phi);
darray_sincos_data_get(&sincos_phis)[iphi].cosine = cos(phi);
}
@@ -162,7 +162,7 @@ sbox_schiff_mesh_dump(struct sbox_schiff_mesh* mesh, const char* filename)
ASSERT(darray_float_size_get(&mesh->vertices) % 3 == 0); /* 3D */
ASSERT(darray_uint_size_get(&mesh->indices) % 3 == 0); /* Triangles */
- fp = fopen(filename, "r");
+ fp = fopen(filename, "w");
if(!fp) {
res = RES_IO_ERR;
goto error;
@@ -176,10 +176,11 @@ sbox_schiff_mesh_dump(struct sbox_schiff_mesh* mesh, const char* filename)
ntris = darray_uint_size_get(&mesh->indices) / 3;
FOR_EACH(i, 0, ntris) {
+ /* Obj indices start from 1 */
fprintf(fp, "f %u %u %u\n",
- darray_uint_data_get(&mesh->indices)[i*3 + 0],
- darray_uint_data_get(&mesh->indices)[i*3 + 1],
- darray_uint_data_get(&mesh->indices)[i*3 + 2]);
+ darray_uint_data_get(&mesh->indices)[i*3 + 0] + 1,
+ darray_uint_data_get(&mesh->indices)[i*3 + 1] + 1,
+ darray_uint_data_get(&mesh->indices)[i*3 + 2] + 1);
}
exit: