Box2D Forums

It is currently Mon May 20, 2013 9:54 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sun Aug 28, 2011 11:15 pm 
Offline

Joined: Sun Aug 28, 2011 10:11 pm
Posts: 7
Hello! I am writing an application using box2d physics & I found a prismatic joint bug (as i think):
Code:
    b2BodyDef bodyLadder1Def;
    bodyLadder1Def.type = b2_dynamicBody;
    bodyLadder1Def.position.Set(400 / PTM_RATIO, 400 / PTM_RATIO); // PTM_RATIO = 46
    bodyLadder1Def.angularDamping  = 0.5f;
    bodyLadder1Def.linearDamping   = 0.5f;

    b2Vec2 verticesLadder1[4];
    verticesLadder1[0].Set(0.0000f, 0.0000f);
    verticesLadder1[1].Set(2.6739f, 0.0000f);
    verticesLadder1[2].Set(2.6739f, 0.4130f);
    verticesLadder1[3].Set(0.0000f, 0.4130f);

    b2PolygonShape dynamicBox;
    dynamicBox.Set(verticesLadder1, 4);

    b2Body *ladder1Body = world->CreateBody(&bodyLadder1Def);

    b2FixtureDef fixtureLadder1Def;
    fixtureLadder1Def.shape           = &dynamicBox;
    fixtureLadder1Def.density         = 100.0f;
    fixtureLadder1Def.friction        = 1.0f;
    fixtureLadder1Def.restitution     = 0.5f;
    fixtureLadder1Def.filter.maskBits = 0x0001;

    ladder1Body->CreateFixture(&fixtureLadder1Def);

    // part 2

    b2BodyDef bodyLadder2Def;
    bodyLadder2Def.type = b2_dynamicBody;
    bodyLadder2Def.position.Set(400 / PTM_RATIO, 400 / PTM_RATIO);
    bodyLadder2Def.angularDamping  = 0.5f;
    bodyLadder2Def.linearDamping   = 0.5f;

    b2Vec2 verticesLadder2[4];

    verticesLadder2[0].Set(0.0000f, 0.0000f);
    verticesLadder2[1].Set(3.9560f, 0.0000f);
    verticesLadder2[2].Set(3.9560f, 0.2391f);
    verticesLadder2[3].Set(0.0000f, 0.2391f);

    b2PolygonShape dynamicLadder2Box;
    dynamicLadder2Box.Set(verticesLadder2, 4);

    b2Body *ladder2Body = world->CreateBody(&bodyLadder2Def);

    b2FixtureDef fixtureLadder2Def;
    fixtureLadder2Def.shape           = &dynamicLadder2Box;
    fixtureLadder2Def.density         = 100.0f;
    fixtureLadder2Def.friction        = 1.0f;
    fixtureLadder2Def.restitution     = 0.5f;
    fixtureLadder2Def.filter.maskBits = 0x0001;

    ladder2Body->CreateFixture(&fixtureLadder2Def);

    // joint
    b2PrismaticJointDef prismaticJointDef;
    b2Vec2 worldAxis(1.0f, 0.0f);
    prismaticJointDef.Initialize(ladder1Body, ladder2Body, b2Vec2((400.0f) / PTM_RATIO, (400.0f) / PTM_RATIO), worldAxis);
   
    world->CreateJoint(&prismaticJointDef);

When I run this code on 2.1.0 version of box it works fine. But in version 2.1.2 (and 2.2 now) world sometimes crashes during one body goes through another.
Here are screencasts of program behaviour (an iPad simulator with cocos2d framework)
http://dl.dropbox.com/u/17069366/new_dont_work.swf
http://dl.dropbox.com/u/17069366/old.swf


Top
 Profile  
 
PostPosted: Mon Aug 29, 2011 12:47 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Is it actually crashing or just moving a lot? If it is crashing, what is the call stack?


Top
 Profile  
 
PostPosted: Mon Aug 29, 2011 1:05 am 
Offline

Joined: Sun Aug 28, 2011 10:11 pm
Posts: 7
It's just moving a lot, cause app continues to work. All objects in world are going away in spite of scene is limited by edgeShapes


Top
 Profile  
 
PostPosted: Sat Sep 03, 2011 3:15 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Please try this fix:


Command: Commit
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PrismaticJoint.cpp
Sending content: D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PrismaticJoint.cpp
Completed: At revision: 215


Top
 Profile  
 
PostPosted: Sun Sep 04, 2011 5:47 pm 
Offline

Joined: Sun Aug 28, 2011 10:11 pm
Posts: 7
thanks, its ok :D


Top
 Profile  
 
PostPosted: Mon Sep 05, 2011 9:51 pm 
Offline

Joined: Sun Aug 28, 2011 10:11 pm
Posts: 7
Hi again :)
I can't understand if it is bug or feature of prismatic joint.

We have a code:
Code:
   
    // cylinder and rootCylinder joint
    b2RevoluteJointDef cylinderJointDef;
    cylinderJointDef.Initialize(cylinderBody, rootCylinder, cylinderBody->GetPosition());
   
    // cylinder and rootCylinder joint   
    b2PrismaticJointDef hydroCylinderJointDef;   
    b2Vec2 axis = cylinderBody->GetPosition() - pistonBody->GetPosition();                       
   
    hydroCylinderJointDef.Initialize(cylinderBody, pistonBody, cylinderBody->GetPosition(), axis);
    hydroCylinderJointDef.lowerTranslation    = -20.0f;
    hydroCylinderJointDef.upperTranslation   = 0.0f;
    hydroCylinderJointDef.enableLimit            = true;
    hydroCylinderJointDef.maxMotorForce      = 10.0f;
    hydroCylinderJointDef.motorSpeed           = 0.0f;
    hydroCylinderJointDef.enableMotor           = true;

    // create joints                                 
    world->CreateJoint(&cylinderJointDef);
    world->CreateJoint(&hydroCylinderJointDef); 
 


Piston starts to twitch, when I try to move piston into cylinder. Screencast

Then we disable limit:
Code:
hydroCylinderJointDef.enableLimit = false;


After that piston can't move through cylinder. Our system just turn round. Screencast


Top
 Profile  
 
PostPosted: Tue Sep 06, 2011 9:18 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Please call b2World::Dump, zip up the log file, and post the zip file.


Top
 Profile  
 
PostPosted: Tue Sep 06, 2011 6:05 pm 
Offline

Joined: Sun Aug 28, 2011 10:11 pm
Posts: 7
log


Attachments:
File comment: log
log.zip [26.42 KiB]
Downloaded 68 times
Top
 Profile  
 
PostPosted: Tue Sep 06, 2011 8:28 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
rav3n wrote:
b2Vec2 axis = cylinderBody->GetPosition() - pistonBody->GetPosition();


This was the problem. You weren't using a unit axis. I added code to normalize the axis.


Top
 Profile  
 
PostPosted: Tue Sep 06, 2011 9:49 pm 
Offline

Joined: Sun Aug 28, 2011 10:11 pm
Posts: 7
thanks a lot :D


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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