void TensegrityModel::addChild(tgStructure& structure, const std::string &parentPath, const std::string& childName, const Yam& childStructurePath, tgBuildSpec& spec) { if (!childStructurePath) return; std::string childPath = childStructurePath.as<std::string>(); // if path is relative, use path relative to parent structure if (childPath[0] != '/') { childPath = parentPath.substr(0, parentPath.rfind("/") + 1) + childPath; } tgStructure childStructure = tgStructure(childName); buildStructure(childStructure, childPath, spec); structure.addChild(childStructure); }
void VerticalSpineModel::addSegments(tgStructure& snake, const tgStructure& tetra, double edge, size_t segmentCount) { //const btVector3 offset(0, 0, -edge * 1.15); const btVector3 offset(0, 7.5, 0); for (size_t i = 1; i < segmentCount; ++i) { tgStructure* const t = new tgStructure(tetra); t->addTags(tgString("segment", i + 1)); t->move((i + 1) * offset); // Add a child to the snake snake.addChild(t); } }
void BigDoxieNoFeet::addSegments(tgStructure& puppy, tgStructure& vertebra, tgStructure& hip, tgStructure& leg, tgStructure& foot, double r){ const double offsetDist = r+1; const double offsetDist2 = offsetDist*8; const double offsetDist3 = offsetDist2+4; const double yOffset_leg = -(2*r+1); const double yOffset_foot = -(2*r+6); //Vertebrae btVector3 offset(offsetDist,0.0,0); //Hips btVector3 offset1(offsetDist*2,0.0,offsetDist); btVector3 offset2(offsetDist2,0.0,offsetDist); btVector3 offset3(offsetDist*2,0.0,-offsetDist); btVector3 offset4(offsetDist2,0.0,-offsetDist); //Lower legs btVector3 offset5(offsetDist3,yOffset_leg,offsetDist); btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist); btVector3 offset7(r*2,yOffset_leg,offsetDist); btVector3 offset8(r*2,yOffset_leg,-offsetDist); //Feet btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist); btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist); btVector3 offset11(r*2+1,yOffset_foot,offsetDist); btVector3 offset12(r*2+1,yOffset_foot,-offsetDist); for(std::size_t i = 0; i < m_segments; i++) { //Connect segments for spine of puppy tgStructure* t = new tgStructure (vertebra); t->addTags(tgString("spine segment num", i + 1)); t->move((i + 1)*offset); if (i % 2 == 1){ t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0); } else{ t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0); } puppy.addChild(t); //Add a segment to the puppy } for(std::size_t i = m_segments; i < (m_segments + 2); i++) {//deal with right hip and shoulder first tgStructure* t = new tgStructure (hip); t->addTags(tgString("segment num", i + 1)); if(i % 2 == 0){ t->move(offset2); t->addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI); } else{ t->move(offset1); t->addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI); } puppy.addChild(t); //Add a segment to the puppy } for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {//deal with left hip and shoulder now tgStructure* t = new tgStructure (hip); t->addTags(tgString("segment num", i + 1)); if(i % 2 == 0){ t->move(offset4); } else{ t->move(offset3); } puppy.addChild(t); //Add a segment to the puppy } for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {//right front and back legs tgStructure* t = new tgStructure (leg); t->addTags(tgString("segment num", i + 1)); if(i % 2 == 0){ t->move(offset5); t->addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI); } else{ t->move(offset7); t->addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI); //the rotations for the legs are a remnant of the earlier design. Removing them now //would mean changing all my muscle attachments. I will do this someday. } puppy.addChild(t); //Add a segment to the puppy } for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {//left front and back legs tgStructure* t = new tgStructure (leg); t->addTags(tgString("segment num", i + 1)); if(i % 2 == 0){ t->move(offset6); t->addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI); } else{ t->move(offset8); t->addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI); } puppy.addChild(t); //Add a segment to the puppy } /*for(std::size_t i = (m_segments + m_hips + m_legs); i < (m_segments + m_hips + m_legs + 2); i++) {//right front and back feet tgStructure* t = new tgStructure (foot); t->addTags(tgString("segment num", i + 1)); if(i % 2 == 0){ t->move(offset9); t->addRotation(btVector3(offsetDist3+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0); } else{ t->move(offset11); t->addRotation(btVector3(r*2+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0); } puppy.addChild(t); //Add a segment to the puppy } for(std::size_t i = (m_segments + m_hips + m_legs + 2); i < (m_segments + m_hips + m_legs + m_feet); i++) {//left front and back feet tgStructure* t = new tgStructure (foot); t->addTags(tgString("segment num", i + 1)); if(i % 2 == 0){ t->move(offset10); t->addRotation(btVector3(offsetDist3+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0); } else{ t->move(offset12); t->addRotation(btVector3(r*2+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0); } puppy.addChild(t); //Add a segment to the puppy } */ }