diff --git a/src/user/user_composite.cc b/src/user/user_composite.cc index 9cc75f58..08496987 100644 --- a/src/user/user_composite.cc +++ b/src/user/user_composite.cc @@ -456,7 +456,7 @@ bool mjCComposite::MakeParticle(mjCModel* model, mjCBody* body, char* error, int // add slider joints if none defined if (!add[mjCOMPKIND_PARTICLE]) { for (int i=0; i<3; i++) { - mjCJoint* jnt = b->AddJoint(&defjoint[mjCOMPKIND_JOINT][0], false); + mjCJoint* jnt = b->AddJoint(&defjoint[mjCOMPKIND_JOINT][0]); jnt->def = body->def; jnt->type = mjJNT_SLIDE; mjuu_setvec(jnt->pos, 0, 0, 0); @@ -468,7 +468,7 @@ bool mjCComposite::MakeParticle(mjCModel* model, mjCBody* body, char* error, int // add user-specified joints else { for (auto defjnt : defjoint[mjCOMPKIND_PARTICLE]) { - mjCJoint* jnt = b->AddJoint(&defjnt, false); + mjCJoint* jnt = b->AddJoint(&defjnt); jnt->def = body->def; } } diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index a8806eed..07852c78 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -659,16 +659,25 @@ mjCFrame* mjCBody::AddFrame(mjCFrame* _frame) { -// create new joint and add it to body -// _def==NULL means no defaults, unlike all others which inherit from body -mjCJoint* mjCBody::AddJoint(mjCDef* _def, bool isfree) { - // create joint - mjCJoint* obj = new mjCJoint(model, _def ? _def : (isfree ? NULL : def)); +// create new free joint (no default inheritance) and add it to body +mjCJoint* mjCBody::AddFreeJoint() { + // create free joint, don't inherit from defaults + mjCJoint* obj = new mjCJoint(model, NULL); + obj->type = mjJNT_FREE; - // set free type if specified - if (isfree) { - obj->type = mjJNT_FREE; - } + // set body pointer, add + obj->body = this; + + joints.push_back(obj); + return obj; +} + + + +// create new joint and add it to body +mjCJoint* mjCBody::AddJoint(mjCDef* _def) { + // create joint + mjCJoint* obj = new mjCJoint(model, _def ? _def : def); // set body pointer, add obj->body = this; diff --git a/src/user/user_objects.h b/src/user/user_objects.h index fa06467d..2ed3f58e 100644 --- a/src/user/user_objects.h +++ b/src/user/user_objects.h @@ -229,7 +229,8 @@ class mjCBody : public mjCBase { // API for adding objects to body mjCBody* AddBody(mjCDef* = 0); mjCFrame* AddFrame(mjCFrame* = 0); - mjCJoint* AddJoint(mjCDef* = 0, bool isfree = false); + mjCJoint* AddJoint(mjCDef* = 0); + mjCJoint* AddFreeJoint(); mjCGeom* AddGeom(mjCDef* = 0); mjCSite* AddSite(mjCDef* = 0); mjCCamera* AddCamera(mjCDef* = 0); diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index 3fcd95a8..fe5c09b3 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -3045,7 +3045,7 @@ void mjXReader::Body(XMLElement* section, mjCBody* pbody, mjCFrame* frame) { } // create free joint without defaults - mjCJoint* pjoint = pbody->AddJoint(NULL, true); + mjCJoint* pjoint = pbody->AddFreeJoint(); pjoint->SetFrame(frame); // save defaults after creation, to make sure writing is ok