Page 1 of 1
How can you copy joints?
Posted: Mon Jan 21, 2013 12:31 pm
by garfi43
I am trying to copy a joint but there are some errors.
Code: Select all
Json::Value jointValue;
b2Joint *tmpJoint;
tmpJoint=json->getJointByName("jointName");
jointValue=json->b2j(tmpJoint);
json->j2b2Joint(World,jointValue);
But it is like the b2j function does not return anything, crushing the program at line 185 on b2Joint.cpp
Code: Select all
b2Assert(def->bodyA != def->bodyB);
Does anyone have managed to do this?
Re: How can you copy joints?
Posted: Mon Jan 21, 2013 1:53 pm
by iforce2d
I had some discussion with garfi about this, and it looks like a slightly different version of the b2j and j2b2Joint functions might do the job. See the pastebin here for a summary of my suggestion:
http://pastebin.com/x1DDNXKx
Re: How can you copy joints?
Posted: Tue Jan 22, 2013 2:15 am
by garfi43
Helpful suggestion Chris, it worked out. Thank you.
on b2dJson.h
Code: Select all
//reading functions
...
b2Joint* j2b2NewJoint(b2World* world, Json::Value jointValue, b2Body *bodyA, b2Body *bodyB);
...
on b2dJson.cpp
Code: Select all
b2Joint* b2dJson::j2b2NewJoint(b2World* world, Json::Value jointValue, b2Body *bodyA, b2Body *bodyB)
{
b2Joint* joint = NULL;
////////////* comment out these four lines *////
// int bodyIndexA = jointValue["bodyA"].asInt();
// int bodyIndexB = jointValue["bodyB"].asInt();
// if ( bodyIndexA >= (int)m_bodies.size() || bodyIndexB >= (int)m_bodies.size() )
// return NULL;
...
if ( jointDef ) {
//set features common to all joints
////////////* replace with parameters *////
jointDef->bodyA = bodyA;//m_bodies[bodyIndexA];
jointDef->bodyB = bodyB;//m_bodies[bodyIndexB];
...
}
return joint;
}
on code:
Code: Select all
json->j2b2NewJoint(World,jointValue,bodyA,bodyB);