Exemple #1
0
TEST(GeoLib, SearchNearestPointsInDenseGrid)
{
	const std::size_t i_max(50), j_max(50), k_max(50);
	std::vector<GeoLib::Point*> pnts(i_max*j_max*k_max);

	// fill the vector with equi-distant points in the
	// cube [0,(i_max-1)/i_max] x [0,(j_max-1)/j_max] x [0,(k_max-1)/k_max]
	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				pnts[offset1 + k] = new GeoLib::Point(
					std::array<double,3>({{static_cast<double>(i) / i_max,
						static_cast<double>(j) / j_max,
						static_cast<double>(k) / k_max}}), offset1+k);
			}
		}
	}

	// create the grid
	GeoLib::Grid<GeoLib::Point>* grid(nullptr);
	ASSERT_NO_THROW(grid = new GeoLib::Grid<GeoLib::Point> (pnts.begin(), pnts.end()));

	// search point (1,1,1) is outside of the point set
	GeoLib::Point search_pnt(std::array<double,3>({{1,1,1}}), 0);
	GeoLib::Point* res(grid->getNearestPoint(search_pnt));
	ASSERT_EQ(i_max*j_max*k_max-1, res->getID());
	ASSERT_NEAR(sqrt(3.0)/50.0, sqrt(MathLib::sqrDist(*res, search_pnt)), std::numeric_limits<double>::epsilon());

	// search point (0,1,1) is outside of the point set
	search_pnt[0] = 0;
	res = grid->getNearestPoint(search_pnt);
	ASSERT_EQ(j_max*k_max - 1, res->getID());
	ASSERT_NEAR(sqrt(2.0)/50.0, sqrt(MathLib::sqrDist(*res, search_pnt)), std::numeric_limits<double>::epsilon());

	// search point (0.5,1,1) is outside of the point set
	search_pnt[0] = 0.5;
	res = grid->getNearestPoint(search_pnt);
	ASSERT_EQ(j_max*k_max*(i_max/2 + 1) - 1, res->getID());
	ASSERT_NEAR(sqrt(2.0)/50.0, sqrt(MathLib::sqrDist(*res, search_pnt)), std::numeric_limits<double>::epsilon());

	// checking only every fourth point per direction to reduce the run time of
	// the test
	for (std::size_t i(0); i < i_max; i=i+4) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j=j+4) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k=k+4) {
				res = grid->getNearestPoint(*pnts[offset1+k]);
				ASSERT_EQ(offset1+k, res->getID());
				ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, *pnts[offset1+k])), 0.0, std::numeric_limits<double>::epsilon());
			}
		}
	}

	delete grid;
	std::for_each(pnts.begin(), pnts.end(), std::default_delete<GeoLib::Point>());
}
Exemple #2
0
TEST(GeoLib, SearchNearestPointsInDenseGrid)
{
	const std::size_t i_max(50), j_max(50), k_max(50);
	std::vector<GeoLib::PointWithID*> pnts(i_max*j_max*k_max);

	// fill the vector with equi-distant points in the
	// cube [0,(i_max-1)/i_max] x [0,(j_max-1)/j_max] x [0,(k_max-1)/k_max]
	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				pnts[offset1 + k] = new GeoLib::PointWithID(static_cast<double>(i) / i_max,
						static_cast<double>(j) / j_max, static_cast<double>(k) / k_max, offset1+k);
			}
		}
	}

	// create the grid
	GeoLib::Grid<GeoLib::PointWithID>* grid(nullptr);
	ASSERT_NO_THROW(grid = new GeoLib::Grid<GeoLib::PointWithID> (pnts.begin(), pnts.end()));

	// search point (1,1,1) is outside of the point set
	GeoLib::PointWithID search_pnt(1,1,1, 0);
	GeoLib::PointWithID* res(grid->getNearestPoint(search_pnt.getCoords()));
	ASSERT_EQ(res->getID(), i_max*j_max*k_max-1);
	ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, search_pnt)), sqrt(3.0)/50.0, std::numeric_limits<double>::epsilon());

	// search point (0,1,1) is outside of the point set
	search_pnt[0] = 0;
	res = grid->getNearestPoint(search_pnt.getCoords());
	ASSERT_EQ(res->getID(), j_max*k_max - 1);
	ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, search_pnt)), sqrt(2.0)/50.0, std::numeric_limits<double>::epsilon());

	// search point (0.5,1,1) is outside of the point set
	search_pnt[0] = 0.5;
	res = grid->getNearestPoint(search_pnt.getCoords());
	ASSERT_EQ(res->getID(), j_max*k_max*(i_max/2 + 1) - 1);
	ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, search_pnt)), sqrt(2.0)/50.0, std::numeric_limits<double>::epsilon());

	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				res = grid->getNearestPoint(pnts[offset1+k]->getCoords());
				ASSERT_EQ(res->getID(), offset1+k);
				ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, *pnts[offset1+k])), 0.0, std::numeric_limits<double>::epsilon());
			}
		}
	}

	delete grid;
	std::for_each(pnts.begin(), pnts.end(), std::default_delete<GeoLib::PointWithID>());
}
Exemple #3
0
float SAHer::Objective(const cv::Rect &roi) {
    float wg = .98, wt = 1 - wg;
    int blur_range = 11;
    cv::Point lu(std::max(0, roi.x - 2*blur_range), std::max(0, roi.y - 2*blur_range)), rd(std::min(w_, roi.x + roi.width + 2*blur_range), std::min(h_, roi.y + roi.height + 2*blur_range));
    cv::Point offset1(blur_range, blur_range);

    if ( roi.x - blur_range < 0) {
        offset1.x = 0;
    } else if (roi.x - blur_range*2 < 0) {
        offset1.x = roi.x - blur_range;
    }
    if ( roi.y - blur_range < 0) {
        offset1.y = 0;
    } else if (roi.y - blur_range*2 < 0) {
        offset1.y = roi.y - blur_range;
    }
    cv::Rect new_roi(lu, rd);
    cv::Mat src_roi = src_image_(new_roi), halftone_roi = halftone_image_(new_roi);

    cv::Rect sub_roi = cv::Rect(offset1.x, offset1.y, std::min(roi.width + 2*blur_range, new_roi.width - offset1.x), std::min(roi.height + 2*blur_range, new_roi.height - offset1.y));
    //info() << "begin" << roi.x << roi.y << roi.width << roi.height << offset1.x << offset1.y << new_roi.x << new_roi.y << new_roi.width << new_roi.height;
    cv::Mat ssim_map = ssim(src_roi, halftone_roi)(sub_roi);
    //info () << "end";
    float mean_ssim = float(cv::mean(ssim_map)[0]);

    cv::Mat gI, gH, se;
    cv::GaussianBlur(src_roi, gI, cv::Size(blur_range, blur_range), 0);
    cv::GaussianBlur(halftone_roi, gH, cv::Size(blur_range, blur_range), 0);
    cv::subtract(gI(sub_roi), gH(sub_roi), se);
    cv::multiply(se, se, se);

    float gaussian_diff = float(cv::mean(se)[0]);

    return wg*gaussian_diff + wt*(1.f - mean_ssim);
}
TEST_F(DisplayItemPropertyTreeBuilderTest, Nested2DTranslation)
{
    FloatSize offset1(10, -40);
    TransformationMatrix translation1;
    translation1.translate(offset1.width(), offset1.height());
    FloatSize offset2(80, 80);
    TransformationMatrix translation2;
    translation2.translate(offset2.width(), offset2.height());

    // These drawings should share a transform node but have different range
    // record offsets.
    processDummyDisplayItem();
    auto transform1 = processBeginTransform3D(translation1);
    processDummyDisplayItem();
    auto transform2 = processBeginTransform3D(translation2);
    processDummyDisplayItem();
    processEndTransform3D(transform2);
    processEndTransform3D(transform1);
    finishPropertyTrees();

    // There should only be a root transform node.
    ASSERT_EQ(1u, transformTree().nodeCount());
    EXPECT_TRUE(transformTree().nodeAt(0).isRoot());

    // Check that the range records have the right offsets.
    EXPECT_THAT(rangeRecordsAsStdVector(), ElementsAre(
        AllOf(hasRange(0, 1), hasTransformNode(0), hasOffset(FloatSize())),
        AllOf(hasRange(2, 3), hasTransformNode(0), hasOffset(offset1)),
        AllOf(hasRange(4, 5), hasTransformNode(0), hasOffset(offset1 + offset2))));
}
Exemple #5
0
void qxgeditScale::setOffset1 ( unsigned short iOffset1 )
{
	if (m_iOffset1 != iOffset1) {
		m_iOffset1  = iOffset1;
		update();
		emit offset1Changed(offset1());
	}
}
void CPlayerStateSwim_WaterTestProxy::DebugDraw(const CPlayer& player, const Vec3& referencePosition)
{
	// DEBUG RENDERING
	const SPlayerStats& stats = *player.GetActorStats();
	const bool debugSwimming = (g_pGameCVars->cl_debugSwimming != 0);
	if (debugSwimming && (m_playerWaterLevel > -10.0f) && (m_playerWaterLevel < 10.0f))
	{
		const Vec3 surfacePosition(referencePosition.x, referencePosition.y, m_waterLevel);

		const Vec3 vRight(player.GetBaseQuat().GetColumn0());

		const static ColorF referenceColor(1,1,1,1);
		const static ColorF surfaceColor1(0,0.5f,1,1);
		const static ColorF surfaceColor0(0,0,0.5f,0);
		const static ColorF bottomColor(0,0.5f,0,1);

		gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(referencePosition, 0.1f, referenceColor);

		gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(referencePosition, surfaceColor1, surfacePosition, surfaceColor1, 2.0f);
		gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(surfacePosition, 0.2f, surfaceColor1);
		gEnv->pRenderer->DrawLabel(referencePosition + vRight * 0.5f, 1.5f, "WaterLevel %3.2f (Head underwater: %d)", m_playerWaterLevel, m_headUnderwater ? 1 : 0);

		const static int lines = 16;
		const static float radius0 = 0.5f;
		const static float radius1 = 1.0f;
		const static float radius2 = 2.0f;
		for (int i = 0; i < lines; ++i)
		{
			float radians = ((float)i / (float)lines) * gf_PI2;
			Vec3 offset0(radius0 * cos_tpl(radians), radius0 * sin_tpl(radians), 0);
			Vec3 offset1(radius1 * cos_tpl(radians), radius1 * sin_tpl(radians), 0);
			Vec3 offset2(radius2 * cos_tpl(radians), radius2 * sin_tpl(radians), 0);
			gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(surfacePosition+offset0, surfaceColor0, surfacePosition+offset1, surfaceColor1, 2.0f);
			gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(surfacePosition+offset1, surfaceColor1, surfacePosition+offset2, surfaceColor0, 2.0f);
		}

		if (m_bottomLevel > 0.0f)
		{
			const Vec3 bottomPosition(referencePosition.x, referencePosition.y, m_bottomLevel);

			gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(referencePosition, bottomColor, bottomPosition, bottomColor, 2.0f);
			gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(bottomPosition, 0.2f, bottomColor);
			gEnv->pRenderer->DrawLabel(bottomPosition + Vec3(0,0,0.5f) - vRight * 0.5f, 1.5f, "BottomDepth %3.3f", m_waterLevel - m_bottomLevel);
		}
	}
}
Exemple #7
0
TEST(GeoLib, InsertManyPointsInGrid)
{
	const std::size_t i_max(100), j_max(100), k_max(100);
	std::vector<GeoLib::Point*> pnts(i_max*j_max*k_max);

	// fill the vector with points
	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				pnts[offset1 + k] = new GeoLib::Point(static_cast<double>(i) / i_max,
						static_cast<double>(j) / j_max, static_cast<double>(k) / k_max);
			}
		}
	}

	ASSERT_NO_THROW(GeoLib::Grid<GeoLib::Point> grid(pnts.begin(), pnts.end()));
}
Exemple #8
0
  void Diagcat::evaluateMX(const MXPtrV& input, MXPtrV& output, const MXPtrVV& fwdSeed,
                           MXPtrVV& fwdSens, const MXPtrVV& adjSeed, MXPtrVV& adjSens,
                           bool output_given) {
    int nfwd = fwdSens.size();
    int nadj = adjSeed.size();

    // Non-differentiated output
    if (!output_given) {
      *output[0] = diagcat(getVector(input));
    }

    // Forward sensitivities
    for (int d = 0; d<nfwd; ++d) {
      *fwdSens[d][0] = diagcat(getVector(fwdSeed[d]));
    }

    // Quick return?
    if (nadj==0) return;

    // Get offsets for each row and column
    vector<int> offset1(ndep()+1, 0);
    vector<int> offset2(ndep()+1, 0);
    for (int i=0; i<ndep(); ++i) {
      int ncol = dep(i).sparsity().size2();
      int nrow = dep(i).sparsity().size1();
      offset2[i+1] = offset2[i] + ncol;
      offset1[i+1] = offset1[i] + nrow;
    }

    // Adjoint sensitivities
    for (int d=0; d<nadj; ++d) {
      MX& aseed = *adjSeed[d][0];
      vector<MX> s = diagsplit(aseed, offset1, offset2);
      aseed = MX();
      for (int i=0; i<ndep(); ++i) {
        adjSens[d][i]->addToSum(s[i]);
      }
    }
  }
