Originally posted by Overmind:
[b]I’m not sure what you mean by the vertices must be shared. If you rotate n 2d vertices using m segments, you’ll get n*m vertices (assuming you already share the 0 and 360 degree vertices). There is no way around this…
At best you can reduce this by sharing vertices that have a radius of 0 and a normal vector parallel to the rotation axis, but for any but the most obscure special cases, this will be the case at most two times (at the top and bottom of the model), so you will save 2*m-2 vertices at best, and that’s not really going to improve performance…[/b]
I mean that each polygon points to the vertices it uses. Hence, mulitple polygons may be sharing the same points. And regarding efficiency, I mean that there are no two vertices in the list which occupy the same position.
Right now I’ve got a method for creating new vertices:
Vertex *AddVertex(Vertex *v);
which iterates through the list of vertices comparing the coordinates. If a vertex already exists in the list, that vertex is returned. Otherwise, the new vertex, v, is added to the end and returned. This way the calling function can be sure that the vertex it just created is unique and this works great for the non-lathed primitives (eg. cubes etc).
I can’t do this with the lathe because the for-loop which adds the polygons calcuates the index numbers of the vertices to use based on the number of vertices in the profile and the number of lathe-steps. The vertices are simply added to the end of the list. If I used AddVertex() as above, a lot of these vertices would not exist (as they are duplicates).
It seems I have 2 options:
- Make the polygon-generating code smarter so that it can redirect the polys to the actual vertices it needs, rather than just assuming they exist.
- Search the list afterwards and combine the duplicates. This is difficult because it means that for every duplicate removed, you have to find the associated polygon and redirect it to the original vertex. This implies that each vertex must maintain a list of adjacent polygons. So we have more lists, and more potential duplicates.
It’s a mess!