Starting to use poly2tri

236 views
Skip to first unread message

Ardo Avancena

unread,
Feb 25, 2014, 5:38:05 PM2/25/14
to poly...@googlegroups.com
I haven't successfully used poly2tri and little by little it has been progressing.

Now I'm trying to initialize CDT but whenever I do, I get this error message:

Undefined symbols for architecture x86_64:
"p2t::CDT::CDT(std::vector<p2t::Point*, std::allocator<p2t::Point*> >)", referenced from:...

clang error: linker command failed with exit code 1 (use -v to see invocation)


I'm using xcode to build this.

I also tried using the namespaces of p2t and std, but I still get a similar error.


On a side note: My goal on using the library is to "shatter" a square. Through this library, will I be able to control the triangulated pieces? Or separate them?

Thanks!!

obi

unread,
Feb 25, 2014, 8:29:14 PM2/25/14
to poly...@googlegroups.com
Sorry I can't help you on the compiling side since I just work with Java.

Yes poly2tri should work well to shatter polygons.
If i wanted to shatter a square I would:
1. Determine the point of impact on the square
2. Subdivide the square edges a few times close the the impact point.
3. Add this polygon to poly2tri and add a few steiner points in some pattern around the impact point but still inside the square polygon. 
   - Having a higher density of steiner points the closer you get to the impact point will give a more natural shatter pattern.
4. Triangulate and smile :)

Ardo Avancena

unread,
Feb 26, 2014, 5:58:07 PM2/26/14
to poly...@googlegroups.com
I see, I haven't gone past my problem still, but I was wondering how would I be able to map a texture, and retain the shard's texture while it is being separated.

obi

unread,
Feb 26, 2014, 6:20:02 PM2/26/14
to poly...@googlegroups.com
Thats pretty simple. 

If you start of with a 4 point square, each point will have a xyz coordinate and a texture coordinate (uv) (0-1).
Lets say the bottom left vertex is 0,0,0 and has texture coordinate 0,0 and top right vertex has 1,1,1 and texture coordinate 1,1.
If you subdivide edges and add interior points their xyz coordinates will be between 0 and 1 so their texture coordinates will be the same.
e.g. if you add a point in the middle 0.5,0.5,0 the tc will be 0.5,0.5.

So when you render the triangles with given ccordinates and tc's the shards will retain the correct texture.

ofc. in the real world your squares will have other coordinates then 0,0,0 and 1,1,1 and even other texCoords in the corners. But knowing the coordinates and texCoords in the square
corners you can easily compute the texture coordinates for any point in the square.

obi

unread,
Feb 26, 2014, 6:21:25 PM2/26/14
to poly...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages