Box2D Forums

 It is currently Tue May 21, 2013 3:30 pm

 All times are UTC - 8 hours [ DST ]

 Page 2 of 3 [ 23 posts ] Go to page Previous  1, 2, 3  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: Re: Contact issuePosted: Tue Mar 06, 2012 7:22 am

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
Yes, only two bodies in the world. I was debugging just this task. I also use BeginContact and EndContact to store list, but in that debug proccess it was clearer to see everything in the same update function

Thanks a lot for that link, I'll read it meticulously, maybe I should use other method to make bodies jump. Anyway the bug of IsTouching=true while the body is flying is still alive jejeje I'll post a link to this post in the bug section.

Thanks!!

Top

 Post subject: Re: Contact issuePosted: Tue Mar 06, 2012 9:03 am

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
At the point where you show the debugger window in the previous post, what output do you get if you put this code in there (just after the Col_AddB2Contact). You might need to #include <stdio.h>
Code:
bool logVertices = false;
//break here to set logVertices to true when the time comes
if ( logVertices ) {

b2Fixture* f[2];
b2Body* b[2];
b2PolygonShape* s[2];

f[0] = ce->contact->GetFixtureA();
f[1] = ce->contact->GetFixtureB();

for (int i = 0; i < 2; i++) {
b[i] = f[i]->GetBody();
s[i] = (b2PolygonShape*)f[i]->GetShape();

int numVerts = s[i]->GetVertexCount();
printf( "Fixture %d has %d vertices:\n", i, numVerts );
for (int k = 0; k < numVerts; k++) {
b2Vec2 v = b[i]->GetWorldPoint( s[i]->GetVertex(k) );
printf( "%f, %f\n", v.x, v.y );
}

}

fflush(stdout);
}

You can use Visual Studio's debugger to change the value of the 'logVertices' bool to true to avoid getting output every frame.

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 5:46 am

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
I uploaded the world info in this thread -> http://box2d.org/forum/viewtopic.php?f=4&t=8250

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 6:41 am

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
Thanks Loren. So that dump was taken immediately after the IsTouching returns true?
Do you have the same problem if you change
Code:
if ( _phy2dcontact->IsTouching() )
to
Code:
if ( ce->contact->IsTouching() )
Just wondering if that cast is safe...

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 7:31 am

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
Yes, the problem is the same. My class inherit from b2Contact.

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 9:40 am

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
I see. I'm just asking because there is no guarantee that c-style downcasts are safe. You could maybe try a dynamic_cast but it would be better to set the b2Contact* as a member in your Phy2DContact class instead of inheriting.

Hmm... how about if you log the calls to BeginContact and EndContact during this run, do you get one call to each?

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 10:21 am

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
Well.. in that example I use Phy2DContact which inherit from b2Contact, but i tried many ways, and not using my own class, and IsTouching also return true. BeginContact and EndContact are called in the right way. The problem is that EndContact is called some frames after the box gets separated from the grouond (for some reason the contact keep alive for a while, and also before the box fall and touch the ground). So it is not useful for my objetive (which is to know which bodies are in contact, and what face of them). Trying it in post-solve callback is also the same than doing it on the main update, when the body gets separated in the first frame, IsTouching returns true as well. So.. I don't know, dump information shows they are separated, I think it has to be a bug In fact in the dump log the bodies are separated. Has to be something about updating touch flag.

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 11:36 am

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
Okay. I am beginning to think that perhaps the contact is being corrupted.
- If you take out all the extra code you have (eg. Col_DelAllB2Contact, Col_AddB2Contact etc) do you still see the problem?
- After the contact is generated, how many steps pass before IsTouching starts to return true? Two?
- Just to be sure, you are not deleting any Phy2DContact inside Col_DelAllB2Contact right?

For example:
Code:
void Phy2DSystem::Update()
{
for (int i = 0; i < num_scenes; i++)
{
Phy2DScene* _s = scene[i];

_s->GetB2World()->Step(time_step, 10, 8);

b2Body* body = ...set this to one of the bodies...;

for (b2ContactEdge *ce = body->GetContactList(); ce; ce = ce->next)
{
if ( ce->contact->IsTouching() )
{
//check
}
}
}
}

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 11:59 am

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
No problem with my code, it's quite simple, no phy2dcontact destroyed or something else.

About the steps.. firstly the box fall from air, contact is generated 3 frames before it touch ground. IsTouching is returning right values for those frames. It is false and when the body really touch ground it returns true. Then the body stand over the ground. Then LinearImpulse is applied, contact will be alive for 4 frames more (the frame where the body gets the impulse and separated from ground for the very first time, which is the frame where IsTouching() return wrong value, and three frames more where the contact is alive and IsTouching() returns false).

Top

 Post subject: Re: Contact issuePosted: Sat Mar 10, 2012 12:08 pm

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
The results are the same with this code:

Code:
// Update del world
_s->GetB2World()->Step(time_step, 10, 8);

for (b2Body *_body = _s->GetB2World()->GetBodyList(); _body; _body = _body->GetNext())
{
for (b2ContactEdge *ce = _body->GetContactList(); ce; ce = ce->next)
{
b2Contact* _c = ce->contact;
if (_c->IsTouching())
{
if (_s->debug)
{
_s->GetB2World()->Dump();
}
}
}
}

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 2 of 3 [ 23 posts ] Go to page Previous  1, 2, 3  Next

 All times are UTC - 8 hours [ DST ]

Who is online

Users browsing this forum: No registered users and 5 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: