本文整理汇总了C++中sp::Interaction::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ Interaction::reset方法的具体用法?C++ Interaction::reset怎么用?C++ Interaction::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sp::Interaction
的用法示例。
在下文中一共展示了Interaction::reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
try
{
// ================= Creation of the model =======================
// User-defined main parameters
unsigned int nDof = 3; // degrees of freedom for the ball
double t0 = 0; // initial computation time
double T = 2.0; // final computation time
double h = 0.0005; // time step
double position_init = 1.0; // initial position for lowest bead.
double velocity_init = 0.0; // initial velocity for lowest bead.
double theta = 0.5; // theta for MoreauJeanOSI integrator
double R = 0.1; // Ball radius
double m = 1; // Ball mass
double g = 9.81; // Gravity
// -------------------------
// --- Dynamical systems ---
// -------------------------
cout << "====> Model loading ..." << endl << endl;
// Number of Beads
unsigned int nBeads = 10;
double initialGap = 0.25;
double alert = 0.02;
SP::SiconosMatrix Mass(new SimpleMatrix(nDof, nDof));
(*Mass)(0, 0) = m;
(*Mass)(1, 1) = m;
(*Mass)(2, 2) = 3. / 5 * m * R * R;
// -- Initial positions and velocities --
std::vector<SP::SiconosVector> q0(nBeads);
std::vector<SP::SiconosVector> v0(nBeads);
for (unsigned int i = 0; i < nBeads; i++)
{
(q0[i]).reset(new SiconosVector(nDof));
(v0[i]).reset(new SiconosVector(nDof));
(q0[i])->setValue(0, position_init + i * initialGap);
(v0[i])->setValue(0, velocity_init);
}
// -- The dynamical system --
SP::SiconosVector weight(new SiconosVector(nDof));
(*weight)(0) = -m * g;
std::vector<SP::LagrangianLinearTIDS> beads(nBeads);
for (unsigned int i = 0; i < nBeads; i++)
{
beads[i].reset(new LagrangianLinearTIDS(q0[i], v0[i], Mass));
// -- Set external forces (weight) --
beads[i]->setFExtPtr(weight);
}
// --------------------
// --- Interactions ---
// --------------------
// -- nslaw --
double e = 0.9;
// Interaction ball-floor
//
SP::SimpleMatrix H(new SimpleMatrix(1, nDof));
(*H)(0, 0) = 1.0;
SP::SiconosVector b(new SiconosVector(1));
(*b)(0) = -R;
SP::NonSmoothLaw nslaw(new NewtonImpactNSL(e));
SP::Relation relation(new LagrangianLinearTIR(H, b));
SP::Interaction inter;
// beads/beads interactions
SP::SimpleMatrix HOfBeads(new SimpleMatrix(1, 2 * nDof));
(*HOfBeads)(0, 0) = -1.0;
(*HOfBeads)(0, 3) = 1.0;
SP::SiconosVector bOfBeads(new SiconosVector(1));
(*bOfBeads)(0) = -2 * R;
// This doesn't work !!!
//SP::Relation relationOfBeads(new LagrangianLinearTIR(HOfBeads));
//std::vector<SP::Interaction > interOfBeads(nBeads-1);
// for (unsigned int i =0; i< nBeads-1; i++)
// {
// interOfBeads[i].reset(new Interaction(1, nslaw, relationOfBeads));
// }
// This works !!
std::vector<SP::Relation > relationOfBeads(nBeads - 1);
std::vector<SP::Interaction > interOfBeads(nBeads - 1);
// for (unsigned int i =0; i< nBeads-1; i++)
//.........这里部分代码省略.........
示例2: buildInteractions
//.........这里部分代码省略.........
dsb = static_cast<BulletDS*>(obB->getUserPointer())->shared_ptr();
assert(dsb->collisionObjects()->find(obB) != dsb->collisionObjects()->end());
gid2 = boost::get<2>((*((*dsb->collisionObjects()).find(obB))).second);
}
else
{
gid2 = (*_staticObjects->find(obB)).second.second;
}
DEBUG_PRINTF("collision between group %ld and %ld\n", gid1, gid2);
nslaw = (*_nslaws)(gid1, gid2);
if (!nslaw)
{
RuntimeException::selfThrow(
(boost::format("Cannot find nslaw for collision between group %1% and %2%") %
gid1 % gid2).str());
}
assert(nslaw);
std::map<btManifoldPoint*, bool>::iterator itc;
itc = contactPoints.find(&*cpoint);
DEBUG_EXPR(if (itc == contactPoints.end())
{
DEBUG_PRINT("contact point not found\n");
for(std::map<btManifoldPoint*, bool>::iterator itd=contactPoints.begin();
itd != contactPoints.end(); ++itd)
{
DEBUG_PRINTF("-->%p != %p\n", &*cpoint, &*(*itd).first);
}
});
if (itc == contactPoints.end() || !cpoint->m_userPersistentData)
{
/* new interaction */
SP::Interaction inter;
if (nslaw->size() == 3)
{
SP::BulletR rel(new BulletR(cpoint, createSPtrbtPersistentManifold(*contactManifold)));
inter.reset(new Interaction(3, nslaw, rel, 4 * i + z));
}
else
{
if (nslaw->size() == 1)
{
SP::BulletFrom1DLocalFrameR rel(new BulletFrom1DLocalFrameR(cpoint));
inter.reset(new Interaction(1, nslaw, rel, 4 * i + z));
}
}
if (obB->getUserPointer())
{
SP::BulletDS dsb(static_cast<BulletDS*>(obB->getUserPointer())->shared_ptr());
if (dsa != dsb)
{
DEBUG_PRINTF("LINK obA:%p obB:%p inter:%p\n", obA, obB, &*inter);
assert(inter);
cpoint->m_userPersistentData = &*inter;
link(inter, dsa, dsb);
}
/* else collision shapes belong to the same object do nothing */
}
else
{
DEBUG_PRINTF("LINK obA:%p inter :%p\n", obA, &*inter);
assert(inter);
cpoint->m_userPersistentData = &*inter;
link(inter, dsa);
}
}
if (cpoint->m_userPersistentData)
{
activeInteractions[static_cast<Interaction *>(cpoint->m_userPersistentData)] = true;
DEBUG_PRINTF("Interaction %p = true\n", static_cast<Interaction *>(cpoint->m_userPersistentData));
DEBUG_PRINTF("cpoint %p = true\n", &*cpoint);
}
else
{
assert(false);
DEBUG_PRINT("cpoint->m_userPersistentData is empty\n");
}
contactPoints[&*cpoint] = true;
DEBUG_PRINTF("cpoint %p = true\n", &*cpoint);
}
}
}