How can you copy joints?

General discussion about the R.U.B.E editor
Post Reply
garfi43
Posts: 6
Joined: Mon Jan 21, 2013 11:00 am

How can you copy joints?

Post 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?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: How can you copy joints?

Post 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
garfi43
Posts: 6
Joined: Mon Jan 21, 2013 11:00 am

Re: How can you copy joints?

Post 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);
Post Reply