Ear Clipping Triangulation Algorithm

  ... information about changes and new features of AndEngine,

Re: Ear Clipping Triangulation Algorithm

Postby K2DaC » Sat Sep 18, 2010 5:48 am

only real clones with the same gamebasics can be removed because of the Lanham Act.
have Blocks - yes
Stack them - yes
remove full lines - no

so there should be no problem :)
K2DaC
 
Posts: 16
Joined: Sat Sep 11, 2010 6:40 am
Location: Berlin, Germany

Re: Ear Clipping Triangulation Algorithm

Postby kplese » Mon Oct 11, 2010 9:05 pm

Hi! Can someone post the usage sample? I've been playing with the triangulation but without success...
kplese
 
Posts: 9
Joined: Mon Sep 27, 2010 11:19 am
Location: Zagreb, Croatia

Re: Ear Clipping Triangulation Algorithm

Postby andryang » Wed Oct 13, 2010 11:19 am

Nicolas Gramlich wrote:Hi,

Changeset: http://code.google.com/p/andenginephysi ... 88fbc18c2d

Actual class: http://code.google.com/p/andenginephysi ... lator.java

Pretty useful once a Vector2[] has been triangulated: PhysicsFactory.createTrianglulatedBody(...)

Summing up, the usage looks somewhat similar to this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final List<Vector2> vertices = new ArrayList<Vector2>(); // Add some vertices here!
  2. final ITriangulationAlgoritm triangulationAlgoritm = new EarClippingTriangulator();
  3. final List<Vector2> triangles = triangulationAlgoritm.computeTriangles(vertices);
  4.                        
  5. final Body body = PhysicsFactory.createTrianglulatedBody(pPhysicsWorld, pShape, triangles, pBodyType, pFixtureDef);
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


Hope this helps :)

Bugs might be included :P and the API might change slightly in future releases :)

Best Regards,
Nicolas


Hello Nicolas, Can you give me the code of this polygons or give me some examples on how to use this . rnoldo@gmail.com
thanks you very much
andryang
 
Posts: 3
Joined: Wed Oct 13, 2010 10:55 am

Re: Ear Clipping Triangulation Algorithm

Postby Radzell » Fri Oct 22, 2010 9:05 am

Are the vertices you input localized or are they based on the shapes placement in the world.
Radzell
 
Posts: 465
Joined: Sun Jul 04, 2010 8:52 am

Re: Ear Clipping Triangulation Algorithm

Postby ichi » Mon Oct 25, 2010 6:26 pm

Radzell wrote:Are the vertices you input localized or are they based on the shapes placement in the world.

The vertex input data are localized and relative to the center point of the shape you provide. The vertex positions are also set by changing the position of the provided shape.
ichi
 
Posts: 62
Joined: Mon Sep 06, 2010 1:47 pm

Re: Ear Clipping Triangulation Algorithm

Postby cannehal » Tue Oct 26, 2010 11:23 am

Hi

I am using your triangulation algorithm to create triangles from polygon. But my polygon is dynamic (it grows by adding vertex points to it; vertex points are user generated). I've got this situation when my polygon has only 3 vertices. I've found that your code is returning list of vertices when you have 3 or less vertices and does nothing more. But when vertices aren't in clockwise order triangle isn't drawn.

Code for computeTriangles looks like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public List<Vector2> computeTriangles(final List<Vector2> pVertices) {
  3.                 // TODO Check if LinkedList performs better
  4.                 final ArrayList<Vector2> triangles = new ArrayList<Vector2>();
  5.                 final ArrayList<Vector2> vertices = new ArrayList<Vector2>(pVertices.size());
  6.                 vertices.addAll(pVertices);
  7.  
  8.                 if(vertices.size() == 3) {
  9.                         triangles.addAll(vertices);
  10.                         return triangles;
  11.                 }
  12.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


I think you should add checking for clockwise order also to condition when you return plain list (vertices.size() == 3)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public List<Vector2> computeTriangles(final List<Vector2> pVertices) {
  3.                 // TODO Check if LinkedList performs better
  4.                 final ArrayList<Vector2> triangles = new ArrayList<Vector2>();
  5.                 final ArrayList<Vector2> vertices = new ArrayList<Vector2>(pVertices.size());
  6.                 vertices.addAll(pVertices);
  7.  
  8.                 if(vertices.size() == 3) {
  9.                         /* Ensure vertices are in clockwise order. */
  10.                         if(!EarClippingTriangulator2.areVerticesClockwise(vertices)) {
  11.                                 Collections.reverse(vertices);
  12.                         }
  13.                         triangles.addAll(vertices);
  14.                         return triangles;
  15.                 }
  16.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Best regards
cannehal
 
Posts: 1
Joined: Mon Oct 25, 2010 8:41 am

Re: Ear Clipping Triangulation Algorithm

Postby palmboy5 » Sun Oct 09, 2011 7:00 am

Nicolas, if you happen to still have the code for your tetris piece example, could you post that please?

Otherwise, I've been trying to use triangulation with little success. I'm pretty much adding the following code into onLoadScene() for PhysicsExample.java just to see if it works but the resulting piece is just a grey rectangle and immediately starts sliding up-left off the screen.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. float halfWidth = 300;
  2. float halfHeight = 200;
  3.  
  4. float top = -halfHeight;
  5. float bottom = halfHeight;
  6. float left1 = -halfWidth;
  7. float right1 = halfWidth;
  8. float centerY = 0;
  9. float thirdFromLeft = (-halfWidth) / 3;
  10. float thirdFromRight = (halfWidth) / 3;
  11.  
  12. List<Vector2> blah = new ArrayList<Vector2>();
  13. blah.add(new Vector2(thirdFromLeft, top));
  14. blah.add(new Vector2(right1, top));
  15. blah.add(new Vector2(right1, centerY));
  16. blah.add(new Vector2(thirdFromRight, centerY));
  17. blah.add(new Vector2(thirdFromRight, bottom));
  18. blah.add(new Vector2(left1, bottom));
  19. blah.add(new Vector2(left1, centerY));
  20. blah.add(new Vector2(thirdFromLeft, centerY));
  21.  
  22. ITriangulationAlgoritm tri = new EarClippingTriangulator();
  23. List<Vector2> triangles = tri.computeTriangles(blah);
  24.  
  25. Sprite blah2 = new Sprite(200, 200, this.tSFaceTextureRegion);
  26. Body blah3 = PhysicsFactory.createTrianglulatedBody(this.mPhysicsWorld, blah2, triangles, BodyType.DynamicBody, FIXTURE_DEF);
  27. this.mScene.attachChild(blah2);
  28. this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(blah2, blah3, true, true));
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


I'm betting the texture isn't set up right either, not sure how to properly texture such a body... :oops: Here is the code for loading the .png, which is also attached to this post.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.mBitmapTextureAtlasTetris = new BitmapTextureAtlas(128, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  2.  
  3. this.tSFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlasTetris, this, "face_s_plain.png", 0, 0);
Parsed in 0.044 seconds, using GeSHi 1.0.8.4


I must be doing something wrong... If anyone can help point me in the right direction, that would be awesome!
Attachments
face_s_plain.png
face_s_plain.png (2.84 KiB) Viewed 1135 times
palmboy5
 
Posts: 2
Joined: Sat May 21, 2011 7:41 am

Previous

Return to Updates

Who is online

Users browsing this forum: No registered users and 3 guests