19 #ifndef CONNECTOR_TEST_MODEL_H
20 #define CONNECTOR_TEST_MODEL_H
23 #include "core/tgLinearString.h"
28 #include "btBulletDynamicsCommon.h"
34 #include "tgcreator/tgLinearStringInfo.h"
35 #include "tgcreator/tgRBStringInfo.h"
41 #include "core/tgUtil.h"
59 virtual void setup(
tgWorld* world)
65 const double density = 4.2/300.0;
66 const double radius = 0.5;
69 tgLinearString::Config muscleConfig(1000, 10);
72 const double strRadius = 0.2;
73 const double strDensity = 2;
76 const double stiffness = 1000.0;
77 const double damping = .01*stiffness;
78 const int segments = 10;
79 const tgLinearString::Config stringConfig(stiffness, damping);
80 const tgRBStringInfo::Config rbConfig(segments, strRodConfig, stringConfig, 3.0);
84 double height = tgUtil::round(std::sqrt(3.0)/2 * edge);
86 std::cout <<
"edge: " << edge <<
"; height: " << height << std::endl;
94 tetra.
addNode(0,height/2, tgUtil::round(std::sqrt(3.0)/2 * height));
96 tetra.
addPair(0,1,
"back bottom rod");
97 tetra.
addPair(0,2,
"back right rod");
98 tetra.
addPair(0,3,
"front right rod");
99 tetra.
addPair(1,2,
"back left rod");
100 tetra.
addPair(1,3,
"front left rod");
101 tetra.
addPair(2,3,
"front top rod");
104 tetra.move(btVector3(0.0,2.0,100.0));
108 btVector3 offset(0,0,-edge * 1.15);
109 for(
int i = 0; i < m_segments; i++) {
112 t->addTags(
tgString(
"segment", i + 1));
113 t->move((i + 1)*offset);
119 std::vector<tgStructure*> children = snake.
getChildren();
120 for(
int i = 1; i < children.size(); i++) {
121 tgNodes n0 = children[i-1]->getNodes();
122 tgNodes n1 = children[i]->getNodes();
124 snake.
addPair(n0[0], n1[0],
"outer right muscle");
125 snake.
addPair(n0[1], n1[1],
"outer left muscle");
126 snake.
addPair(n0[2], n1[2],
"outer top muscle");
128 snake.
addPair(n0[0], n1[3],
"inner right muscle");
129 snake.
addPair(n0[1], n1[3],
"inner left muscle");
130 snake.
addPair(n0[2], n1[3],
"inner top muscle");
136 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
146 structureInfo.buildInto(
this, world);
150 allMuscles = tgCast::filter<tgModel, tgLinearString> (
getDescendants());
154 muscleMap[
"inner left"] = this->find<tgLinearString>(
"inner left muscle");
155 muscleMap[
"inner right"] = this->find<tgLinearString>(
"inner right muscle");
156 muscleMap[
"inner top"] = this->find<tgLinearString>(
"inner top muscle");
157 muscleMap[
"outer left"] = this->find<tgLinearString>(
"outer left muscle");
158 muscleMap[
"outer right"] = this->find<tgLinearString>(
"outer right muscle");
159 muscleMap[
"outer top"] = this->find<tgLinearString>(
"outer top muscle");
162 std::cout <<
"StructureInfo:" << std::endl;
163 std::cout << structureInfo << std::endl;
165 std::cout <<
"Model: " << std::endl;
166 std::cout << *
this << std::endl;
170 std::vector<tgLinearString*> outerMuscles = find<tgLinearString>(
"outer");
171 for(
int i = 0; i < outerMuscles.size(); i++) {
172 std::cout <<
"Outer muscle: " << *(outerMuscles[i]) << std::endl;
188 void changeMuscle (
double length,
double dt)
190 for(
int i = 0; i < allMuscles.size(); i++){
191 allMuscles[i]->setRestLength(length, dt);
194 const std::vector<tgLinearString*> getMuscles (std::string key)
196 return muscleMap[key];
199 const int getSegments()
205 std::vector<tgLinearString*> allMuscles;
206 std::map<std::string, std::vector<tgLinearString*> > muscleMap;
208 const int m_segments;
const std::vector< tgStructure * > & getChildren() const
void addChild(tgStructure *child)
Definition of class tgRodInfo.
Definition of tgSubject class.
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 tgModel.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
std::string tgString(std::string s, int i)
Definition of class tgStructure.
Definition of class tgStructureInfo.
Contains the definition of class tgRBString. A string with small rigid bodies to create contact dynam...
Definition of class tgBuildSpec.
Definition of class tgRigidAutoCompound.
void notifyStep(double dt)
virtual void step(double dt)
std::vector< tgModel * > getDescendants() const
void addNode(double x, double y, double z, std::string tags="")