30 #include "btBulletDynamicsCommon.h"
35 #include "tgcreator/tgLinearStringInfo.h"
44 #include "core/tgBaseString.h"
67 tgNode startNode = this->getFrom();
68 tgNode endNode = this->getTo();
70 btVector3 buildVec = (endNode - startNode);
71 double startLength = buildVec.length();
74 buildModel(world, thisString);
78 void tgRBStringInfo::buildModel(
tgWorld& world,
tgModel* thisString)
81 tgNode startNode = this->getFrom();
82 tgNode endNode = this->getTo();
87 const double stiffness = m_config.m_stringConfig.stiffness;
88 const double damping = m_config.m_stringConfig.damping;
89 tgLinearString::Config muscleConfig1(stiffness, damping,
false, -M_PI / 2.0);
90 tgLinearString::Config muscleConfig2(stiffness, damping,
false, M_PI / 2.0);
91 tgLinearString::Config muscleConfig3(stiffness, damping,
false, M_PI);
92 tgLinearString::Config muscleConfig4(stiffness, damping,
false, 0);
95 double v_size = m_config.m_minTotalLength / (double) m_config.m_segments;
98 btVector3 buildVec = (endNode - startNode);
99 double startLength = buildVec.length();
101 double spacing = (startLength - v_size / 2.0) / (double) m_config.m_segments;
103 btVector3 offset = buildVec.normalize() * spacing;
109 tgNode secNode(v_size * buildVec);
115 strRod.move(startNode);
120 for(
int i = 0; i < m_config.m_segments; i++) {
123 t->addTags(
tgString(
"srod num", i + 1));
124 t->move((i + 1)*offset);
129 std::vector<tgStructure*> children = snake.
getChildren();
130 for(
int i = 1; i < children.size(); i++) {
131 tgNodes n0 = children[i-1]->getNodes();
132 tgNodes n1 = children[i]->getNodes();
142 spec.addBuilder(
"rod",
new tgRodInfo(m_config.m_rodConfig));
144 spec.addBuilder(
"muscle v1",
new tgLinearStringInfo(muscleConfig1));
145 spec.addBuilder(
"muscle v2",
new tgLinearStringInfo(muscleConfig2));
146 spec.addBuilder(
"muscle v3",
new tgLinearStringInfo(muscleConfig3));
147 spec.addBuilder(
"muscle v4",
new tgLinearStringInfo(muscleConfig4));
155 structureInfo.buildInto(*thisString, world);
164 std::vector<tgPair*> linkerPairs;
167 tgNodes n0 = children[0]->getNodes();
172 std::size_t cldend = children.size() - 1;
173 tgNodes n1 = children[cldend]->getNodes();
174 linkerPairs.push_back(
new tgPair(n1[1], endNode,
tgString(
"anchor seg", cldend - 1) +
tgString(
" seg", cldend)));
178 std::vector <tgRigidInfo*> allRigids(structureInfo.getAllRigids());
179 allRigids.push_back(getToRigidInfo());
180 allRigids.push_back(getFromRigidInfo());
183 std::vector <tgConnectorInfo* > linkerInfo;
186 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig1, *linkerPairs[0]));
187 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig1, *linkerPairs[1]));
189 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig2, *linkerPairs[0]));
190 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig2, *linkerPairs[1]));
192 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig3, *linkerPairs[0]));
193 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig3, *linkerPairs[1]));
195 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig4, *linkerPairs[0]));
196 linkerInfo.push_back(
new tgLinearStringInfo(muscleConfig4, *linkerPairs[1]));
198 for (std::size_t i = 0; i < linkerInfo.size(); i++)
200 linkerInfo[i]->chooseRigids(allRigids);
201 linkerInfo[i]->initConnector(world);
203 tgModel* m = linkerInfo[i]->createModel(world);
204 m->setTags(linkerInfo[i]->getTags());
211 for (std::size_t i = 0; i < linkerInfo.size(); i++)
213 delete linkerInfo[i];
217 for (std::size_t i = 0; i < linkerPairs.size(); i++)
219 delete linkerPairs[i];
225 std::cout <<
"StructureInfo:" << std::endl;
226 std::cout << structureInfo << std::endl;
228 std::cout <<
"Model: " << std::endl;
229 std::cout << *thisString << std::endl;
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
void addChild(tgModel *pChild)
Convenience function for combining strings with ints, mostly for naming structures.
Definition of class tgPair.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Definition of class tgConnectorInfo.
Definition of class tgNode.
std::string tgString(std::string s, int i)
Definition of class tgStructure.
Definition of class tgStructureInfo.
Rand seeding simular to the evolution and terrain classes.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
Contains the definition of class tgRBStringInfo. A string with small rigid bodies to create contact d...
void addNode(double x, double y, double z, std::string tags="")