Fixture Frustration!

What I am doing:
As soon as a body(bodyA) collides with another body (bodyB), bodyA will be destroyed
and will be recreated as a fixture on bodyB with a position relative to bodyB.

The Issue:
The fixtures are placed relative to the body, however this fails
when you have a fixture being placed on top of another fixture.

What I want to do:
Place the newly created fixtures relative to the position of the fixture it is colliding with (not the body!).
But I can't seem to do this! Fixtures don't have a position, only bodies do!

I've tried giving a position in fixture's user data to use but I ended up with the same result as in 3 (overlap, not on top),
because I am getting the position of body of the object being collided (but I want the position of the fixture being collided).

Take a look at the pic below 😐
You need to express the position of the colliding fixture (the one to be destroyed) in terms of local coordinates of the target body (the one that will remain).

For a circle this is pretty easy because there is no rotation, only one point and usually it is at (0,0) in the colliding body's local coordinates. If so, you could do:
Code:
b2Vec2 newLocalPos = targetBody->GetLocalPoint( collidingBody->GetPosition() );

... to find the center of the circle in local coordinates of the target body.

For a polygon it's a little more complicated because rotation can't be ignored. If you don't have any information about how the polygon was created you will need to dig out the polygon shape itself and iterate over the vertices. You could then get these in world coordinates by using collidingBody->GetWorldPoint( v ) and then continue as above for each of them.
irresistibleforce, I am doing what you said but there is a problem:

The target body will always be the center planet (and it will have fixtures attached to it)

So when I collide with a fixture it will always grab position relative to the center planet,

instead I want to get the position relative to the fixture that I collided with (not the body).

Do you know how I can do this?
You don't need the "position" of the fixture you collided with.

Code:
newCircle.m_p = oldCircle.m_p + targetBody->GetLocalPoint( collidingBody->GetPosition() );


Drawing some pictures with vectors will help you figure it out.
When you create the new fixture on the target body, you have to specify the position for it in local coordinates of the target body, so I would contend that the position relative to the target body is in fact exactly what you want.

Just to be sure, we are talking about two bodies right? I am a bit puzzled about this part:
fuzzymint wrote:
The Issue:
The fixtures are placed relative to the body, however this fails
when you have a fixture being placed on top of another fixture.

When the collision is detected, if you are taking the current world position of the colliding body and converting that to local coordinates of the target body to create the new fixture, I don't see why it makes any difference how many other fixtures are already there.
I think you guys might be a little confused why I am trying to do things this way:

At first I tried Erin's/Irresistable force's method, adding the fixture relative to the center target body.

This worked fine except when I spin the center body fast and a fixture from the center body

collides with the body (soon to become a fixture) moving towards it because

the new fixture is usually placed with an overlap or a gap with fixture it collided with.

Note: (Fixture is created and position is set immediately after beginContact is called)

So I realized I wanted the fixtures to be placed at a fixed distance from each other.

The best way I found was to somehow get the distance vector between the two colliding fixtures

and scale that to the fixed distance I want. So that is why I need the position of the fixtures.

Now how can achieve this? 😐

Original thread: https://box2d.org/forum/viewtopic.php?t=8292