// ----------------------------------------------------------------------------- // Utility for adding (visible or invisible) walls // ----------------------------------------------------------------------------- void AddWall(ChSharedPtr<ChBody>& body, const ChVector<>& dim, const ChVector<>& loc, bool visible) { body->GetCollisionModel()->AddBox(dim.x, dim.y, dim.z, loc); if (visible == true) { ChSharedPtr<ChBoxShape> box(new ChBoxShape); box->GetBoxGeometry().Size = dim; box->Pos = loc; box->SetColor(ChColor(1, 0, 0)); box->SetFading(0.6f); body->AddAsset(box); } }
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); }