40 #include "btBulletDynamicsCommon.h"
74 double targetVelocity;
81 tgUtil::round(c.edge / std::sqrt(2.0)),
99 std::cout <<
"StructureInfo:" << std::endl
100 << structureInfo << std::endl
101 <<
"Model: " << std::endl
102 << model << std::endl;
105 void VerticalSpineModel::addNodes(
tgStructure& tetra,
double edge,
double height)
108 tetra.
addNode( c.edge / 2.0, 0, 0);
110 tetra.
addNode( -c.edge / 2.0, 0, 0);
112 tetra.
addNode(0, c.height, -edge / 2.0);
114 tetra.
addNode(0, c.height, edge / 2.0);
116 tetra.
addNode(0, c.height/2, 0);
119 void VerticalSpineModel::addPairs(
tgStructure& tetra)
127 void VerticalSpineModel::addPairsB(
tgStructure& tetra)
136 double edge,
size_t segmentCount)
139 const btVector3 offset(0, 7.5, 0);
140 for (
size_t i = 1; i < segmentCount; ++i)
143 t->addTags(
tgString(
"segment", i + 1));
144 t->move((i + 1) * offset);
152 void VerticalSpineModel::addMuscles(
tgStructure& snake)
154 const std::vector<tgStructure*> children = snake.
getChildren();
155 for (
size_t i = 1; i < children.size(); ++i)
157 tgNodes n0 = children[i-1]->getNodes();
158 tgNodes n1 = children[i ]->getNodes();
161 snake.
addPair(n0[0], n1[0],
"vertical muscle a");
162 snake.
addPair(n0[1], n1[1],
"vertical muscle b");
163 snake.
addPair(n0[2], n1[2],
"vertical muscle c");
164 snake.
addPair(n0[3], n1[3],
"vertical muscle d");
175 tgModel& model,
size_t segmentCount)
186 for (
size_t i = 1; i < segmentCount ; ++i)
199 std::cout <<
"edge: " << c.edge <<
"; height: " << c.height << std::endl;
204 addNodes(tetraB, c.edge, c.height);
206 tetraB.move(btVector3(0.0, 2, 0));
214 tB->addTags(
tgString(
"segment", 1));
218 addNodes(tetra, c.edge, c.height);
223 tetra.move(btVector3(0.0, -6, 0));
226 addSegments(snake, tetra, c.edge, m_segments);
238 const tgRod::Config rodConfigA(c.radius, c.densityA, c.friction,
239 c.rollFriction, c.restitution);
240 const tgRod::Config rodConfigB(c.radius, c.densityB, c.friction,
241 c.rollFriction, c.restitution);
243 spec.addBuilder(
"rod",
new tgRodInfo(rodConfigA));
244 spec.addBuilder(
"rodB",
new tgRodInfo(rodConfigB));
249 c.hist, c.maxTens, c.targetVelocity);
256 structureInfo.buildInto(*
this, world);
260 allMuscles = tgCast::filter<tgModel, tgBasicActuator> (
getDescendants());
261 mapMuscles(muscleMap, *
this, m_segments);
263 trace(structureInfo, *
this);
273 throw std::invalid_argument(
"dt is not positive");
284 const std::vector<tgBasicActuator*>&
287 const MuscleMap::const_iterator it = muscleMap.
find(key);
288 if (it == muscleMap.end())
290 throw std::invalid_argument(
"Key '" + key +
"' not found in muscle map");
298 const std::vector<tgBasicActuator*>& VerticalSpineModel::getAllMuscles()
const
const std::vector< tgStructure * > & getChildren() const
virtual void step(const double dt)
virtual void setup(tgWorld &world)
void addChild(tgStructure *child)
Definition of class tgRodInfo.
virtual void setup(tgWorld &world)
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 VerticalSpineModel.
VerticalSpineModel(size_t segments)
std::map< std::string, std::vector< tgBasicActuator * > > MuscleMap
Definition of class tgBasicActuatorInfo.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
const std::vector< tgBasicActuator * > & getMuscles(const std::string &key) const
Contains the definition of class tgBasicActuator.
std::string tgString(std::string s, int i)
Definition of class tgStructure.
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition of class tgStructureInfo.
Contains the definition of class tgUtil and overloaded operator<<() free functions.
Definition of class tgBuildSpec.
Definition of class tgRigidAutoCompound.
void notifyStep(double dt)
std::vector< tgModel * > getDescendants() const
void addNode(double x, double y, double z, std::string tags="")