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 * 0.6);
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 actuator");
103 snake.
addPair(n0[1], n1[1],
"outer left actuator");
104 snake.
addPair(n0[2], n1[2],
"outer top actuator");
106 snake.
addPair(n0[0], n1[3],
"inner right actuator");
107 snake.
addPair(n0[1], n1[3],
"inner left actuator");
108 snake.
addPair(n0[2], n1[3],
"inner top actuator");
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 = .00311;
158 const double radius = 0.5;
161 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
173 allActuators = tgCast::filter<tgModel, tgBasicActuator> (
getDescendants());
174 mapActuators(actuatorMap, *
this);
176 trace(structureInfo, *
this);
186 throw std::invalid_argument(
"dt is not positive");
197 const std::vector<tgBasicActuator*>&
200 const ActuatorMap::const_iterator it = actuatorMap.find(key);
201 if (it == actuatorMap.end())
203 throw std::invalid_argument(
"Key '" + key +
"' not found in actuator map");
const std::vector< tgStructure * > & getChildren() const
virtual void setup(tgWorld &world)
std::map< std::string, std::vector< tgBasicActuator * > > ActuatorMap
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.
Definition of class tgBasicActuatorInfo.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
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.
const std::vector< tgBasicActuator * > & getActuators(const std::string &key) const
Rand seeding simular to the evolution and terrain classes.
Definition of class tgBuildSpec.
Definition of class tgRigidAutoCompound.
void notifyStep(double dt)
virtual void step(double dt)
std::vector< tgModel * > getDescendants() const
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")