Box2D Forums

It is currently Thu May 23, 2013 5:08 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: PolygonShape not precise
PostPosted: Wed Apr 18, 2012 12:12 pm 
Offline

Joined: Wed Apr 18, 2012 11:55 am
Posts: 4
Hey,
I'm starting with Box2d in Flash. Is there an option to get collisions directly with a movieClip or bitmap? I found no example. So I tried to programm a Class witch transforms movieClips directly while the runtime to a PolygonShape. It works fine, but the collision is extremly unprecise and other shapes "digging" through. What's the reason?
Example
Thanks for Tipps.
Best regards.
Clemi


Top
 Profile  
 
PostPosted: Wed Apr 18, 2012 12:41 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
Is this a single polygon? It's not a convex shape, so you would need to make it up from smaller convex polygons.
You could also use a chain/loop shape if it's enough just to have the outline of the shape.


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 5:12 am 
Offline

Joined: Wed Apr 18, 2012 11:55 am
Posts: 4
Thank you for your hints. I changed my Landscape-Generation-Class to create seperated, smaller, convex polygons, but the Circle-Shapes already "digging" through the surface:
Example

Did I use the wrong paramters?

Ball/Charakter (Circle-Shapes):
Code:
         fixtureDef.density = 1;
         fixtureDef.friction = 0.1;
         fixtureDef.restitution = 0.1;
         fixtureDef.filter.categoryBits = 1;
         fixtureDef.filter.maskBits = 65535;
         fixtureDef.filter.groupIndex = 1;


Landscape (Polygon-Shape):
Code:
         fixtureDef.density = 2;
         fixtureDef.friction = 1;
         fixtureDef.restitution = 0.2;
         fixtureDef.filter.categoryBits = 1;
         fixtureDef.filter.maskBits = 65535;
         fixtureDef.filter.groupIndex = 1;


I will be glad for further hints.
Thank you very much.
Clemi


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 6:39 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
The fixture settings look fine. Are the polygon vertices given in counter-clockwise order?


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 7:22 am 
Offline

Joined: Wed Apr 18, 2012 11:55 am
Posts: 4
I tried it in both directions. If I make it in CCW order, the "hill" is also out of "quicksand" :D
Is there perhaps an other criteria (start with the lowest/highest point, or something else)?
Thank you,
Clemi


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 7:46 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
So in one case the hill part is ok (as it seems in the swf) and the flat part is bad, and if you reverse the winding these are the other way around? Are you sure you are getting the windings right for both areas?
Also, the circles do not seems to be colliding correctly, but maybe you have intentionally set it to be like that?
Is this showing the output from Box2D's debug draw?


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 10:14 am 
Offline

Joined: Wed Apr 18, 2012 11:55 am
Posts: 4
Thank you sort your fast response. In the reverse chicle the flat part is also like quicksand. And correct: it shows the debug draw :( I will try and test other forms to understand the problem. So stay interested :D Thanks a lot. Clemi


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 3:48 pm 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
The flat (horizontal) parts are the only places the circles go weird and have that quicksand effect. The circles collide fine with the angled parts. How are you making the polygon shapes? There may be something that's making some parts in a weird way that would create that quicksand effect.


Top
 Profile  
 
PostPosted: Sun Apr 29, 2012 8:25 am 
Offline

Joined: Sun Apr 29, 2012 8:19 am
Posts: 1
OK, i was wrong with my guess.

But i have similar question. I want to make compound object from rectangle, circle and triangle. But i have problem illustrated on this picture. Is it possible to make this working?

Image

I only added this code to original source to make a test.

Code:
circ.radius = 20 / m_physScale;
circ.density = 0.0;
circ.friction = 0.4;
circ.restitution = 0.3;
bd = new b2BodyDef();
bd.position.Set(2*((10*j) / m_physScale), (160 + 20*j) / m_physScale);
head = m_world.CreateBody(bd);
head.CreateShape(circ);
head.SetMassFromShapes();
box.density = 0.0;
box.friction = 0.4;
box.restitution = 0.3;
box.vertexCount = 3;
box.vertices[0].Set(0, 0);
z = Math.sqrt(2*Math.pow(20,2))/(2*m_physScale);
box.vertices[1].Set(z, 0);
box.vertices[2].Set(0,-z);
bd = new b2BodyDef();
bd.position.Set(2*((10*j) / m_physScale) + z, (160 + 20*j) / m_physScale);
head = m_world.CreateBody(bd);
head.CreateShape(box);
head.SetMassFromShapes();


Oops, it works fine when i draw triangle clockwise.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group