Hello,
Following code:
Triangulator triangulator = new Triangulator();
triangulator.addVertex(new Vector3f(-1.0f, -1.0f, 0.0f));
triangulator.addVertex(new Vector3f( 1.0f, -1.0f, 0.0f));
triangulator.addVertex(new Vector3f(-1.0f, 1.0f, 0.0f));
triangulator.addVertex(new Vector3f( 1.0f, 1.0f, 0.0f));
triangulator.addEdge(0,1);
triangulator.addEdge(1,2);
triangulator.addEdge(2,3);
triangulator.addEdge(3,0);
IntBuffer intBuf = triangulator.triangulate();
Gives me
WARNING: We could find no left of {(real )2(-1.0,1.0)->3:(1.0,1.0),Helper:null,angle:0.0}: -1.0
Exception in thread "main" java.util.NoSuchElementException
What am I doing wrong?
Thanks.
I think your vertex order is wrong, it should be counterclockwise, right?
right now you do:
3 4
1 2
if you switch the 3rd and 4th vertex you will get:
4 3
1 2
Thanks,
That worked,
I actually need to triangulate arbitrary ngon, how should I order the vertices in this case?
hmm no clue, i don't know much about manually created geoms
The ordering should ALWAYS be the same (counter-clockwise in this case), the order of the points tells opengl which is the 'front' face of a polygon. But they do need to be in order, your first rotation wasn't actual a complete, correction rotation.