erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.09k stars 1.52k forks source link

Hi, how to 'link' edge shapes in v2.4? #648

Closed jcyuan closed 3 years ago

jcyuan commented 3 years ago

my game is an endless 2d platformer, in 2.3 i create (or move the previous) edge shape forward ahead by dynamically change it's m_nextVertex & m_hasNextVertex for chain or m_hasVertex3 & m_vertex3 for edge to achieve road edge recycling. but in 2.4 they are removed and new SetOneSided and SetTwoSided provided, what should i do to achieve what i want? (of course take ghost collision into account) thanks.

jcyuan commented 3 years ago

and a question: what is the difference between this two methods?

jcyuan commented 3 years ago

actually what confused me is, in v2.3 there is hasPrevVertex / hasNextVertex / SetPrevVertex / SetNextVertex in it, and i can only set v0 or v3 for the shape, but now only 2 cases you can choose: OneSided (provide all v0 - v3), otherwise TwoSided, am i right?

thegrb93 commented 3 years ago

I think edge shapes now always have next/prev Vertex and you need to set them via constructor or public methods. The has* stuff was removed.

jcyuan commented 3 years ago

I think OneSided uses all the 4vertices, and TwoSided only use v1 & v2, if i can't set only v0 v1 v2 or v1 v2 v3 for an edge, I think i need to find another way to achieve what i want.

that means, for example:

edge1 edge2 edge3


when game starts, i only create edge1 & edge2 so they will be TwoSided only which means they does not handle ghost collision because OneSided needs 4vertices but there is no v0 for edge1 and no v3 for edge2, in v2.3 there is hasPrev = false for edge1 and hasNext=false for edge2 so they can have ghost vertices still (but not sure this actually works), but in v2.4 these members are removed, so here i can enable ghost vertices for edge2 only once edge3 is created and just update edge2.v0 = edge1.v2 and edge2.v3 = edge3.v1. so with v2.4 it is impossible to achieve what i did in v2.3 right? or what i did in v2.3 is actually not work?

thegrb93 commented 3 years ago

Yeah, those were replaced too, but there's some new helper functions that let you convert to Stiffness and Damping if needed.

erincatto commented 3 years ago

You can just destroy and recreate the shape.

jcyuan commented 3 years ago

You can just destroy and recreate the shape.

hi, if i destroy / recreate repaidly, is this a efficient way? i mean, more efficient than re-use?

erincatto commented 3 years ago

Modifying a shape in place is just as expensive as recreate. Recreating is likely to be more robust as well.

jcyuan commented 3 years ago

Modifying a shape in place is just as expensive as recreate. Recreating is likely to be more robust as well.

i got it, thanks so much!