Box2D Forums

It is currently Sun May 19, 2013 9:26 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Mar 06, 2012 7:28 am 
Offline

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
Hi. I post a link to my issue. Im not sure if it is a bug, but it seems to.

The fact is a body flying in the air (non touching anything), with a b2Contact class attached to it and returning true by the IsTouching() function.

http://box2d.org/forum/viewtopic.php?f=3&t=8245

Greetings!


Top
 Profile  
 
PostPosted: Thu Mar 08, 2012 1:08 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Did you try using the latest version in SVN? If that doesn't help, please call b2World::Dump at the point where IsTouching is incorrect and attach the file here or on the issues page here: http://code.google.com/p/box2d/issues/list


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 5:45 am 
Offline

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
Hi Erin.
Before anything thanks for box2d. It's great.

Im using 2.2.1 version (the latest on download page). [Box2D_v2.2.1.zip]

The issue: Body stood over the ground. I apply LinearImpulse to make him jump, then world->step. After this world->step I get a contact with IsTouching=true. Then render with DebugDraw and I see the body separated from the ground.

My code:

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

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

      // Genera los contactos actuales
      for (int j = 0; j < _s->CheckCol_GetListSize(); j++)
      {
// Here I Get pointer to the box which I applied LinearImpulse to make it jump
         Phy2DBody* _phy2dbody = _s->CheckCol_GetBody(j);
         
         for (b2ContactEdge *ce = _phy2dbody->GetB2Body()->GetContactList(); ce; ce = ce->next)
         {
// Phy2DContact inherit from b2Contact
            Phy2DContact *_phy2dcontact = (Phy2DContact *)ce->contact;
         
            if (_phy2dcontact->IsTouching())
            {
               if (_s->debug)
               {
// I get inside this line after apply LinearImpulse and the world->step above. Then render and box is separated from ground. Using DebugDraw.
                  _s->GetB2World()->Dump();
               }
            }
         }
      }
   }
}


Dump info:
Quote:
b2Vec2 g(0.000000000000000e+000f, 1.100000000000000e+001f);
m_world->SetGravity(g);
b2Body** bodies = (b2Body**)b2Alloc(2 * sizeof(b2Body*));
b2Joint** joints = (b2Joint**)b2Alloc(0 * sizeof(b2Joint*));

{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(3.000000000000000e+001f, 6.909857940673828e+001f);
bd.angle = 0.000000000000000e+000f;
bd.linearVelocity.Set(0.000000000000000e+000f, -8.618643951416016e+001f);
bd.angularVelocity = 0.000000000000000e+000f;
bd.linearDamping = 0.000000000000000e+000f;
bd.angularDamping = 0.000000000000000e+000f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(16);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+000f;
bodies[0] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 6.000000238418579e-001f;
fd.restitution = 0.000000000000000e+000f;
fd.density = 5.000000000000000e-001f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(2);
fd.filter.groupIndex = int16(0);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(-1.950000047683716e+000f, -4.750000000000000e+000f);
vs[1].Set(1.950000047683716e+000f, -4.750000000000000e+000f);
vs[2].Set(1.950000047683716e+000f, 4.750000000000000e+000f);
vs[3].Set(-1.950000047683716e+000f, 4.750000000000000e+000f);
shape.Set(vs, 4);

fd.shape = &shape;

bodies[0]->CreateFixture(&fd);
}
}

{
b2BodyDef bd;
bd.type = b2BodyType(0);
bd.position.Set(5.120000457763672e+001f, 7.580000305175781e+001f);
bd.angle = 0.000000000000000e+000f;
bd.linearVelocity.Set(0.000000000000000e+000f, 0.000000000000000e+000f);
bd.angularVelocity = 0.000000000000000e+000f;
bd.linearDamping = 0.000000000000000e+000f;
bd.angularDamping = 0.000000000000000e+000f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+000f;
bodies[1] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 0.000000000000000e+000f;
fd.restitution = 0.000000000000000e+000f;
fd.density = 1.000000000000000e+000f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(2);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(0);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(-5.120000076293945e+001f, -5.000000000000000e-001f);
vs[1].Set(5.120000076293945e+001f, -5.000000000000000e-001f);
vs[2].Set(5.120000076293945e+001f, 5.000000000000000e-001f);
vs[3].Set(-5.120000076293945e+001f, 5.000000000000000e-001f);
shape.Set(vs, 4);

fd.shape = &shape;

bodies[1]->CreateFixture(&fd);
}
}

b2Free(joints);
b2Free(bodies);
joints = NULL;
bodies = NULL;


I hope it helps!!
Thanks!


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 1:43 pm 
Offline

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
Here the info of b2Contact class

Quote:
- _c 0x02396238 b2Contact *
+ [b2PolygonContact] {...} b2PolygonContact
+ __vfptr 0x00942aa0 const b2PolygonContact::`vftable' *
+ s_registers 0x00947de0 struct b2ContactRegister (* b2Contact::s_registers)[4] b2ContactRegister [4][4]
s_initialized true bool
m_flags 38 unsigned int
+ m_prev 0x00000000 {m_flags=??? m_prev=??? m_next=??? ...} b2Contact *
+ m_next 0x00000000 {m_flags=??? m_prev=??? m_next=??? ...} b2Contact *
+ m_nodeA {other=0x023960f8 contact=0x02396238 prev=0x00000000 ...} b2ContactEdge
+ m_nodeB {other=0x02395fb8 contact=0x02396238 prev=0x00000000 ...} b2ContactEdge
+ m_fixtureA 0x0239a0d0 {m_density=1.0000000 m_next=0x00000000 m_body=0x02395fb8 ...} b2Fixture *
+ m_fixtureB 0x0239a110 {m_density=0.50000000 m_next=0x00000000 m_body=0x023960f8 ...} b2Fixture *
m_indexA 0 int
m_indexB 0 int
+ m_manifold {points=0x02396278 localNormal={...} localPoint={...} ...} b2Manifold
m_toiCount 0 int
m_toi 1.0000000 float
m_friction 0.00000000 float
m_restitution 0.00000000 float


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 1:53 pm 
Offline

Joined: Mon Mar 05, 2012 7:18 am
Posts: 25
Location: Sevilla
I'm seeing your code... the problem is that box2d solve collisions before move bodies. Box2d update touching flag in the collision step before move the body, so before to know that the contact won't be touching, box2d thinks it is touching. Then it moves the body and it is not touching. Box2D should update touching flag after move bodies, but it could have to test collisions again so I dont know what whould be a solution.


Top
 Profile  
 
PostPosted: Fri Mar 16, 2012 10:46 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
You can always freshen up contacts that you care about using b2Contact::Evaluate. That will not hinder overall performance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group