Box2D Forums

It is currently Thu Sep 02, 2010 3:47 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 110 posts ]  Go to page 1, 2, 3, 4, 5 ... 11  Next
Author Message
 Post subject: EdgeShapes (aka Thin Line Segments)
PostPosted: Sun Sep 14, 2008 12:01 pm 
Offline

Joined: Sun Jan 20, 2008 7:52 pm
Posts: 434
EDIT: The post below is outdated. EdgeShapes are now merged into the main Box2DFlash SVN repository. Get them from there:
http://sourceforge.net/scm/?type=svn&group_id=210232
The new EdgeShapes are a direct port of the version I made for C++:
viewtopic.php?f=3&t=1577&hilit=edgeshapes



OLD POST:

DEMO!

I have (re)implemented shapes composed of infinitely-thin line segments in Box2D. I've decided to call my implementation "Static Edges".

This is a beta. The API is subject to change. A C++ port is possible, eventually, though whether or not it will be integrated into the main branch of Box2D is still uncertain, and this branch will be updated at my whim. :) However, I welcome bug reports and feedback.

The way you create Static Edges differs from the norm. You start by creating a definition of a "chain" of connected edges:
Code:
var chainDef: b2StaticEdgeChainDef = new b2StaticEdgeChainDef();
chainDef.vertexCount = 3;
chainDef.vertices.push(new b2Vec2(x1,y1));
chainDef.vertices.push(new b2Vec2(x2,y2));
chainDef.vertices.push(new b2Vec2(x3,y3));
chainDef.isALoop = true; // connect the first and last vertices
Line Segments are only allowed to be static. So you can only attach them to the ground body:
Code:
world.CreateGroundShape(chainDef);
In this example, this one function call will create 3 line segments, each of type "b2StaticEdgeShape", and it will return one object of type "b2StaticEdgeChain".

Static Edges have an "inside" and an "outside". Which is which depends on your coordinate system. If up is positive on the Y axis, floors go from right to left, and ceilings go from left to right. If up is negative, floors go from left to right and ceilings go from right to left. This is consistent with the vertex order of Polygons.

As a bonus, you can find a super-barebones SVG parser in TestBed/TestEdges.as, so that you can draw paths in Inkscape and import them into Box2D. Inkscape was my level editor for Planet of the Forklift Kid.


Attachments:
File comment: Update 2
Box2DAS3_staticEdges.zip [219.42 KiB]
Downloaded 576 times


Last edited by shaktool on Mon Mar 30, 2009 2:21 pm, edited 5 times in total.
Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Sun Sep 14, 2008 1:26 pm 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1908
Ohmigod, that is sweet. And you've done an SVG parser too, I was considering that, though less with the XML, and more with the robust path parsing. Damn, now I need adapt b2ConcaveArc into a thin version, too.

You say the lines are "one-sided". They seem to let stuff through the other way, but with "popping". Is that intentional/usable, or did you just mean they are intended to be used a particular way around to do convexity test etc.


Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Sun Sep 14, 2008 9:05 pm 
Offline

Joined: Sun Jan 20, 2008 7:52 pm
Posts: 434
This is actually based on your concave arc code, mostly because it sort of laid the foundation for adding new types of shapes. Thank you! The concave arcs are still in there, though they do not collide with static edges. If you make any updates to your concave arcs or the SVG parser, I'll offer to merge them in with any of my updates to the static edges, but I do not offer to write collision detection between the two. :P I'm assuming they'll both be used as static level geometry most of the time anyway.


Last edited by shaktool on Tue Sep 16, 2008 9:21 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Tue Sep 16, 2008 4:34 pm 
Offline

Joined: Sun Aug 03, 2008 9:09 am
Posts: 8
The only problem is that the physics solver seems to "push" an object as it penetrates the shape.

This is was what I was looking for


Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Tue Sep 16, 2008 4:41 pm 
Offline

Joined: Sun Jan 20, 2008 7:52 pm
Posts: 434
Are you referring to when objects approach a Static Edge from the "wrong" side? If so, what is the behavior you would expect in this situation? Do you want it to collide with the "wrong" side just like it collides with the "right" side, or do you want it to pass through freely instead of being forced through?


Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Tue Sep 16, 2008 4:44 pm 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1908
shaktool wrote:
it to pass through freely instead of being forced through?

That would be best in my books, but I after seeing that Tinger game, I'm no longer concerned as it seems pretty easy to do with filters instead, and would rather what ever gives the best performance, which is probably what you have at the moment.


Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Tue Sep 16, 2008 5:05 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 493
shaktool wrote:
do you want it to pass through freely instead of being forced through?

Yes! I got all excited about this until I realized that this is not the case.

Just wondering... is there any advantage to using this (besides easier authoring) over building static level shapes out of a bunch of polygons or even thin rectangles? Is it better performance-wise?


Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Tue Sep 16, 2008 5:24 pm 
Offline

Joined: Sun Jan 20, 2008 7:52 pm
Posts: 434
One advantage these lines have over polygons already is that this will never happen:
viewtopic.php?f=3&t=906

I have not yet attempted to compare their performance, though theoretically my static edges should be faster in many cases, as they are simpler to evaluate for contacts. However, they result in separate AABBs for each edge. If you have a large shape whose AABB overlaps the AABBs of eight static edges with convex corners all at once, it would be faster to use one static polygon with eight sides, resulting in one contact test with a polygon instead of eight contact tests with static edges.


Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Wed Sep 17, 2008 7:09 am 
Offline

Joined: Sun Sep 14, 2008 2:47 am
Posts: 12
shaktool wrote:
This is actually based on your concave arc code, mostly because it sort of laid the foundation for adding new types of shapes. Thank you! The concave arcs are still in there, though they do not collide with static edges. If you make any updates to your concave arcs or the SVG parser, I'll offer to merge them in with any of my updates to the static edges, but I do not offer to write collision detection between the two. :P I'm assuming they'll both be used as static level geometry most of the time anyway.



Thx both of you for the great additions ot box2d as3.

Do you mean that we can already define a concave arc line within the thin line segment shape ?


Top
 Profile  
 
 Post subject: Re: Thin Line Segment Shapes (beta)
PostPosted: Wed Sep 17, 2008 10:34 am 
Offline

Joined: Sun Jan 20, 2008 7:52 pm
Posts: 434
If you download the code attached to my first post, you'll get a version of Box2DAS3 that contains both b2ConcaveArcShapes and b2StaticEdgeShapes. They are separate, unrelated shapes, and they will never collide with each other, but you can use them both as static level geometry.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 110 posts ]  Go to page 1, 2, 3, 4, 5 ... 11  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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 © 2000, 2002, 2005, 2007 phpBB Group