41 #include "LinearMath/btVector3.h"
50 tetra.
addNode(0.0, v_size, v_size / 2.0);
51 tetra.
addNode(-v_size, 0.0, -v_size);
52 tetra.
addNode(v_size, 0.0, -v_size);
53 #if (0) // Attempt at compliant rib attachments
54 tetra.
addNode(-v_size / 5.0, 0.0, 0.0);
55 tetra.
addNode(v_size / 5.0, 0.0, 0.0);
63 void ellipseNodes(
tgStructure& tetra,
double a,
double b,
double startT,
double endT,
size_t n)
65 double rodL = (endT - startT) / (
double) n;
67 for(
size_t i = 0; i < n; i++)
69 double x = a * cos( startT + i * rodL);
70 double y = b * sin( startT + i * rodL);
72 tgNode node( btVector3( x, y, 0.0));
77 double x = a * cos( startT + (n - 1) * rodL);
78 double y = b * sin( startT + (n - 1) * rodL) - 0.5;
79 tgNode node( btVector3( x, y, 0.0));
89 tetra.
addPair(0,3,
"right rod");
90 #if (0) // extra connection points for muscles
91 tetra.
addPair(0,4,
"leftRib rod");
92 tetra.
addPair(0,5,
"rightRib rod");
102 std::cout <<
"Nodes size is " << n << std::endl;
103 for(std::size_t i = 1; i < n; i++) {
109 const tgStructure& ribs,
double edge,
size_t segmentCount)
111 const btVector3 offset(0, 0, -edge * 1.3);
112 const btVector3 rotAxis(0, 1.0, 0);
113 for (
size_t i = 0; i < segmentCount; ++i)
127 size_t r02End = r02.getNodes().size();
130 t->
addPair(t01[0], r01[0],
"multiMuscle connect");
131 t->
addPair(t01[0], r02[0],
"multiMuscle connect");
133 t->
addPair(t01[0], r01[0],
"rod connect");
134 t->
addPair(t01[0], r02[0],
"rod connect");
139 t->addTags(
tgString(
"segment num", i + 1));
140 t->move((i + 1) * offset);
149 const std::vector<tgStructure*> children = snake.
getChildren();
150 for (
size_t i = 1; i < children.size(); ++i)
152 tgNodes n0 = children[i-1]->getNodes();
153 tgNodes n1 = children[i ]->getNodes();
155 const std::vector<tgStructure*> subChildren1 = children[i-1]->getChildren();
156 const std::vector<tgStructure*> subChildren2 = children[i]->getChildren();
158 tgNodes r10 = subChildren1[0]->getNodes();
159 tgNodes r11 = subChildren1[1]->getNodes();
160 tgNodes r20 = subChildren2[0]->getNodes();
161 tgNodes r21 = subChildren2[1]->getNodes();
182 std::cout <<
"StructureInfo:" << std::endl
183 << structureInfo << std::endl
184 <<
"Model: " << std::endl
185 << model << std::endl;
187 const std::vector<tgSpringCableActuator*> outerMuscles =
189 for (
size_t i = 0; i < outerMuscles.size(); ++i)
192 assert(pMuscle != NULL);
193 std::cout <<
"Outer muscle: " << *pMuscle << std::endl;
199 RibModel::RibModel(
int segments) :
204 RibModel::~RibModel()
214 addNodes(vertebrae, v_size);
219 vertebrae.move(btVector3(0.0, 2 * v_size, v_size * m_segments));
222 double majorAxis = 6.0;
223 double minorAxis = 4.0;
224 double startTheta = M_PI / 2.0;
225 double endTheta = 5.0 * M_PI / 4.0;
229 ellipseNodes(ribs, majorAxis, minorAxis, startTheta, endTheta, segs);
232 #if (0) // Attempt at compliant rib attachments
233 ribs.move(btVector3(v_size / 3.0, 2 * v_size - minorAxis, v_size * m_segments));
235 ribs.move(btVector3(0.0, 2 * v_size - minorAxis -.3, v_size * m_segments));
239 addSegments(snake, vertebrae, ribs, v_size, m_segments);
241 snake.move(btVector3(0.0, majorAxis, 0.0));
247 const double density = 4.2 / 300.0;
248 const double radius = 0.5;
249 const double friction = 0.5;
250 const double rollFriction = 0.5;
251 const double restitution = 0.0;
253 const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
255 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
257 const double pretension = 0.0;
258 const bool hist =
false;
266 #if (0) // Compliant Rib Attachments
267 const double stiffness = 1000;
268 const double damping = .01 * stiffness;
288 m_allMuscles = find<tgSpringCableActuator> (
"muscleAct");
289 m_allSegments = find<tgModel> (
"segment");
292 trace(structureInfo, *
this);
310 throw std::invalid_argument(
"dt is not positive");
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Implements a spine model with a rib cage.
virtual void setup(tgWorld &world)
Convenience function for combining strings with ints, mostly for naming structures.
Utility class for class casting and filtering collections by type.
virtual void setup(tgWorld &world)
const tgNodes & getNodes() const
Definition of class tgBasicActuatorInfo.
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)
std::string tgString(std::string s, int i)
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)
virtual void step(double dt)
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")