本文整理汇总了C++中opensim::Body::set_mass方法的典型用法代码示例。如果您正苦于以下问题:C++ Body::set_mass方法的具体用法?C++ Body::set_mass怎么用?C++ Body::set_mass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opensim::Body
的用法示例。
在下文中一共展示了Body::set_mass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testBouncingBall
//==========================================================================================================
// Test Cases
//==========================================================================================================
int testBouncingBall(bool useMesh)
{
// Setup OpenSim model
Model *osimModel = new Model;
//OpenSim bodies
OpenSim::Body& ground = *new OpenSim::Body("ground", SimTK::Infinity,
Vec3(0), Inertia());
osimModel->addBody(&ground);
OpenSim::Body ball;
ball.setName("ball");
ball.set_mass(mass);
ball.set_mass_center(Vec3(0));
ball.setInertia(Inertia(1.0));
// Add joints
FreeJoint free("free", ground, Vec3(0), Vec3(0), ball, Vec3(0), Vec3(0));
osimModel->addBody(&ball);
osimModel->addJoint(&free);
// Create ContactGeometry.
ContactHalfSpace *floor = new ContactHalfSpace(Vec3(0), Vec3(0, 0, -0.5*SimTK_PI), ground, "ground");
osimModel->addContactGeometry(floor);
OpenSim::ContactGeometry* geometry;
if (useMesh)
geometry = new ContactMesh(mesh_file, Vec3(0), Vec3(0), ball, "ball");
else
geometry = new ContactSphere(radius, Vec3(0), ball, "ball");
osimModel->addContactGeometry(geometry);
OpenSim::Force* force;
if (useMesh)
{
// Add an ElasticFoundationForce.
OpenSim::ElasticFoundationForce::ContactParameters* contactParams = new OpenSim::ElasticFoundationForce::ContactParameters(1.0e6/radius, 1e-5, 0.0, 0.0, 0.0);
contactParams->addGeometry("ball");
contactParams->addGeometry("ground");
force = new OpenSim::ElasticFoundationForce(contactParams);
osimModel->addForce(force);
}
else
{
// Add a HuntCrossleyForce.
OpenSim::HuntCrossleyForce::ContactParameters* contactParams = new OpenSim::HuntCrossleyForce::ContactParameters(1.0e6, 1e-5, 0.0, 0.0, 0.0);
contactParams->addGeometry("ball");
contactParams->addGeometry("ground");
force = new OpenSim::HuntCrossleyForce(contactParams);
osimModel->addForce(force);
}
osimModel->setGravity(gravity_vec);
osimModel->setName("TestContactGeomtery_Ball");
osimModel->clone()->print("TestContactGeomtery_Ball.osim");
Kinematics* kin = new Kinematics(osimModel);
osimModel->addAnalysis(kin);
SimTK::State& osim_state = osimModel->initSystem();
osim_state.updQ()[4] = height;
osimModel->getMultibodySystem().realize(osim_state, Stage::Position );
//Initial system energy is all potential
double Etot_orig = mass*(-gravity_vec[1])*height;
//==========================================================================================================
// Simulate it and see if it bounces correctly.
cout << "stateY=" << osim_state.getY() << std::endl;
RungeKuttaMersonIntegrator integrator(osimModel->getMultibodySystem() );
integrator.setAccuracy(integ_accuracy);
Manager manager(*osimModel, integrator);
for (unsigned int i = 0; i < duration/interval; ++i)
{
manager.setInitialTime(i*interval);
manager.setFinalTime((i+1)*interval);
manager.integrate(osim_state);
double time = osim_state.getTime();
osimModel->getMultibodySystem().realize(osim_state, Stage::Acceleration);
Vec3 pos, vel;
osimModel->updSimbodyEngine().getPosition(osim_state, osimModel->getBodySet().get("ball"), Vec3(0), pos);
osimModel->updSimbodyEngine().getVelocity(osim_state, osimModel->getBodySet().get("ball"), Vec3(0), vel);
double Etot = mass*((-gravity_vec[1])*pos[1] + 0.5*vel[1]*vel[1]);
//cout << "starting system energy = " << Etot_orig << " versus current energy = " << Etot << endl;
// contact absorbs and returns energy so make sure not in contact
if (pos[1] > 2*radius)
{
ASSERT_EQUAL(Etot_orig, Etot, 1e-2, __FILE__, __LINE__, "Bouncing ball on plane Failed: energy was not conserved.");
}
else
{
//.........这里部分代码省略.........