37 #include "LinearMath/btVector3.h"
69 double targetVelocity;
99 const btVector3 offset(-edge, 0, 0.0);
100 for (
size_t i = 0; i < segmentCount; ++i)
103 t->addTags(
tgString(
"segment", i + 1));
104 t->move((i + 1) * offset);
113 const std::vector<tgStructure*> children = snake.
getChildren();
115 for (
size_t i = 1; i < children.size(); ++i)
117 tgNodes n0 = children[i-1]->getNodes();
118 tgNodes n1 = children[i ]->getNodes();
122 snake.
addPair(n0[4], n1[5],
"segment rod");
126 snake.
addPair(n0[6], n1[7],
"segment rod");
134 const std::vector<tgStructure*> children = snake.
getChildren();
135 for (
size_t i = 1; i < children.size(); ++i)
137 tgNodes n0 = children[i-1]->getNodes();
138 tgNodes n1 = children[i ]->getNodes();
140 tgNode mid0((n0[0] + n1[0])/2.0);
141 tgNode mid1((n0[1] + n1[1])/2.0);
142 tgNode mid2((n0[2] + n1[2])/2.0);
143 tgNode mid3((n0[3] + n1[3])/2.0);
147 btScalar segDist = (n0[0] - n1[0]).length() / 2.0;
148 tgNode start0 = n0[0] + btVector3(segDist, 0.0, 0.0);
149 tgNode start1 = n0[1] + btVector3(segDist, 0.0, 0.0);
150 tgNode start2 = n0[2] + btVector3(segDist, 0.0, 0.0);
151 tgNode start3 = n0[3] + btVector3(segDist, 0.0, 0.0);
153 snake.
addPair(start0, start1,
"segment rod");
154 snake.
addPair(start2, start3,
"segment rod");
156 snake.
addPair(n0[5], start0,
"segment muscle front one");
157 snake.
addPair(n0[5], start2,
"segment muscle front two");
158 snake.
addPair(n0[7], start1,
"segment muscle front three");
159 snake.
addPair(n0[7], start3,
"segment muscle front four");
161 snake.
addPair(n0[8], start0,
"segment muscle rear one");
162 snake.
addPair(n0[8], start1,
"segment muscle rear two");
163 snake.
addPair(n0[9], start2,
"segment muscle rear three");
164 snake.
addPair(n0[9], start3,
"segment muscle rear four");
167 if (i == children.size() - 1)
169 btScalar segDist = (n0[0] - n1[0]).length() / 2.0;
170 tgNode end0 = n1[0] - btVector3(segDist, 0.0, 0.0);
171 tgNode end1 = n1[1] - btVector3(segDist, 0.0, 0.0);
172 tgNode end2 = n1[2] - btVector3(segDist, 0.0, 0.0);
173 tgNode end3 = n1[3] - btVector3(segDist, 0.0, 0.0);
175 snake.
addPair(end0, end1,
"segment rod");
176 snake.
addPair(end2, end3,
"segment rod");
178 snake.
addPair(n1[4], end0,
"segment muscle rear one");
179 snake.
addPair(n1[4], end2,
"segment muscle rear two");
180 snake.
addPair(n1[6], end1,
"segment muscle rear three");
181 snake.
addPair(n1[6], end3,
"segment muscle rear four");
183 snake.
addPair(n1[10], end0,
"segment muscle rear one");
184 snake.
addPair(n1[10], end1,
"segment muscle rear two");
185 snake.
addPair(n1[11], end2,
"segment muscle rear three");
186 snake.
addPair(n1[11], end3,
"segment muscle rear four");
189 snake.
addPair(mid0, mid1,
"segment rod");
190 snake.
addPair(mid2, mid3,
"segment rod");
192 snake.
addPair(n0[4], mid0,
"segment muscle rear one");
193 snake.
addPair(n0[4], mid2,
"segment muscle rear two");
194 snake.
addPair(n0[6], mid1,
"segment muscle rear three");
195 snake.
addPair(n0[6], mid3,
"segment muscle rear four");
197 snake.
addPair(n1[5], mid0,
"segment muscle front one");
198 snake.
addPair(n1[5], mid2,
"segment muscle front two");
199 snake.
addPair(n1[7], mid1,
"segment muscle front three");
200 snake.
addPair(n1[7], mid3,
"segment muscle front four");
202 snake.
addPair(n0[10], mid0,
"segment muscle rear one");
203 snake.
addPair(n0[10], mid1,
"segment muscle rear two");
204 snake.
addPair(n0[11], mid2,
"segment muscle rear three");
205 snake.
addPair(n0[11], mid3,
"segment muscle rear four");
207 snake.
addPair(n1[8], mid0,
"segment muscle rear one");
208 snake.
addPair(n1[8], mid1,
"segment muscle rear two");
209 snake.
addPair(n1[9], mid2,
"segment muscle rear three");
210 snake.
addPair(n1[9], mid3,
"segment muscle rear four");
227 const double half_length = c.rod_length / 2;
229 s.
addNode(-c.rod_space, -half_length, 0);
230 s.
addNode(-c.rod_space, half_length, 0);
231 s.
addNode( c.rod_space, -half_length, 0);
232 s.
addNode( c.rod_space, half_length, 0);
233 s.
addNode(0, -c.rod_space, -half_length);
234 s.
addNode(0, -c.rod_space, half_length);
235 s.
addNode(0, c.rod_space, -half_length);
236 s.
addNode(0, c.rod_space, half_length);
237 s.
addNode(-half_length, 0, c.rod_space);
238 s.
addNode( half_length, 0, c.rod_space);
239 s.
addNode(-half_length, 0, -c.rod_space);
240 s.
addNode( half_length, 0, -c.rod_space);
293 const tgRod::Config rodConfig(c.radius, c.density, c.friction,
294 c.rollFriction, c.restitution);
297 c.maxTens, c.targetVelocity);
305 btVector3 rotationPoint = btVector3(0, 0, 0);
306 btVector3 rotationAxis = btVector3(0, 1, 0);
307 double rotationAngle = M_PI/2;
308 s.
addRotation(rotationPoint, rotationAxis, rotationAngle);
310 s.move(btVector3(0, 10, 0));
313 addSegments(caterpillar, s, 2.0 * c.rod_length, 5);
314 addSegmentMuscles(caterpillar);
318 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
325 structureInfo.buildInto(*
this, world);
329 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
343 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
virtual void setup(tgWorld &world)
void addChild(tgStructure *child)
Definition of class tgRodInfo.
const std::vector< tgSpringCableActuator * > & getAllMuscles() const
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
Definition of class tgBasicActuatorInfo.
virtual void onVisit(const tgModelVisitor &r) const
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
virtual ~CaterpillarModel()
std::string tgString(std::string s, int i)
Definition of class tgStructure.
Definition of class tgStructureInfo.
Contains the definition of class CaterpillarModel. $Id$.
virtual void setup(tgWorld &world)
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
virtual void step(double dt)
void notifyStep(double dt)
std::vector< tgModel * > getDescendants() const
virtual void onVisit(tgModelVisitor &r)
void addNode(double x, double y, double z, std::string tags="")