Add AddFreeJoint and remove isfree from AddJoint.

PiperOrigin-RevId: 604597442
Change-Id: I2fe03cf0f9a59b425080cc5cc12b236fea9c020d
This commit is contained in:
Alessio Quaglino
2024-02-06 03:48:48 -08:00
committed by Copybara-Service
parent 3b2dd06c54
commit 01439f28b3
4 changed files with 23 additions and 13 deletions
+2 -2
View File
@@ -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;
}
}
+18 -9
View File
@@ -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;
+2 -1
View File
@@ -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);
+1 -1
View File
@@ -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