Skip to main content
GameDev.net gamedev.net
🔒 Locked

Generating 2d mesh - triangle mesh

Started by prezaKG Feb 27, 2011 at 5:54 PM 2 replies 1.7k views
Original Post
prezaKG
prezaKG
I need idea for c++ algorithm which can generate 2d mesh within polygon like this one:

28tc30m.jpg
or this one:
vrgim9.jpg

Mesh should look like this (or something similar) - it should consist of triangles:
nxjmvk.jpg

Any idea is there already algorithm that can do this? Or what should I look in google to find solution?

Thanks!
EricTheRed
EricTheRed
What you want to do is called "triangulation". One of the simpler methods (though not the most efficient) is called "ear clipping". Try searching for those terms and you should find what you need.
prezaKG
prezaKG
Thanks!
I'll look for those terms and see what will came up.
prezaKG
prezaKG
Hi again.

I have found rather simple solution here:

http://codesupposito...r-clipping.html

but i'm a little bit rusty in C++

here is my code:


Triangulator *t = createTriangulator();
t->addPoint(0.0, 0.0, 0.0);
t->addPoint(0.0, 10.0, 0.0);
t->addPoint(10.0, 20.0, 0.0);
t->addPoint(12.0, 15.0, 0.0);
t->addPoint(20.0, 20.0, 0.0);
t->addPoint(10.0, 10.0, 0.0);
t->addPoint(10.0, 0.0, 0.0);
unsigned int tcount;
unsigned int *indices = t->triangulate(tcount);

printf("%d\n ", tcount)

FILE *p_tri;
p_tri = fopen("000.stl", "w");
fprintf(p_tri,"solid STL\n");
fprintf(p_tri," facet normal 0.000000e+000 0.000000e+000 -1.000000e+000\n");
fprintf(p_tri," outer loop\n");

fprintf(p_tri," endloop\n");
fprintf(p_tri," endfacet\n");
}
fprintf(p_tri,"endsolid STL");
fclose(p_tri);


releaseTriangulator(t);



tcount is always 0.....it should return number of generated triangles...

I'm stuck...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.