void BigDoxieNoFeet::addSegments(tgStructure& puppy, tgStructure& vertebra, tgStructure& hip, tgStructure& leg, tgStructure& foot, 
                 double r){ 
    const double offsetDist = r+1; 
    const double offsetDist2 = offsetDist*8; 
    const double offsetDist3 = offsetDist2+4;
    const double yOffset_leg = -(2*r+1); 
    const double yOffset_foot = -(2*r+6);

    //Vertebrae
    btVector3 offset(offsetDist,0.0,0);
    //Hips
    btVector3 offset1(offsetDist*2,0.0,offsetDist);
    btVector3 offset2(offsetDist2,0.0,offsetDist);
    btVector3 offset3(offsetDist*2,0.0,-offsetDist);
    btVector3 offset4(offsetDist2,0.0,-offsetDist);
    //Lower legs
    btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
    btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
    btVector3 offset7(r*2,yOffset_leg,offsetDist);
    btVector3 offset8(r*2,yOffset_leg,-offsetDist);
    //Feet
    btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
    btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
    btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
    btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);

    for(std::size_t i = 0; i < m_segments; i++) { //Connect segments for spine of puppy
        tgStructure* t = new tgStructure (vertebra);
        t->addTags(tgString("spine segment num", i + 1));
        t->move((i + 1)*offset);

        if (i % 2 == 1){

            t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);

        }
        else{

            t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);

        }

        puppy.addChild(t); //Add a segment to the puppy
    }

     for(std::size_t i = m_segments; i < (m_segments + 2); i++) {//deal with right hip and shoulder first
        tgStructure* t = new tgStructure (hip);
        t->addTags(tgString("segment num", i + 1));
 
        if(i % 2 == 0){
            t->move(offset2);
            t->addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);

        }
        else{
            t->move(offset1);
            t->addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
        }

        puppy.addChild(t); //Add a segment to the puppy
    }

    for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {//deal with left hip and shoulder now
        tgStructure* t = new tgStructure (hip);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0){
            t->move(offset4);
        }
        else{
            t->move(offset3);
        }

        puppy.addChild(t); //Add a segment to the puppy

    }

     for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {//right front and back legs
        tgStructure* t = new tgStructure (leg);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0){
            t->move(offset5);
            t->addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);

        }
        else{
            t->move(offset7);
            t->addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
            //the rotations for the legs are a remnant of the earlier design. Removing them now 
            //would mean changing all my muscle attachments. I will do this someday. 

        }

        puppy.addChild(t); //Add a segment to the puppy
    }

    for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {//left front and back legs
        tgStructure* t = new tgStructure (leg);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0){
            t->move(offset6);
            t->addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);

        }
        else{
            t->move(offset8);
            t->addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
        }

        puppy.addChild(t); //Add a segment to the puppy
    }

    /*for(std::size_t i = (m_segments + m_hips + m_legs); i < (m_segments + m_hips + m_legs + 2); i++) {//right front and back feet
        tgStructure* t = new tgStructure (foot);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0){
            t->move(offset9);
            t->addRotation(btVector3(offsetDist3+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);

        }
        else{
            t->move(offset11);
            t->addRotation(btVector3(r*2+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
        }

        puppy.addChild(t); //Add a segment to the puppy
    }

    for(std::size_t i = (m_segments + m_hips + m_legs + 2); i < (m_segments + m_hips + m_legs + m_feet); i++) {//left front and back feet
        tgStructure* t = new tgStructure (foot);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0){
            t->move(offset10);
            t->addRotation(btVector3(offsetDist3+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);

        }
        else{
            t->move(offset12);
            t->addRotation(btVector3(r*2+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
        }

        puppy.addChild(t); //Add a segment to the puppy
    } */
}
Exemple #10
0
//---------------------------------------------------------------------
void PlayPen_testPoseAnimationWithoutNormals::setupContent()
{
	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
	Vector3 dir(-1, -1, 0.5);
	dir.normalise();
	Light* l = mSceneMgr->createLight("light1");
	l->setType(Light::LT_DIRECTIONAL);
	l->setDirection(dir);

	MeshPtr mesh = MeshManager::getSingleton().load("cube.mesh", 
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		
	String newName = "testposenonormals.mesh";
	mesh = mesh->clone(newName);


	SubMesh* sm = mesh->getSubMesh(0);
	// Re-organise geometry since this mesh has no animation and all 
	// vertex elements are packed into one buffer
	VertexDeclaration* newDecl = 
		sm->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(false, true, false);
	sm->vertexData->reorganiseBuffers(newDecl);

	// create 2 poses
	Pose* pose = mesh->createPose(1, "pose1");
	// Pose1 moves vertices 0, 1, 2 and 3 upward 
	Vector3 offset1(0, 50, 0);
	pose->addVertex(0, offset1);
	pose->addVertex(1, offset1);
	pose->addVertex(2, offset1);
	pose->addVertex(3, offset1);

	pose = mesh->createPose(1, "pose2");
	// Pose2 moves vertices 3, 4, and 5 to the right
	// Note 3 gets affected by both
	Vector3 offset2(100, 0, 0);
	pose->addVertex(3, offset2);
	pose->addVertex(4, offset2);
	pose->addVertex(5, offset2);


	Animation* anim = mesh->createAnimation("poseanim", 20.0f);
	VertexAnimationTrack* vt = anim->createVertexTrack(1, sm->vertexData, VAT_POSE);
	
	// Frame 0 - no effect 
	VertexPoseKeyFrame* kf = vt->createVertexPoseKeyFrame(0);

	// Frame 1 - bring in pose 1 (index 0)
	kf = vt->createVertexPoseKeyFrame(3);
	kf->addPoseReference(0, 1.0f);

	// Frame 2 - remove all 
	kf = vt->createVertexPoseKeyFrame(6);

	// Frame 3 - bring in pose 2 (index 1)
	kf = vt->createVertexPoseKeyFrame(9);
	kf->addPoseReference(1, 1.0f);

	// Frame 4 - remove all
	kf = vt->createVertexPoseKeyFrame(12);


	// Frame 5 - bring in pose 1 at 50%, pose 2 at 100% 
	kf = vt->createVertexPoseKeyFrame(15);
	kf->addPoseReference(0, 0.5f);
	kf->addPoseReference(1, 1.0f);

	// Frame 6 - bring in pose 1 at 100%, pose 2 at 50% 
	kf = vt->createVertexPoseKeyFrame(18);
	kf->addPoseReference(0, 1.0f);
	kf->addPoseReference(1, 0.5f);

	// Frame 7 - reset
	kf = vt->createVertexPoseKeyFrame(20);

	// Export the mesh
	DataStreamPtr stream = Root::getSingleton().createFileStream(newName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
	MeshSerializer ser;
	ser.exportMesh(mesh.get(), stream);
	stream->close();

	// Unload old mesh to force reload
	MeshManager::getSingleton().remove(mesh->getHandle());
	mesh->unload();
	mesh.setNull();

	Entity*  e;
	AnimationState* animState;
	// software pose
	e = mSceneMgr->createEntity("test2", newName);
	mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(150,0,0))->attachObject(e);
	animState = e->getAnimationState("poseanim");
	animState->setEnabled(true);
	animState->setWeight(1.0f);
	mAnimStateList.push_back(animState);
	
	// test hardware pose
	e = mSceneMgr->createEntity("test", newName);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(e);
	e->setMaterialName("Examples/HardwarePoseAnimation");
	animState = e->getAnimationState("poseanim");
	animState->setEnabled(true);
	animState->setWeight(1.0f);
	mAnimStateList.push_back(animState);
	

	mCamera->setNearClipDistance(0.5);

	Plane plane;
	plane.normal = Vector3::UNIT_Y;
	plane.d = 200;
	MeshManager::getSingleton().createPlane("Myplane",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
		1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);
	Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
	pPlaneEnt->setMaterialName("2 - Default");
	pPlaneEnt->setCastShadows(false);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

	mCamera->setPosition(0,-200,-300);
	mCamera->lookAt(0,0,0);

}
Exemple #11
0
// Draw curve.
void qxgeditScale::paintEvent ( QPaintEvent *pPaintEvent )
{
	QPainter painter(this);

	const int h  = height();
	const int w  = width();

	const int h2 = h >> 1;

	const int x1 = 6 + int((m_iBreak1 * (w - 12)) >> 7);
	const int x2 = 6 + int((m_iBreak2 * (w - 12)) >> 7);
	const int x3 = 6 + int((m_iBreak3 * (w - 12)) >> 7);
	const int x4 = 6 + int((m_iBreak4 * (w - 12)) >> 7);

	const int y1 = h2 - ((int(m_iOffset1) - 64) * (h - 12) >> 7);
	const int y2 = h2 - ((int(m_iOffset2) - 64) * (h - 12) >> 7);
	const int y3 = h2 - ((int(m_iOffset3) - 64) * (h - 12) >> 7);
	const int y4 = h2 - ((int(m_iOffset4) - 64) * (h - 12) >> 7);

	m_poly.putPoints(0, 6,
		0,  y1,
		x1, y1,
		x2, y2,
		x3, y3,
		x4, y4,
		w,  y4);

	const QPalette& pal = palette();
	const bool bDark = (pal.window().color().value() < 0x7f);
	const QColor& rgbLite = (bDark ? Qt::darkYellow : Qt::yellow);
	if (bDark)
		painter.fillRect(0, 0, w, h, pal.dark().color());

	painter.setRenderHint(QPainter::Antialiasing, true);
	painter.setPen(bDark ? Qt::gray : Qt::darkGray);

	const QPen oldpen(painter.pen());
	QPen dotpen(oldpen);
	dotpen.setStyle(Qt::DotLine);
	painter.setPen(dotpen);
	painter.drawLine(0, h2, w, h2);
	painter.setPen(oldpen);

	painter.drawPolyline(m_poly);

	painter.setBrush(rgbLite); // pal.midlight().color()
	painter.drawRect(nodeRect(1));
	painter.drawRect(nodeRect(2));
	painter.drawRect(nodeRect(3));
	painter.drawRect(nodeRect(4));

#ifdef CONFIG_DEBUG_0
	painter.drawText(QFrame::rect(),
		Qt::AlignTop|Qt::AlignHCenter,
		tr("Break (%1,%2,%3,%4) Offset(%5,%6,%7,%8)")
		.arg(int(break1()))
		.arg(int(break2()))
		.arg(int(break3()))
		.arg(int(break4()))
		.arg(int(offset1()) - 64)
		.arg(int(offset2()) - 64)
		.arg(int(offset3()) - 64)
		.arg(int(offset4()) - 64));
#endif

	painter.setRenderHint(QPainter::Antialiasing, false);
	painter.end();

	QFrame::paintEvent(pPaintEvent);
}
Exemple #12
0
void BigPuppy::setup(tgWorld& world)
{
    //Rod and Muscle configuration. Todo: make these into structs in a namespace block!

    const double density = 4.2/300.0;	//Note: this needs to be high enough or things fly apart...
    const double radius = 0.5;
    const double rod_space = 10.0;
    const double friction = 0.5;
    const double rollFriction = 0.0;
    const double restitution = 0.0;
    const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);

    const double radius2 = 0.15;
    const double density2 = 1;	// Note: This needs to be high enough or things fly apart...
    const tgRod::Config rodConfig2(radius2, density2);

    const double stiffness = 1000.0;
    const double damping = .01*stiffness;
    const double pretension = 0.0;
    const bool   history = false;
    const double maxTens = 7000.0;
    const double maxSpeed = 12.0;

    const double passivePretension = 700; // 5 N

#ifdef USE_KINEMATIC

    const double mRad = 1.0;
    const double motorFriction = 10.0;
    const double motorInertia = 1.0;
    const bool backDrivable = false;
    tgKinematicActuator::Config motorConfig(2000, 20, passivePretension,
                                            mRad, motorFriction, motorInertia, backDrivable,
                                            history, maxTens, maxSpeed);
#else

    const tgSpringCableActuator::Config stringConfig(stiffness, damping, pretension, false, 7000, 24);

    tgSpringCableActuator::Config muscleConfig(2000, 20, passivePretension);

#endif

    // Calculations for the flemons spine model
    double v_size = 10.0;

    //Todo: make separate functions for node, rod, and muscle placement! Do for each type of segment.

    //Foot:
    tgStructure foot;

    //Foot nodes. Todo: make into separate function
    foot.addNode(8,0,8);//0
    foot.addNode(8,0,-8);//1
    foot.addNode(-8,0,-8);//2
    foot.addNode(-8,0,8);//3
    foot.addNode(4,rod_space/2,0);//4
    foot.addNode(0,rod_space/2,-4);//5
    foot.addNode(-4,rod_space/2,0);//6
    foot.addNode(0,rod_space/2,4);//7

    //Foot rods. Todo: make into separate function
    foot.addPair(0,6,"rod");
    foot.addPair(1,7,"rod");
    foot.addPair(2,4,"rod");
    foot.addPair(3,5,"rod");

    //Create basic unit for right leg. Todo: make just one basic unit for right and left legs, since they're now the same.
    tgStructure rightLeg;

    //Right Leg nodes:
    rightLeg.addNode(0,0,0); //0: Bottom Center of lower leg segment
    rightLeg.addNode(0,10,0);  //1: Center of lower leg segment
    rightLeg.addNode(10,10,0); //2: Right of lower leg segment
    rightLeg.addNode(-10,10,0);  //3: Left of lower leg segment
    rightLeg.addNode(0,20,0);  //4: Top of lower leg segment
    rightLeg.addNode(0,-4,0);  //5: was z=3; was y=-3
    //rightLeg.addNode(0,-3,-3);  //6
    //rightLeg.addNode(3,-3,0);  //7
    //rightLeg.addNode(-3,-3,0);  //8

    //Add rods for right leg:
    rightLeg.addPair(0,1,"rod");
    rightLeg.addPair(1,2,"rod");
    rightLeg.addPair(1,3,"rod");
    rightLeg.addPair(1,4,"rod");
    rightLeg.addPair(0,5,"rod");
    //rightLeg.addPair(0,6,"rod");
    //rightLeg.addPair(0,7,"rod");
    //rightLeg.addPair(0,8,"rod");

    //Create basic unit for left leg
    tgStructure leftLeg;

    //Left Leg nodes:
    leftLeg.addNode(0,0,0); //0: Bottom Center of lower leg segment
    leftLeg.addNode(0,10,0);  //1: Center of lower leg segment
    leftLeg.addNode(10,10,0); //2: Right of lower leg segment
    leftLeg.addNode(-10,10,0);  //3: Left of lower leg segment
    leftLeg.addNode(0,20,0);  //4: Top of lower leg segment
    leftLeg.addNode(0,-4,0);  //5: was z=3; was y=-3
    //leftLeg.addNode(0,-3,-3);  //6
    //leftLeg.addNode(3,-3,0);  //7
    //leftLeg.addNode(-3,-3,0);  //8

    //Add rods for left leg:
    leftLeg.addPair(0,1,"rod");
    leftLeg.addPair(1,2,"rod");
    leftLeg.addPair(1,3,"rod");
    leftLeg.addPair(1,4,"rod");
    leftLeg.addPair(0,5,"rod");
    //leftLeg.addPair(0,6,"rod");
    //leftLeg.addPair(0,7,"rod");
    //leftLeg.addPair(0,8,"rod");

    //Create the basic unit of the spine
    tgStructure tetra;

    //Add the nodes
    tetra.addNode(0,0,0); //Node 0
    tetra.addNode(v_size, 0, v_size); //Node 1
    tetra.addNode(v_size, 0, -v_size); //Node 2
    tetra.addNode(-v_size, 0, -v_size); //Node 3
    tetra.addNode(-v_size, 0, v_size); //Node 4

    tetra.addPair(0,1,"rod");
    tetra.addPair(0,2,"rod");
    tetra.addPair(0,3,"rod");
    tetra.addPair(0,4,"rod");

    //Create the basic unit for the hips/shoulders:
    tgStructure lHip;

    lHip.addNode(0,0,0); //Node 0
    lHip.addNode(0, v_size, v_size); //Node 1
    lHip.addNode(0, -v_size, -v_size); //Node 2
    lHip.addNode(0, -v_size, v_size); //Node 3

    lHip.addPair(0,1,"rod");
    lHip.addPair(0,2,"rod");
    lHip.addPair(0,3,"rod");

    tgStructure rHip;

    rHip.addNode(0,0,0); //Node 0
    rHip.addNode(0, v_size, -v_size); //Node 1
    rHip.addNode(0, -v_size, -v_size); //Node 2
    rHip.addNode(0, -v_size, v_size); //Node 3

    rHip.addPair(0,1,"rod");
    rHip.addPair(0,2,"rod");
    rHip.addPair(0,3,"rod");

    //Build the spine
    tgStructure spine;
    const double offsetDist = v_size + 1; //So rod ends don't touch, may need to adjust
    const double offsetDist2 = v_size*5 + 5 + 3.3;
    const double offsetDist3 = v_size*6;
    const double yOffset_leg = -21.0;
    const double yOffset_foot = -26.0;
    std::size_t m_segments = 6;
    std::size_t m_hips = 4;
    std::size_t m_legs = 4;
    std::size_t m_feet = 4;
    //Vertebrae
    btVector3 offset(offsetDist,0.0,0);
    //Hips
    btVector3 offset1(offsetDist*2,0.0,offsetDist);
    btVector3 offset2(offsetDist2,0.0,offsetDist);
    btVector3 offset3(offsetDist*2,0.0,-offsetDist);
    btVector3 offset4(offsetDist2,0.0,-offsetDist);
    //Lower legs
    btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
    btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
    btVector3 offset7(v_size*2,yOffset_leg,offsetDist);
    btVector3 offset8(v_size*2,yOffset_leg,-offsetDist);
    //Feet
    btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
    btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
    btVector3 offset11(v_size*2+1,yOffset_foot,offsetDist);
    btVector3 offset12(v_size*2+1,yOffset_foot,-offsetDist);


    for(std::size_t i = 0; i < m_segments; i++) { //Connect segments for spine
        tgStructure* t = new tgStructure (tetra);
        t->addTags(tgString("segment num", i + 1));
        t->move((i + 1)*offset);

        if (i % 2 == 1) {

            t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);

        }
        else {

            t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);

        }

        spine.addChild(t); //Add a segment to the spine
    }

    for(std::size_t i = m_segments; i < (m_segments + 2); i++) {//deal with right hip and shoulder first
        tgStructure* t = new tgStructure (rHip);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0) {
            t->move(offset1);
            t->addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(1, 0, 0), 0.0);
        }
        else {
            t->move(offset2);
            t->addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 0, 1), M_PI*1/8);
        }

        spine.addChild(t); //Add a segment to the spine
    }

    for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {//deal with left hip and shoulder now
        tgStructure* t = new tgStructure (lHip);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0) {
            t->move(offset3);
            t->addRotation(btVector3(offsetDist*2, 0.0, -offsetDist), btVector3(1, 0, 0), 0.0);
        }
        else {
            t->move(offset4);
            t->addRotation(btVector3(offsetDist2, 0.0, -offsetDist), btVector3(0, 0, 1), M_PI*1/8);
        }

        spine.addChild(t); //Add a segment to the spine

    }

    for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {//right front and back legs
        tgStructure* t = new tgStructure (rightLeg);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0) {
            t->move(offset7);
            t->addRotation(btVector3(v_size*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
        }
        else {
            t->move(offset5);
            t->addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
        }

        spine.addChild(t); //Add a segment to the spine
    }

    for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {//left front and back legs
        tgStructure* t = new tgStructure (leftLeg);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0) {
            t->move(offset8);
            t->addRotation(btVector3(v_size*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
        }
        else {
            t->move(offset6);
            t->addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
        }

        spine.addChild(t); //Add a segment to the spine
    }

    for(std::size_t i = (m_segments + m_hips + m_legs); i < (m_segments + m_hips + m_legs + 2); i++) {//right front and back feet
        tgStructure* t = new tgStructure (foot);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0) {
            t->move(offset11);
            t->addRotation(btVector3(v_size*2+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
        }
        else {
            t->move(offset9);
            t->addRotation(btVector3(offsetDist3+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
        }

        spine.addChild(t); //Add a segment to the spine
    }

    for(std::size_t i = (m_segments + m_hips + m_legs + 2); i < (m_segments + m_hips + m_legs + m_feet); i++) {//left front and back feet
        tgStructure* t = new tgStructure (foot);
        t->addTags(tgString("segment num", i + 1));

        if(i % 2 == 0) {
            t->move(offset12);
            t->addRotation(btVector3(v_size*2+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
        }
        else {
            t->move(offset10);
            t->addRotation(btVector3(offsetDist3+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
        }

        spine.addChild(t); //Add a segment to the spine
    }

#ifdef SMALL_HILLS
    spine.move(btVector3(0.0,-yOffset_foot+5,0.0));
#endif

#ifdef LARGE_HILLS
    spine.move(btVector3(0.0,-yOffset_foot+12,0.0));
#endif

#ifdef FLAT_GROUND
    spine.move(btVector3(0.0,-yOffset_foot,0.0));
#endif

#ifdef BLOCKY_GROUND
    spine.move(btVector3(0.0,10.0,0.0));
#endif

#ifdef STAIRS
    spine.move(btVector3(0.0,0.0,0.0));
#endif

    std::vector<tgStructure*> children = spine.getChildren();
    for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs + m_feet)); i++) {

        tgNodes n0 = children[i-2]->getNodes();
        tgNodes n1 = children[i-1]->getNodes();
        tgNodes n2 = children[i]->getNodes();


        if(i==2) {
            //Extra muscles, to keep front vertebra from swinging.
            spine.addPair(n0[3], n1[3], tgString("spine front upper right muscle seg", i-2) + tgString(" seg", i-1));
            spine.addPair(n0[3], n1[4], tgString("spine front upper left muscle seg", i-2) + tgString(" seg", i-1));

        }

        //Add muscles to the spine
        if(i < 3) {
            if(i % 2 == 0) { //front
                spine.addPair(n0[1], n1[3], tgString("spine front lower right muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[1], n1[4], tgString("spine front lower left muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[2], n1[3], tgString("spine front upper right muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[2], n1[4], tgString("spine front upper left muscle seg", i-2) + tgString(" seg", i-1));
            }
            else { //rear
                spine.addPair(n0[1], n1[3], tgString("spine rear upper left muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[1], n1[4], tgString("spine rear lower left muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[2], n1[3], tgString("spine rear upper right muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[2], n1[4], tgString("spine rear lower right muscle seg", i-2) + tgString(" seg", i-1));
            }
        }
        if(i < 6) {
            if(i % 2 == 0) {
                spine.addPair(n0[1], n2[4], tgString("spine bottom muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[2], n2[3], tgString("spine top muscle seg", i-2) + tgString(" seg", i-1));
            }
            else {
                spine.addPair(n0[1], n2[4], tgString("spine lateral left muscle seg", i-2) + tgString(" seg", i-1));
                spine.addPair(n0[2], n2[3], tgString("spine lateral right muscle seg", i-2) + tgString(" seg", i-1));

            }
        }
        if(i > 0 && i < 5) {
            if(i % 2 == 0) { //rear
                spine.addPair(n1[1], n2[3], tgString("spine rear upper left muscle seg", i-1) + tgString(" seg", i));
                spine.addPair(n1[1], n2[4], tgString("spine rear lower left muscle seg", i-1) + tgString(" seg", i));
                spine.addPair(n1[2], n2[3], tgString("spine rear upper right muscle seg", i-1) + tgString(" seg", i));
                spine.addPair(n1[2], n2[4], tgString("spine rear lower right muscle seg", i-1) + tgString(" seg", i));
            }
            else { //front

                spine.addPair(n1[1], n2[3], tgString("spine front lower right muscle seg", i-1) + tgString(" seg", i));
                spine.addPair(n1[1], n2[4], tgString("spine front lower left muscle seg", i-1) + tgString(" seg", i));
                spine.addPair(n1[2], n2[3], tgString("spine front upper right muscle seg", i-1) + tgString(" seg", i));
                spine.addPair(n1[2], n2[4], tgString("spine front upper left muscle seg", i-1) + tgString(" seg", i));
            }
        }
        if(i == 5) {
            //rear
            spine.addPair(n1[1], n2[1], tgString("spine rear lower left muscle seg", i-1) + tgString(" seg", i));
            spine.addPair(n1[1], n2[2], tgString("spine rear lower right muscle seg", i-1) + tgString(" seg", i));
            spine.addPair(n1[2], n2[1], tgString("spine rear upper left muscle seg", i-1) + tgString(" seg", i));
            spine.addPair(n1[2], n2[2], tgString("spine rear upper right muscle seg", i-1) + tgString(" seg", i));
            //front
            spine.addPair(n1[1], n2[3], tgString("spine front lower right muscle seg", i-1) + tgString(" seg", i));
            spine.addPair(n1[1], n2[4], tgString("spine front lower left muscle seg", i-1) + tgString(" seg", i));
            spine.addPair(n1[2], n2[3], tgString("spine front upper right muscle seg", i-1) + tgString(" seg", i));
            spine.addPair(n1[2], n2[4], tgString("spine front upper left muscle seg", i-1) + tgString(" seg", i));

        }

    }


    //Now add muscles to hips....
    tgNodes n0 = children[0]->getNodes();
    tgNodes n1 = children[1]->getNodes();
    tgNodes n2 = children[2]->getNodes();
    tgNodes n3 = children[3]->getNodes();
    tgNodes n4 = children[4]->getNodes();
    tgNodes n5 = children[5]->getNodes();
    tgNodes n6 = children[6]->getNodes();
    tgNodes n7 = children[7]->getNodes();
    tgNodes n8 = children[8]->getNodes();
    tgNodes n9 = children[9]->getNodes();
    tgNodes n10 = children[10]->getNodes();
    tgNodes n11 = children[11]->getNodes();
    tgNodes n12 = children[12]->getNodes();
    tgNodes n13 = children[13]->getNodes();

    //Left shoulder muscles
    spine.addPair(n6[1], n1[1], tgString("left shoulder rear upper muscle seg", 6) + tgString(" seg", 1));
    spine.addPair(n6[1], n1[4], tgString("left shoulder front upper muscle seg", 6) + tgString(" seg", 1));
    spine.addPair(n6[1], n0[2], tgString("left shoulder front top muscle seg", 6) + tgString(" seg", 0));
    spine.addPair(n6[1], n2[3], tgString("left shoulder rear top muscle seg", 6) + tgString(" seg", 2));

    spine.addPair(n6[2], n1[1], tgString("left shoulder rear lower muscle seg", 6) + tgString(" seg", 1));
    spine.addPair(n6[2], n1[4], tgString("left shoulder front lower muscle seg", 6) + tgString(" seg", 1));
    spine.addPair(n6[2], n0[1], tgString("left shoulder front bottom muscle seg", 6) + tgString(" seg", 0));
    spine.addPair(n6[2], n2[4], tgString("left shoulder rear bottom muscle seg", 6) + tgString(" seg", 2));

    //Extra muscles, to move left shoulder forward and back:
    spine.addPair(n6[0], n1[1], tgString("left shoulder rear mid muscle seg", 6) + tgString(" seg", 1));
    spine.addPair(n6[0], n1[4], tgString("left shoulder front mid muscle seg", 6) + tgString(" seg", 1));

    //Left hip muscles
    spine.addPair(n7[1], n5[1], tgString("left hip rear upper muscle seg", 7) + tgString(" seg", 5));
    spine.addPair(n7[1], n5[4], tgString("left hip front upper muscle seg", 7) + tgString(" seg", 5));
    spine.addPair(n7[1], n4[2], tgString("left hip rear top muscle seg", 7) + tgString(" seg", 4));
    spine.addPair(n7[1], n4[3], tgString("left hip front top muscle seg", 7) + tgString(" seg", 4));

    spine.addPair(n7[2], n5[1], tgString("left hip rear lower muscle seg", 7) + tgString(" seg", 5));
    spine.addPair(n7[2], n5[4], tgString("left hip front lower muscle seg", 7) + tgString(" seg", 5));
    spine.addPair(n7[2], n4[1], tgString("left hip bottom muscle seg", 7) + tgString(" seg", 4));

    //Extra muscles, to move left hip forward and back:
    spine.addPair(n7[0], n3[1], tgString("left hip rear mid muscle seg", 7) + tgString(" seg", 3)); //could also be n3[3]
    spine.addPair(n7[0], n5[4], tgString("left hip front mid muscle seg", 7) + tgString(" seg", 5));

    //Inter-hip connector muscle
    spine.addPair(n7[2], n9[3], tgString("inter-hip bottom muscle seg", 7) + tgString(" seg", 9)); //inter-hip bottom muscle

    //Right shoulder muscles
    spine.addPair(n8[1], n1[2], tgString("right shoulder rear upper muscle seg", 8) + tgString(" seg", 1));
    spine.addPair(n8[1], n1[3], tgString("right shoulder front upper muscle seg", 8) + tgString(" seg", 1));
    spine.addPair(n8[1], n0[2], tgString("right shoulder front top muscle seg", 8) + tgString(" seg", 0));
    spine.addPair(n8[1], n2[3], tgString("right shoulder rear top muscle seg", 8) + tgString(" seg", 2));

    spine.addPair(n8[3], n1[2], tgString("right shoulder rear lower muscle seg", 8) + tgString(" seg", 1));
    spine.addPair(n8[3], n1[3], tgString("right shoulder front lower muscle seg", 8) + tgString(" seg", 1));
    spine.addPair(n8[3], n0[1], tgString("right shoulder front bottom muscle seg", 8) + tgString(" seg", 0));
    spine.addPair(n8[3], n2[4], tgString("right shoulder rear bottom muscle seg", 8) + tgString(" seg", 2));

    //Extra muscles, to move right shoulder forward and back:
    spine.addPair(n8[0], n1[2], tgString("right shoulder rear mid muscle seg", 8) + tgString(" seg", 1));
    spine.addPair(n8[0], n1[3], tgString("right shoulder front mid muscle seg", 8) + tgString(" seg", 1));

    //Right hip muscles
    spine.addPair(n9[1], n5[2], tgString("right hip rear upper muscle seg", 9) + tgString(" seg", 5));
    spine.addPair(n9[1], n5[3], tgString("right hip front upper muscle seg", 9) + tgString(" seg", 5));
    spine.addPair(n9[1], n4[2], tgString("right hip rear top muscle seg", 9) + tgString(" seg", 4));
    spine.addPair(n9[1], n4[3], tgString("right hip front top muscle seg", 9) + tgString(" seg", 4));

    spine.addPair(n9[3], n5[2], tgString("right hip rear lower muscle seg", 9) + tgString(" seg", 5));
    spine.addPair(n9[3], n5[3], tgString("right hip front lower muscle seg", 9) + tgString(" seg", 5));
    spine.addPair(n9[3], n4[1], tgString("right hip bottom muscle seg", 9) + tgString(" seg", 4));

    //Extra muscles, to move right hip forward and back:
    spine.addPair(n9[0], n3[2], tgString("right hip rear mid muscle seg", 9) + tgString(" seg", 3)); //could also be n3[3]
    spine.addPair(n9[0], n5[3], tgString("right hip front mid muscle seg", 9) + tgString(" seg", 5));

    //Leg/hip connections:

    //Right front leg/shoulder
    spine.addPair(n10[4], n6[2], tgString("right outer bicep muscle seg", 10) + tgString(" seg", 6));
    spine.addPair(n10[4], n6[3], tgString("right inner bicep muscle seg", 10) + tgString(" seg", 6));
    spine.addPair(n10[4], n1[4], tgString("right front abdomen connection muscle seg", 10) + tgString(" seg", 1));

    spine.addPair(n10[3], n6[2], tgString("right outer tricep muscle seg", 10) + tgString(" seg", 6));
    spine.addPair(n10[3], n6[3], tgString("right inner tricep muscle seg", 10) + tgString(" seg", 6));

    spine.addPair(n10[2], n6[2], tgString("right outer front tricep muscle seg", 10) + tgString(" seg", 6));
    spine.addPair(n10[2], n6[3], tgString("right inner front tricep muscle seg", 10) + tgString(" seg", 6));

    //Adding muscle to pull up on right front leg:
    spine.addPair(n10[4], n6[1], tgString("right mid bicep muscle seg", 10) + tgString(" seg", 6));

    //Left front leg/shoulder
    spine.addPair(n12[4], n8[2], tgString("left inner bicep muscle seg", 12) + tgString(" seg", 8));
    spine.addPair(n12[4], n8[3], tgString("left outer bicep muscle seg", 12) + tgString(" seg", 8));
    spine.addPair(n12[4], n1[3], tgString("left front abdomen connection muscle seg", 12) + tgString(" seg", 1)); //Was n1[2]

    spine.addPair(n12[3], n8[2], tgString("left inner tricep muscle seg", 12) + tgString(" seg", 8));
    spine.addPair(n12[3], n8[3], tgString("left outer tricep muscle seg", 12) + tgString(" seg", 8));

    spine.addPair(n12[2], n8[2], tgString("left inner front tricep muscle seg", 12) + tgString(" seg", 8));
    spine.addPair(n12[2], n8[3], tgString("left outer front tricep muscle seg", 12) + tgString(" seg", 8));

    //Adding muscle to pull up on left front leg:
    spine.addPair(n12[4], n8[1], tgString("left mid bicep muscle seg", 12) + tgString(" seg", 8));

    //Right rear leg/hip
    spine.addPair(n11[4], n7[2], tgString("right outer thigh muscle seg", 11) + tgString(" seg", 7));
    spine.addPair(n11[4], n7[3], tgString("right inner thigh muscle seg", 11) + tgString(" seg", 7));

    spine.addPair(n11[4], n3[4],tgString("right rear abdomen connection muscle seg", 11) + tgString(" seg", 3));
    spine.addPair(n11[3], n5[1],tgString("right rear abdomen connection muscle seg", 11) + tgString(" seg", 5));

    spine.addPair(n11[3], n7[2], tgString("right outer calf muscle seg", 11) + tgString(" seg", 7));
    spine.addPair(n11[3], n7[3], tgString("right inner calf muscle seg", 11) + tgString(" seg", 7));

    spine.addPair(n11[2], n7[2], tgString("right outer front calf muscle seg", 11) + tgString(" seg", 7));
    spine.addPair(n11[2], n7[3], tgString("right inner front calf muscle seg", 11) + tgString(" seg", 7));

    //Adding muscle to pull rear right leg up:
    spine.addPair(n11[4], n7[1], tgString("right central thigh muscle seg", 11) + tgString(" seg", 7));

    //Left rear leg/hip
    spine.addPair(n13[4], n9[2], tgString("left inner thigh muscle seg", 13) + tgString(" seg", 9));
    spine.addPair(n13[4], n9[3], tgString("left outer thigh muscle seg", 13) + tgString(" seg", 9));

    spine.addPair(n13[4], n3[3], tgString("left rear abdomen connection muscle seg", 13) + tgString(" seg", 3));
    spine.addPair(n13[3], n5[2], tgString("left rear abdomen connection muscle seg", 13) + tgString(" seg", 5));

    spine.addPair(n13[3], n9[2], tgString("left inner calf muscle seg", 13) + tgString(" seg", 9));
    spine.addPair(n13[3], n9[3], tgString("left outer calf muscle seg", 13) + tgString(" seg", 9));

    spine.addPair(n13[2], n9[2], tgString("left inner front calf muscle seg", 13) + tgString(" seg", 9));
    spine.addPair(n13[2], n9[3], tgString("left outer front calf muscle seg", 13) + tgString(" seg", 9));

    //Adding muscle to pull rear left leg up:
    spine.addPair(n13[4], n9[1], tgString("left central thigh muscle seg", 13) + tgString(" seg", 9));

    //Populate feet with muscles. Todo: think up names to differentiate each!
    for(std::size_t i = (m_segments + m_hips + m_legs); i < children.size(); i++) {
        tgNodes ni = children[i]->getNodes();
        tgNodes ni4 = children[i-4]->getNodes(); //Think of a nicer name for this!

        spine.addPair(ni[0],ni[1],tgString("foot muscle seg", i));
        spine.addPair(ni[0],ni[3],tgString("foot muscle seg", i));
        spine.addPair(ni[1],ni[2],tgString("foot muscle seg", i));
        spine.addPair(ni[2],ni[3],tgString("foot muscle seg", i));
        spine.addPair(ni[0],ni[7],tgString("foot muscle seg", i));
        spine.addPair(ni[1],ni[4],tgString("foot muscle seg", i));
        spine.addPair(ni[2],ni[5],tgString("foot muscle seg", i));
        spine.addPair(ni[3],ni[6],tgString("foot muscle seg", i));
        spine.addPair(ni[4],ni[5],tgString("foot muscle seg", i));
        spine.addPair(ni[4],ni[7],tgString("foot muscle seg", i));
        spine.addPair(ni[5],ni[6],tgString("foot muscle seg", i));
        spine.addPair(ni[6],ni[7],tgString("foot muscle seg", i));

        //Connecting feet to legs:
        //spine.addPair(ni4[5],ni[1],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[5],ni[2],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[5],ni[5],tgString("foot muscle seg", i) + tgString(" seg", i-4));

        //spine.addPair(ni4[6],ni[0],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[6],ni[3],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[6],ni[7],tgString("foot muscle seg", i) + tgString(" seg", i-4));

        //spine.addPair(ni4[7],ni[0],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[7],ni[1],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[7],ni[4],tgString("foot muscle seg", i) + tgString(" seg", i-4));

        //spine.addPair(ni4[8],ni[2],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[8],ni[3],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        //spine.addPair(ni4[8],ni[6],tgString("foot muscle seg", i) + tgString(" seg", i-4));

        //Trying out these for foot:
        spine.addPair(ni4[5],ni[0],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        spine.addPair(ni4[5],ni[1],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        spine.addPair(ni4[5],ni[2],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        spine.addPair(ni4[5],ni[3],tgString("foot muscle seg", i) + tgString(" seg", i-4));

        spine.addPair(ni4[0],ni[4],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        spine.addPair(ni4[0],ni[5],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        spine.addPair(ni4[0],ni[6],tgString("foot muscle seg", i) + tgString(" seg", i-4));
        spine.addPair(ni4[0],ni[7],tgString("foot muscle seg", i) + tgString(" seg", i-4));

    }

    //Don't forget muscles connecting hips to feet!


    // Create the build spec that uses tags to turn the structure into a real model
    tgBuildSpec spec;
    spec.addBuilder("rod", new tgRodInfo(rodConfig));
#ifdef USE_KINEMATIC
    spec.addBuilder("muscle", new tgKinematicContactCableInfo(motorConfig));
#else
    spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig));
#endif

    // Create your structureInfo
    tgStructureInfo structureInfo(spine, spec);

    // Use the structureInfo to build ourselves
    structureInfo.buildInto(*this, world);

    // We could now use tgCast::filter or similar to pull out the
    // models (e.g. muscles) that we want to control.
    allActuators = tgCast::filter<tgModel, tgSpringCableActuator> (getDescendants());

    // Notify controllers that setup has finished.
    notifySetup();

    // Actually setup the children
    tgModel::setup(world);

    children.clear();
}