Skip to content

Commit 7a2e32d

Browse files
author
Eric Sartre
committed
fixed bug : invalid mesh generating
1 parent 008c7b7 commit 7a2e32d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

solid.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,32 @@ bool make_face(const vertex_id* restrict a, const vertex_id* restrict b,
6868
return true;
6969
}
7070

71-
shape_t *new_revolution(const shape_t *standard, const unsigned m, const unsigned n)
71+
shape_t *new_revolution(const shape_t *standard, const unsigned m)
7272
{
7373
shape_t *ret = new_shape();
7474
shape_t *prev = new_shape();
75-
for(unsigned i = 0; i < n+1; ++i) {
75+
const unsigned n = standard->num_vertices;
76+
for(unsigned i = 0; i < n; ++i) {
7677
const vertex_id v = standard->vertices[i];
7778
add_vertex(prev, v);
7879
add_vertex(ret, v);
7980
}
8081
for(unsigned rot = 1; rot < m; ++rot) {
8182
shape_t *current = new_shape();
8283
const double theta = rot * (2 * M_PI / m);
83-
for(unsigned i = 0; i < n+1; ++i) {
84+
for(unsigned i = 0; i < n; ++i) {
8485
const vertex_t vs = get_point(standard->vertices[i]);
8586
const double x = vs.x * cos(theta);
8687
const double z = vs.x * sin(theta);
8788
const vertex_id v = new_vertex(x, vs.y, z);
8889
add_vertex(current, v);
8990
add_vertex(ret, v);
9091
}
91-
make_face(prev->vertices, current->vertices, n+1);
92+
make_face(prev->vertices, current->vertices, n);
9293
free_shape(prev);
9394
prev = current;
9495
}
95-
make_face(prev->vertices, standard->vertices, n+1);
96+
make_face(prev->vertices, standard->vertices, n);
9697
free_shape(prev);
9798
return ret;
9899
}
@@ -130,7 +131,7 @@ shape_t *new_cylinder(const double r, const double height, const unsigned m, con
130131
for(unsigned i = 0; i < rn+1; ++i) {
131132
add_vertex(standard, new_vertex(r - i * r / rn, height / 2, 0));
132133
}
133-
shape_t *ret = new_revolution(standard, m, 2*rn+hn+2);
134+
shape_t *ret = new_revolution(standard, m);
134135
free_shape(standard);
135136
return ret;
136137
}
@@ -144,7 +145,7 @@ shape_t *new_taurus(const double offset, const double r,
144145
const vertex_id v = new_vertex(r * cos(theta) + offset, r * sin(theta), 0);
145146
add_vertex(standard, v);
146147
}
147-
shape_t *ret = new_revolution(standard, m, n);
148+
shape_t *ret = new_revolution(standard, m);
148149
free_shape(standard);
149150
return ret;
150151
}
@@ -157,7 +158,7 @@ shape_t *new_sphere(const double r, const unsigned m, const unsigned n)
157158
const vertex_id v = new_vertex(r * cos(theta), r * sin(theta), 0);
158159
add_vertex(standard, v);
159160
}
160-
shape_t *ret = new_revolution(standard, m, n);
161+
shape_t *ret = new_revolution(standard, m);
161162
free_shape(standard);
162163
return ret;
163164
}

solid.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool make_face(const vertex_id* restrict a, const vertex_id* restrict b,
2424
const unsigned len);
2525

2626

27-
shape_t *new_revolution(const shape_t *standard, const unsigned m, const unsigned n);
27+
shape_t *new_revolution(const shape_t *standard, const unsigned m);
2828
shape_t *new_cone(const double r, const double height, const unsigned m);
2929
shape_t *new_cylinder(const double r, const double height,
3030
const unsigned m, const unsigned rn, const unsigned hn);

0 commit comments

Comments
 (0)