# Box2D Forums

 It is currently Sat May 25, 2013 5:04 am

 All times are UTC - 8 hours [ DST ]

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Fixture Frustration!Posted: Thu Mar 22, 2012 10:12 am

Joined: Wed Nov 30, 2011 3:50 pm
Posts: 9
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

 Attachments: helpme.png [ 28.38 KiB | Viewed 489 times ]
Top

 Post subject: Re: Fixture Frustration!Posted: Thu Mar 22, 2012 11:46 am

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
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.

Top

 Post subject: Re: Fixture Frustration!Posted: Thu Mar 22, 2012 3:35 pm

Joined: Wed Nov 30, 2011 3:50 pm
Posts: 9
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?

Top

 Post subject: Re: Fixture Frustration!Posted: Thu Mar 22, 2012 5:17 pm

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
You don't need the "position" of the fixture you collided with.

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

Top

 Post subject: Re: Fixture Frustration!Posted: Thu Mar 22, 2012 5:24 pm

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
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.

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.

Top

 Post subject: Re: Fixture Frustration!Posted: Thu Mar 22, 2012 7:36 pm

Joined: Wed Nov 30, 2011 3:50 pm
Posts: 9
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?

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC - 8 hours [ DST ]

#### Who is online

Users browsing this forum: Google [Bot] and 4 guests

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

 Search for: