48 #include "btBulletDynamicsCommon.h"
57 VerticalSpineModelCableCollision::VerticalSpineModelCableCollision(
size_t segments) :
62 VerticalSpineModelCableCollision::~VerticalSpineModelCableCollision()
86 double targetVelocity;
93 tgUtil::round(c.edge / std::sqrt(2.0)),
111 std::cout <<
"StructureInfo:" << std::endl
112 << structureInfo << std::endl
113 <<
"Model: " << std::endl
114 << model << std::endl;
117 void addNodes(
tgStructure& tetra,
double edge,
double height)
120 tetra.
addNode( c.edge / 2.0, 0, 0,
"sphere");
122 tetra.
addNode( -c.edge / 2.0, 0, 0,
"sphere");
124 tetra.
addNode(0, c.height, -edge / 2.0,
"sphere");
126 tetra.
addNode(0, c.height, edge / 2.0,
"sphere");
128 tetra.
addNode(0, c.height/2, 0,
"sphere");
131 tetra.
addNode(c.edge / 2.0, 0, 0.5,
"sphere");
132 tetra.
addNode( c.edge / 2.0, 0, -0.5,
"sphere");
133 tetra.
addNode( 0.5+c.edge / 2.0, 0, 0.5,
"sphere");
134 tetra.
addNode( 0.5+c.edge / 2.0, 0, -0.5,
"sphere");
136 tetra.
addNode(-c.edge / 2.0, 0, 0.5,
"sphere");
137 tetra.
addNode(-c.edge / 2.0, 0, -0.5,
"sphere");
138 tetra.
addNode(-0.5 + -c.edge / 2.0, 0, 0.5,
"sphere");
139 tetra.
addNode(-0.5 + -c.edge / 2.0, 0, -0.5,
"sphere");
141 tetra.
addNode(0.5, c.height, -edge / 2.0,
"sphere");
142 tetra.
addNode(-0.5, c.height, -edge / 2.0,
"sphere");
143 tetra.
addNode(0.5, c.height, -0.5 + -edge / 2.0,
"sphere");
144 tetra.
addNode(-0.5, c.height, -0.5 + -edge / 2.0,
"sphere");
146 tetra.
addNode(0.5, c.height, edge / 2.0,
"sphere");
147 tetra.
addNode(-0.5, c.height, edge / 2.0,
"sphere");
148 tetra.
addNode(0.5, c.height, 0.5 + edge / 2.0,
"sphere");
149 tetra.
addNode(-0.5, c.height, 0.5 + edge / 2.0,
"sphere");
152 void addNodesB(
tgStructure& tetra,
double edge,
double height)
156 tetra.
addNode( c.edge / 2.0, 0, 0);
158 tetra.
addNode( -c.edge / 2.0, 0, 0);
160 tetra.
addNode(0, c.height, -edge / 2.0);
162 tetra.
addNode(0, c.height, edge / 2.0);
164 tetra.
addNode(0, c.height/2, 0);
196 for (
double i = 0; i<=3; i++)
198 tetra.
addPair(i,i*4+5,
"holder");
199 tetra.
addPair(i,i*4+6,
"holder");
200 tetra.
addPair(i*4+5,i*4+7,
"holder");
201 tetra.
addPair(i*4+6,i*4+8,
"holder");
202 tetra.
addPair(i*4+7,i*4+8,
"holder");
240 double edge,
size_t segmentCount)
243 const btVector3 offset(0, 7.5, 0);
244 for (
size_t i = 1; i < segmentCount; ++i)
247 t->addTags(
tgString(
"segment", i + 1));
248 t->move((i + 1) * offset);
259 const std::vector<tgStructure*> children = snake.
getChildren();
260 for (
size_t i = 1; i < children.size(); ++i)
262 tgNodes vn0 = children[0]->getNodes();
263 tgNodes vn1 = children[i ]->getNodes();
266 snake.
addPair(vn0[0], vn1[0],
"vertical muscle a");
267 snake.
addPair(vn0[1], vn1[1],
"vertical muscle b");
268 snake.
addPair(vn0[2], vn1[2],
"vertical muscle c");
269 snake.
addPair(vn0[3], vn1[3],
"vertical muscle d");
271 tgNodes sn0 = children[i-1]->getNodes();
272 tgNodes sn1 = children[i ]->getNodes();
281 void mapMuscles(VerticalSpineModelCableCollision::MuscleMap& muscleMap,
282 tgModel& model,
size_t segmentCount)
293 for (
size_t i = 1; i < segmentCount ; ++i)
307 std::cout <<
"edge: " << c.edge <<
"; height: " << c.height << std::endl;
312 addNodesB(tetraB, c.edge, c.height);
314 tetraB.move(btVector3(0.0, 2, 0));
322 tB->addTags(
tgString(
"segment", 1));
326 addNodes(tetra, c.edge, c.height);
331 tetra.move(btVector3(0.0, -6, 0));
334 addSegments(snake, tetra, c.edge, m_segments);
346 const tgRod::Config rodConfigA(c.radius, c.densityA, c.friction,
347 c.rollFriction, c.restitution);
348 const tgRod::Config rodConfigB(c.radius, c.densityB, c.friction,
349 c.rollFriction, c.restitution);
351 const tgRod::Config holderConfigA(0.15, c.densityA, c.friction,
352 c.rollFriction, c.restitution);
353 const tgRod::Config holderConfigB(0.15, c.densityB, c.friction,
354 c.rollFriction, c.restitution);
361 spec.addBuilder(
"rod",
new tgRodInfo(rodConfigA));
362 spec.addBuilder(
"rodB",
new tgRodInfo(rodConfigB));
365 spec.addBuilder(
"holder",
new tgRodInfo(holderConfigA));
366 spec.addBuilder(
"holderB",
new tgRodInfo(holderConfigB));
370 spec.addBuilder(
"sphere",
new tgSphereInfo(weldingConfigA));
377 false, c.maxTens, c.targetVelocity, 1.0,0.1,0.0);
390 m_allMuscles = this->find<tgSpringCableActuator> (
"muscle");
391 m_allSegments = this->find<tgModel> (
"segment");
393 mapMuscles(m_muscleMap, *
this, m_segments);
395 trace(structureInfo, *
this);
411 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Definition of class tgSphereInfo.
Contains the definition of class VerticalSpineModel.
Convenience function for combining strings with ints, mostly for naming structures.
Contains the definition of class tgSphere.
Utility class for class casting and filtering collections by type.
virtual void setup(tgWorld &world)
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
std::string tgString(std::string s, int i)
virtual void step(const double dt)
Definition of class tgStructure.
std::vector< T * > find(const tgTagSearch &tagSearch)
Definition of class tgStructureInfo.
Rand seeding simular to the evolution and terrain classes.
Definition of class tgBuildSpec.
virtual void step(double dt)
Definition of class tgRigidAutoCompound.
virtual void setup(tgWorld &world)
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")