void purge_debris(ChIrrAppInterface& application, int nmaxparticles = 100) { while (particlelist.size() > nmaxparticles) { application.GetSystem()->Remove(particlelist[0]); // remove from physical simulation particlelist.erase(particlelist.begin()); // remove also from our particle list (will also automatically delete // object thank to shared pointer) } }
void create_items(ChIrrAppInterface& application) { // Create some spheres in a vertical stack bool do_wall = false; bool do_stack = true; bool do_oddmass = true; bool do_spheres = true; bool do_heavyonside = true; double sphrad = 0.2; double dens= 1000; double sphmass = dens * (4./3.) * CH_C_PI * pow(sphrad,3); double sphinertia = (2./5.) * sphmass * pow(sphrad,2); if (do_stack) { int nbodies = 15; double totmass= 0; double level = 0; double sphrad_base = 0.2; double oddfactor = 100; for (int bi = 0; bi < nbodies; bi++) // N. of vert. bricks { double sphrad = sphrad_base; if (do_oddmass && bi==(nbodies-1)) sphrad = sphrad*pow(oddfactor, 1./3.); double dens= 1000; ChSharedPtr<ChBody> mrigidBody; if (do_spheres) { mrigidBody = ChSharedPtr<ChBodyEasySphere>(new ChBodyEasySphere( sphrad, // radius dens, // density true, // collide enable? true)); // visualization? mrigidBody->SetPos(ChVector<>(0.5, sphrad+level, 0.7)); mrigidBody->AddAsset(ChSharedPtr<ChTexture>(new ChTexture(GetChronoDataFile("bluwhite.png")))); application.GetSystem()->Add(mrigidBody); } else { mrigidBody = ChSharedPtr<ChBodyEasyBox>(new ChBodyEasyBox( sphrad,sphrad,sphrad, // x,y,z size dens, // density true, // collide enable? true)); // visualization? mrigidBody->SetPos(ChVector<>(0.5, sphrad+level, 0.7)); mrigidBody->AddAsset(ChSharedPtr<ChTexture>(new ChTexture(GetChronoDataFile("cubetexture_bluwhite.png")))); application.GetSystem()->Add(mrigidBody); } mrigidBody->GetMaterialSurface()->SetFriction(0.5f); mrigidBody->GetMaterialSurface()->SetRestitution(0.0f); mspheres.push_back(mrigidBody); level +=sphrad*2; totmass +=mrigidBody->GetMass(); } GetLog() << "Expected contact force at bottom F=" << (totmass *application.GetSystem()->Get_G_acc().y) << "\n"; } if (do_wall) for (int ai = 0; ai < 1; ai++) // N. of walls { for (int bi = 0; bi < 10; bi++) // N. of vert. bricks { for (int ui = 0; ui < 15; ui++) // N. of hor. bricks { ChSharedPtr<ChBodyEasyBox> mrigidWall (new ChBodyEasyBox( 3.96,2,4, // radius dens, // density true, // collide enable? true)); // visualization? mrigidWall->SetPos(ChVector<>(-8+ui*4.0+2*(bi%2), 1.0+bi*2.0, -5+ ai*6)); mrigidWall->GetMaterialSurface()->SetFriction(0.4f); mrigidWall->AddAsset(ChSharedPtr<ChTexture>(new ChTexture(GetChronoDataFile("cubetexture_bluwhite.png")))); application.GetSystem()->Add(mrigidWall); } } } if (do_heavyonside) { double sphrad = 0.2; double dens= 1000; double hfactor = 100; ChSharedPtr<ChBodyEasySphere> mrigidHeavy(new ChBodyEasySphere( sphrad, // radius dens*hfactor,// density true, // collide enable? true)); // visualization? mrigidHeavy->SetPos(ChVector<>(0.5, sphrad+0.1, -1)); mrigidHeavy->AddAsset(ChSharedPtr<ChTexture>(new ChTexture(GetChronoDataFile("pinkwhite.png")))); application.GetSystem()->Add(mrigidHeavy); GetLog() << "Expected contact deformation at side sphere=" << (mrigidHeavy->GetMass() *application.GetSystem()->Get_G_acc().y)*STATIC_COMPLIANCE << "\n"; } // Create the floor using a fixed rigid body of 'box' type: ChSharedPtr<ChBodyEasyBox> mrigidFloor (new ChBodyEasyBox( 50,4,50, // radius dens, // density true, // collide enable? true)); // visualization? mrigidFloor->SetPos( ChVector<>(0,-2,0) ); mrigidFloor->SetBodyFixed(true); mrigidFloor->GetMaterialSurface()->SetFriction(0.6f); mrigidFloor->AddAsset(ChSharedPtr<ChTexture>(new ChTexture(GetChronoDataFile("concrete.jpg")))); application.GetSystem()->Add(mrigidFloor); }
void create_items(ChIrrAppInterface& application) { ChBodySceneNode* mrigidBody; // Create some spheres in a vertical stack, and put them into 'parent' level video::ITexture* sphereMap = application.GetVideoDriver()->getTexture("../data/bluwhite.png"); bool do_wall = false; bool do_stack = true; bool do_oddmass = true; bool do_spheres = true; bool do_heavyonside = true; double sphrad = 0.2; double dens= 1000; double sphmass = dens * (4./3.) * CH_C_PI * pow(sphrad,3); double sphinertia = (2./5.) * sphmass * pow(sphrad,2); if (do_stack) { int nbodies = 15; double totmass= 0; double level = 0; double sphrad_base = 0.2; double oddfactor = 100; for (int bi = 0; bi < nbodies; bi++) // N. of vert. bricks { double sphrad = sphrad_base; if (do_oddmass && bi==(nbodies-1)) sphrad = sphrad*pow(oddfactor, 1./3.); double dens= 1000; double sphmass = dens * (4./3.) * CH_C_PI * pow(sphrad,3); double sphinertia = (2./5.) * sphmass * pow(sphrad,2); if (do_spheres) mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easySphere( application.GetSystem(), application.GetSceneManager(), sphmass, ChVector<>(0.5, sphrad+level, 0.7), sphrad); else mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox( application.GetSystem(), application.GetSceneManager(), sphmass, ChVector<>(0.5, sphrad+level, 0.7), ChQuaternion<>(1,0,0,0), ChVector<>(sphrad,sphrad,sphrad) ); mrigidBody->GetBody()->SetInertiaXX(ChVector<>(sphinertia,sphinertia,sphinertia)); mrigidBody->GetBody()->SetFriction(0.5f); mrigidBody->GetBody()->SetImpactC(0.0f); mrigidBody->addShadowVolumeSceneNode(); mrigidBody->setMaterialTexture(0, sphereMap); mspheres.push_back(mrigidBody); level +=sphrad*2; totmass +=sphmass; } GetLog() << "Expected contact force at bottom F=" << (totmass *application.GetSystem()->Get_G_acc().y) << "\n"; } if (do_wall) for (int ai = 0; ai < 1; ai++) // N. of walls { for (int bi = 0; bi < 10; bi++) // N. of vert. bricks { for (int ui = 0; ui < 15; ui++) // N. of hor. bricks { mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox( application.GetSystem(), application.GetSceneManager(), 0.8, ChVector<>(-8+ui*4.0+2*(bi%2), 1.0+bi*2.0, -5+ ai*6), ChQuaternion<>(1,0,0,0), ChVector<>(3.96,2,4) ); mrigidBody->GetBody()->SetFriction(0.4f); mrigidBody->setMaterialTexture(0, sphereMap); } } } if (do_heavyonside) { double sphrad = 0.2; double dens= 1000; double sphmass = dens * (4./3.) * CH_C_PI * pow(sphrad,3); double sphinertia = (2./5.) * sphmass * pow(sphrad,2); double hfactor = 100; mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easySphere( application.GetSystem(), application.GetSceneManager(), sphmass*hfactor, ChVector<>(0.5, sphrad+0.1, -1), sphrad); mrigidBody->GetBody()->SetInertiaXX(ChVector<>(sphinertia*hfactor,sphinertia*hfactor,sphinertia*hfactor)); mrigidBody->addShadowVolumeSceneNode(); mrigidBody->setMaterialTexture(0, sphereMap); GetLog() << "Expected contact deformation at side sphere=" << (sphmass*hfactor *application.GetSystem()->Get_G_acc().y)*STATIC_COMPLIANCE << "\n"; } // Create the floor using a fixed rigid body of 'box' type: mrigidBody = (ChBodySceneNode*)addChBodySceneNode_easyBox( application.GetSystem(), application.GetSceneManager(), 1.0, ChVector<>(0,-2,0), ChQuaternion<>(1,0,0,0), ChVector<>(50,4,50) ); mrigidBody->GetBody()->SetBodyFixed(true); mrigidBody->GetBody()->SetFriction(0.6f); video::ITexture* cubeMap = application.GetVideoDriver()->getTexture("../data/concrete.jpg"); mrigidBody->setMaterialTexture(0, cubeMap); /* // Create rotating stuff ChBodySceneNode* rotatingBody = (ChBodySceneNode*)addChBodySceneNode_easyBox( application.GetSystem(), application.GetSceneManager(), 1.0, ChVector<>(0,12,0), ChQuaternion<>(1,0,0,0), ChVector<>(10,2.5,1) ); rotatingBody->GetBody()->SetMass(100); rotatingBody->GetBody()->SetInertiaXX(ChVector<>(500,500,500)); rotatingBody->GetBody()->SetFriction(0.4f); rotatingBody->addShadowVolumeSceneNode(); // .. an engine between mixer and truss ChSharedPtr<ChLinkEngine> my_motor(new ChLinkEngine); my_motor->Initialize(rotatingBody->GetBody(), mrigidBody->GetBody(), ChCoordsys<>(ChVector<>(0,15,0), Q_from_AngAxis(CH_C_PI_2, VECT_X)) ); my_motor->Set_eng_mode(ChLinkEngine::ENG_MODE_SPEED); if (ChFunction_Const* mfun = dynamic_cast<ChFunction_Const*>(my_motor->Get_spe_funct())) mfun->Set_yconst(CH_C_PI/2.0); // speed w=90°/s application.GetSystem()->AddLink(my_motor); */ }