Just wanted to say thanks for this, have used them in my new game and works great. Only feature I'd maybe ask for is the ability to toggle a flag to change the direction of which the shapes allow collisions (I built a large playing area, tested it and then all sprites could leave the playing area, then not get back into it... then i reread this thread and found I just had to reverse the definition of my points).. Not really a big problem and I think its great without this additional toggle option.
EdgeShapes (aka Thin Line Segments)
FlashHey...
So the way I understand it, one of these chains of edges can actually be concave? 😐
You better not make me rewrite all my code 😛, I used to make hills by tessellating the whole landscape, to remove concavities.
What would you say performance-wise... Would an implementation using these edges be faster than polygon-"blocks" for a hilly landscape?
So the way I understand it, one of these chains of edges can actually be concave? 😐
You better not make me rewrite all my code 😛, I used to make hills by tessellating the whole landscape, to remove concavities.
What would you say performance-wise... Would an implementation using these edges be faster than polygon-"blocks" for a hilly landscape?
Yep, the chains can be concave. That's kinda the whole point. 😉
I imagine this would be faster than tessellated polygons in most cases. Don't worry about it unless you find that Box2D is a bottleneck in your update code, though I hope that using the chains would prove to be a quick, simple change.
I imagine this would be faster than tessellated polygons in most cases. Don't worry about it unless you find that Box2D is a bottleneck in your update code, though I hope that using the chains would prove to be a quick, simple change.
It's sour...
Tessellating the terrain polygons to create destructible terrain was my pride 😛. But this is like easymode 😀.
It seems to be more robust too, sometimes, on the terrain, when tessellation gave very thin polygons, objects would still fall halfway through.
Alas, I have no choice.. If the performance really is better, I might even get a higher resolution on my terrain heightmap.
I'll go for it!
[edit] oh actually, one more question.
Do these generate any anomalies when I destroy them and create them again in the exact same place? (When I have to redraw the terrain because there's a crater in it? Or do they basically behave like normal polygons? [/edit]
Tessellating the terrain polygons to create destructible terrain was my pride 😛. But this is like easymode 😀.
It seems to be more robust too, sometimes, on the terrain, when tessellation gave very thin polygons, objects would still fall halfway through.
Alas, I have no choice.. If the performance really is better, I might even get a higher resolution on my terrain heightmap.
I'll go for it!
[edit] oh actually, one more question.
Do these generate any anomalies when I destroy them and create them again in the exact same place? (When I have to redraw the terrain because there's a crater in it? Or do they basically behave like normal polygons? [/edit]
Don't feel too bad, android. Thin lines like this are exceedingly easy to use, but they do only work for static shapes. I'm personally worried that this will kill development on tessellation, which would be a shame.
Hahaha, thanks 🙂
Are these line segments intrinsically static?
I guess you're right, there is still tessellation for dynamic objects. What kind of work is being done on tessellation? And what kind of results are needed?
Are these line segments intrinsically static?
I guess you're right, there is still tessellation for dynamic objects. What kind of work is being done on tessellation? And what kind of results are needed?
Quote:
Do these generate any anomalies when I destroy them and create them again in the exact same place?
The only thing to be cautious of is the core vertices used to calculate time-of-impact against fast-moving dynamic objects. Turn on core display in the debug draw in the testbed to see what the core vertices are like for static edge chains. The code that turns a chain definition into a series of static edges takes into account the relative angles between the edges to determine where to put the core vertices. That's why I even bothered with the chain thing, instead of forcing you to create one edge at a time, like you do with circles and polygons. At the extremities of chains that are not looping, my algorithm with simply guess at what the angle is between the edge at the extremity, and any adjacent edge that might exist in the world. This guess is less robust... HOWEVER it should be reasonable for all concave angles and also all convex angles that are less than 135 degree turns. And even if you have a sharp convex corner, the worst case scenario is that objects will stutter as they slide past the corner.
If you destroy and recreate the entire landscape whenever you change it, that would also solve the problem, though it may not be worth it.
Quote:
Are these line segments intrinsically static?
Forcing them to be static and one-sided removes a lot of ambiguity and complexity from the problem, and allows me to make something more robust. (and faster!) In particular, deep collisions between two dynamic edge chains would be a mess to try to resolve.Hey,
I got to work on implementing my terrain with the static edges, but I have the following problem.
My game engine relies (heavily) on assigning userData objects to all bodies, the userData objects are always "Actor" objects, and these "Actors" then receive the collision events, so they can explode, take damage, or whatever needs to be done. (Actor subclasses into enemies, terrain, basically every existing object in the game world).
It seems though that all static edges in the whole world would be part of the same body? This leads to the problem that in my engine, I cannot find out what actor a certain chain belongs to, and I cannot apply the explosion to the appropriate section of terrain.
I got to work on implementing my terrain with the static edges, but I have the following problem.
My game engine relies (heavily) on assigning userData objects to all bodies, the userData objects are always "Actor" objects, and these "Actors" then receive the collision events, so they can explode, take damage, or whatever needs to be done. (Actor subclasses into enemies, terrain, basically every existing object in the game world).
It seems though that all static edges in the whole world would be part of the same body? This leads to the problem that in my engine, I cannot find out what actor a certain chain belongs to, and I cannot apply the explosion to the appropriate section of terrain.
Can you test if shapes have userData before resorting to the body's userData for everything else? If you only are using the userData in contact listener reports, I imagine this would be the best solution.
If there are other places where your code expects bodies to have unique userData, you will have to modify the b2StaticEdgeChain constructor to accept an additional parameter for a body:
Don't forget that world.CreateGroundShape() returns a b2StaticEdgeChain which contains an array of all of the b2StaticEdgeShapes that were created. You can modify them individually from there. (If the chain is a loop, the edge connecting the first and last vertices will be the first edge in the array, the rest should be in the sequence you specified.)
Sorry about all this. I figured it wouldn't be a problem because there's usually nothing you can do with body.userData that you can't do with shape.userData.
If there are other places where your code expects bodies to have unique userData, you will have to modify the b2StaticEdgeChain constructor to accept an additional parameter for a body:
Code:
public function b2StaticEdgeChain(def:b2ShapeDef, world: b2World, body: b2Body){
And then replace all references to world.m_groundBody inside the constructor with the new body parameter. Then you can skip the call to world.CreateGroundShape and construct the static edges directly like this:Code:
new b2StaticEdgeChain(chainDef, world, myBody);
Don't forget that world.CreateGroundShape() returns a b2StaticEdgeChain which contains an array of all of the b2StaticEdgeShapes that were created. You can modify them individually from there. (If the chain is a loop, the edge connecting the first and last vertices will be the first edge in the array, the rest should be in the sequence you specified.)
Sorry about all this. I figured it wouldn't be a problem because there's usually nothing you can do with body.userData that you can't do with shape.userData.
No need to apologize! I'm actually excited I get to play with this 🙂. Maybe I should have implemented the contact listener so it listens to shape.userData instead, from the beginning.. I hadn't given it much thought at the time.
And the idea of checking whether the shape has a userData attached to it is actually quite a good idea! 🙂. Unfortunately, when actors collide, they sometimes get a rough position of each other, by getting the world position of the other body. (other.body.GetPosition()). Every Actor in the engine is expected to have a body object. Though I don't think any Actor ever asks for the position of a piece of Terrain, so it probably wouldn't be a problem if all Terrains had the groundbody as their body.
But you are saying that the static edges could just as well be part of a normal static body? With a slightly different constructor? That would probably be the better solution.
And the idea of checking whether the shape has a userData attached to it is actually quite a good idea! 🙂. Unfortunately, when actors collide, they sometimes get a rough position of each other, by getting the world position of the other body. (other.body.GetPosition()). Every Actor in the engine is expected to have a body object. Though I don't think any Actor ever asks for the position of a piece of Terrain, so it probably wouldn't be a problem if all Terrains had the groundbody as their body.
But you are saying that the static edges could just as well be part of a normal static body? With a slightly different constructor? That would probably be the better solution.
Original thread: https://box2d.org/forum/viewtopic.php?t=1437