40 #include "btBulletDynamicsCommon.h"
45 NestedStructureTestModel::NestedStructureTestModel(
size_t segments) :
56 void addNodes(
tgStructure& tetra,
double edge,
double height)
59 tetra.
addNode(-edge / 2.0, 0, 0);
61 tetra.
addNode( edge / 2.0, 0, 0);
65 tetra.
addNode(0, height / 2.0, tgUtil::round(std::sqrt(3.0) / 2.0 * height));
70 tetra.
addPair(0, 1,
"back bottom rod");
71 tetra.
addPair(0, 2,
"back right rod");
72 tetra.
addPair(0, 3,
"front right rod");
73 tetra.
addPair(1, 2,
"back left rod");
74 tetra.
addPair(1, 3,
"front left rod");
75 tetra.
addPair(2, 3,
"front top rod");
82 const btVector3 offset(0, 0, -edge * 1.15);
83 for (
size_t i = 0; i < segmentCount; ++i)
86 t->addTags(
tgString(
"segment", i + 1));
87 t->move((i + 1) * offset);
96 const std::vector<tgStructure*> children = snake.
getChildren();
97 for (
size_t i = 1; i < children.size(); ++i)
99 tgNodes n0 = children[i-1]->getNodes();
100 tgNodes n1 = children[i ]->getNodes();
102 snake.
addPair(n0[0], n1[0],
"outer right muscle");
103 snake.
addPair(n0[1], n1[1],
"outer left muscle");
104 snake.
addPair(n0[2], n1[2],
"outer top muscle");
106 snake.
addPair(n0[0], n1[3],
"inner right muscle");
107 snake.
addPair(n0[1], n1[3],
"inner left muscle");
108 snake.
addPair(n0[2], n1[3],
"inner top muscle");
127 std::cout <<
"StructureInfo:" << std::endl
128 << structureInfo << std::endl
129 <<
"Model: " << std::endl
130 << model << std::endl;
135 void NestedStructureTestModel::setup(
tgWorld& world)
137 const double edge = 30.0;
138 const double height = tgUtil::round(std::sqrt(3.0)/2 * edge);
139 std::cout <<
"edge: " << edge <<
"; height: " << height << std::endl;
143 addNodes(tetra, edge, height);
148 tetra.move(btVector3(0.0, 2.0, 100.0));
152 addSegments(snake, tetra, edge, m_segments);
157 const double density = 4.2 / 300.0;
158 const double radius = 0.5;
161 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
169 structureInfo.buildInto(*
this, world);
173 allMuscles = tgCast::filter<tgModel, tgLinearString> (
getDescendants());
174 mapMuscles(muscleMap, *
this);
176 trace(structureInfo, *
this);
186 throw std::invalid_argument(
"dt is not positive");
197 const std::vector<tgLinearString*>&
198 NestedStructureTestModel::getMuscles (
const std::string& key)
const
200 const MuscleMap::const_iterator it = muscleMap.find(key);
201 if (it == muscleMap.end())
203 throw std::invalid_argument(
"Key '" + key +
"' not found in muscle map");
const std::vector< tgStructure * > & getChildren() const
virtual void setup(tgWorld &world)
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
Utility class for class casting and filtering collections by type.
Contains the definition of class NestedStructureTestModel.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of class tgLinearString.
std::string tgString(std::string s, int i)
Definition of class tgStructure.
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition of class tgStructureInfo.
Definition of class tgLinearStringInfo.
Contains the definition of class tgUtil and overloaded operator<<() free functions.
Definition of class tgBuildSpec.
std::map< std::string, std::vector< tgLinearString * > > MuscleMap
Definition of class tgRigidAutoCompound.
void notifyStep(double dt)
virtual void step(double dt)
std::vector< tgModel * > getDescendants() const
void addNode(double x, double y, double z, std::string tags="")