本文整理汇总了C++中SimulationModel::getRigidBodies方法的典型用法代码示例。如果您正苦于以下问题:C++ SimulationModel::getRigidBodies方法的具体用法?C++ SimulationModel::getRigidBodies怎么用?C++ SimulationModel::getRigidBodies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimulationModel
的用法示例。
在下文中一共展示了SimulationModel::getRigidBodies方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildModel
void buildModel ()
{
TimeManager::getCurrent ()->setTimeStepSize (0.005);
createMesh();
// create static rigid body
string fileName = dataPath + "/models/cube.obj";
IndexedFaceMesh mesh;
VertexData vd;
OBJLoader::loadObj(fileName, vd, mesh);
string fileNameTorus = dataPath + "/models/torus.obj";
IndexedFaceMesh meshTorus;
VertexData vdTorus;
OBJLoader::loadObj(fileNameTorus, vdTorus, meshTorus);
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
rb.resize(2);
// floor
rb[0] = new RigidBody();
rb[0]->initBody(1.0,
Vector3r(0.0, -5.5, 0.0),
Quaternionr(1.0, 0.0, 0.0, 0.0),
vd, mesh,
Vector3r(100.0, 1.0, 100.0));
rb[0]->setMass(0.0);
// torus
rb[1] = new RigidBody();
rb[1]->initBody(1.0,
Vector3r(5.0, -1.5, 0.0),
Quaternionr(1.0, 0.0, 0.0, 0.0),
vdTorus, meshTorus,
Vector3r(3.0, 3.0, 3.0));
rb[1]->setMass(0.0);
rb[1]->setFrictionCoeff(0.1);
sim.setCollisionDetection(model, &cd);
cd.setTolerance(0.05);
const std::vector<Vector3r> *vertices1 = rb[0]->getGeometry().getVertexDataLocal().getVertices();
const unsigned int nVert1 = static_cast<unsigned int>(vertices1->size());
cd.addCollisionBox(0, CollisionDetection::CollisionObject::RigidBodyCollisionObjectType, &(*vertices1)[0], nVert1, Vector3r(100.0, 1.0, 100.0));
const std::vector<Vector3r> *vertices2 = rb[1]->getGeometry().getVertexDataLocal().getVertices();
const unsigned int nVert2 = static_cast<unsigned int>(vertices2->size());
cd.addCollisionTorus(1, CollisionDetection::CollisionObject::RigidBodyCollisionObjectType, &(*vertices2)[0], nVert2, Vector2r(3.0, 1.5));
SimulationModel::TetModelVector &tm = model.getTetModels();
ParticleData &pd = model.getParticles();
for (unsigned int i = 0; i < tm.size(); i++)
{
const unsigned int nVert = tm[i]->getParticleMesh().numVertices();
unsigned int offset = tm[i]->getIndexOffset();
tm[i]->setFrictionCoeff(0.1);
cd.addCollisionObjectWithoutGeometry(i, CollisionDetection::CollisionObject::TetModelCollisionObjectType, &pd.getPosition(offset), nVert);
}
}
示例2: clearAccelerations
void TimeStepController::clearAccelerations(SimulationModel &model)
{
//////////////////////////////////////////////////////////////////////////
// rigid body model
//////////////////////////////////////////////////////////////////////////
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
const Eigen::Vector3f grav(0.0f, -9.81f, 0.0f);
for (size_t i=0; i < rb.size(); i++)
{
// Clear accelerations of dynamic particles
if (rb[i]->getMass() != 0.0)
{
Eigen::Vector3f &a = rb[i]->getAcceleration();
a = grav;
}
}
//////////////////////////////////////////////////////////////////////////
// particle model
//////////////////////////////////////////////////////////////////////////
ParticleData &pd = model.getParticles();
const unsigned int count = pd.size();
for (unsigned int i = 0; i < count; i++)
{
// Clear accelerations of dynamic particles
if (pd.getMass(i) != 0.0)
{
Eigen::Vector3f &a = pd.getAcceleration(i);
a = grav;
}
}
}
示例3: initConstraint
//////////////////////////////////////////////////////////////////////////
// ParticleRigidBodyContactConstraint
//////////////////////////////////////////////////////////////////////////
bool ParticleRigidBodyContactConstraint::initConstraint(SimulationModel &model,
const unsigned int particleIndex, const unsigned int rbIndex,
const Vector3r &cp1, const Vector3r &cp2,
const Vector3r &normal, const Real dist,
const Real restitutionCoeff, const Real stiffness, const Real frictionCoeff)
{
m_stiffness = stiffness;
m_frictionCoeff = frictionCoeff;
m_bodies[0] = particleIndex;
m_bodies[1] = rbIndex;
SimulationModel::RigidBodyVector &rbs = model.getRigidBodies();
ParticleData &pd = model.getParticles();
RigidBody &rb = *rbs[m_bodies[1]];
m_sum_impulses = 0.0;
return PositionBasedRigidBodyDynamics::init_ParticleRigidBodyContactConstraint(
pd.getInvMass(particleIndex),
pd.getPosition(particleIndex),
pd.getVelocity(particleIndex),
rb.getInvMass(),
rb.getPosition(),
rb.getVelocity(),
rb.getInertiaTensorInverseW(),
rb.getRotation(),
rb.getAngularVelocity(),
cp1, cp2, normal, restitutionCoeff,
m_constraintInfo);
}
示例4: selection
void selection(const Eigen::Vector2i &start, const Eigen::Vector2i &end)
{
std::vector<unsigned int> hits;
selectedParticles.clear();
ParticleData &pd = model.getParticles();
Selection::selectRect(start, end, &pd.getPosition(0), &pd.getPosition(pd.size() - 1), selectedParticles);
selectedBodies.clear();
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > x;
x.resize(rb.size());
for (unsigned int i = 0; i < rb.size(); i++)
{
x[i] = rb[i]->getPosition();
}
Selection::selectRect(start, end, &x[0], &x[rb.size() - 1], selectedBodies);
if ((selectedBodies.size() > 0) || (selectedParticles.size() > 0))
MiniGL::setMouseMoveFunc(GLUT_MIDDLE_BUTTON, mouseMove);
else
MiniGL::setMouseMoveFunc(-1, NULL);
MiniGL::unproject(end[0], end[1], oldMousePos);
}
示例5: constraintProjection
void TimeStepController::constraintProjection(SimulationModel &model)
{
const unsigned int maxIter = 5;
unsigned int iter = 0;
// init constraint groups if necessary
model.initConstraintGroups();
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
SimulationModel::ConstraintVector &constraints = model.getConstraints();
SimulationModel::ConstraintGroupVector &groups = model.getConstraintGroups();
while (iter < maxIter)
{
for (unsigned int group = 0; group < groups.size(); group++)
{
#pragma omp parallel default(shared)
{
#pragma omp for schedule(static)
for (int i = 0; i < (int)groups[group].size(); i++)
{
const unsigned int constraintIndex = groups[group][i];
constraints[constraintIndex]->updateConstraint(model);
constraints[constraintIndex]->solveConstraint(model);
}
}
}
iter++;
}
}
示例6: updateConstraint
bool RigidBodyParticleBallJoint::updateConstraint(SimulationModel &model)
{
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
ParticleData &pd = model.getParticles();
RigidBody &rb1 = *rb[m_bodies[0]];
return PositionBasedRigidBodyDynamics::update_RigidBodyParticleBallJoint(
rb1.getPosition(),
rb1.getRotation(),
pd.getPosition(m_bodies[1]),
m_jointInfo);
}
示例7: velocityConstraintProjection
void TimeStepController::velocityConstraintProjection(SimulationModel &model)
{
unsigned int iter = 0;
// init constraint groups if necessary
model.initConstraintGroups();
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
SimulationModel::ConstraintVector &constraints = model.getConstraints();
SimulationModel::ConstraintGroupVector &groups = model.getConstraintGroups();
SimulationModel::RigidBodyContactConstraintVector &rigidBodyContacts = model.getRigidBodyContactConstraints();
SimulationModel::ParticleRigidBodyContactConstraintVector &particleRigidBodyContacts = model.getParticleRigidBodyContactConstraints();
for (unsigned int group = 0; group < groups.size(); group++)
{
const int groupSize = (int)groups[group].size();
#pragma omp parallel if(groupSize > MIN_PARALLEL_SIZE) default(shared)
{
#pragma omp for schedule(static)
for (int i = 0; i < groupSize; i++)
{
const unsigned int constraintIndex = groups[group][i];
constraints[constraintIndex]->updateConstraint(model);
}
}
}
while (iter < m_maxIterVel)
{
for (unsigned int group = 0; group < groups.size(); group++)
{
const int groupSize = (int)groups[group].size();
#pragma omp parallel if(groupSize > MIN_PARALLEL_SIZE) default(shared)
{
#pragma omp for schedule(static)
for (int i = 0; i < groupSize; i++)
{
const unsigned int constraintIndex = groups[group][i];
constraints[constraintIndex]->solveVelocityConstraint(model);
}
}
}
// solve contacts
for (unsigned int i = 0; i < rigidBodyContacts.size(); i++)
rigidBodyContacts[i].solveVelocityConstraint(model);
for (unsigned int i = 0; i < particleRigidBodyContacts.size(); i++)
particleRigidBodyContacts[i].solveVelocityConstraint(model);
iter++;
}
}
示例8: initConstraint
//////////////////////////////////////////////////////////////////////////
// RigidBodyParticleBallJoint
//////////////////////////////////////////////////////////////////////////
bool RigidBodyParticleBallJoint::initConstraint(SimulationModel &model, const unsigned int rbIndex, const unsigned int particleIndex)
{
m_bodies[0] = rbIndex;
m_bodies[1] = particleIndex;
SimulationModel::RigidBodyVector &rbs = model.getRigidBodies();
ParticleData &pd = model.getParticles();
RigidBody &rb = *rbs[m_bodies[0]];
return PositionBasedRigidBodyDynamics::init_RigidBodyParticleBallJoint(
rb.getPosition(),
rb.getRotation(),
pd.getPosition(particleIndex),
m_jointInfo);
}
示例9: mouseMove
void mouseMove(int x, int y)
{
Vector3r mousePos;
MiniGL::unproject(x, y, mousePos);
const Vector3r diff = mousePos - oldMousePos;
TimeManager *tm = TimeManager::getCurrent();
const float h = tm->getTimeStepSize();
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
for (size_t j = 0; j < selectedBodies.size(); j++)
{
rb[selectedBodies[j]]->getVelocity() += 1.0f / h * diff;
}
oldMousePos = mousePos;
}
示例10: clearAccelerations
void TimeStepController::clearAccelerations(SimulationModel &model)
{
//////////////////////////////////////////////////////////////////////////
// rigid body model
//////////////////////////////////////////////////////////////////////////
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
for (size_t i=0; i < rb.size(); i++)
{
// Clear accelerations of dynamic particles
if (rb[i]->getMass() != 0.0)
{
Vector3r &a = rb[i]->getAcceleration();
a = m_gravity;
}
}
//////////////////////////////////////////////////////////////////////////
// particle model
//////////////////////////////////////////////////////////////////////////
ParticleData &pd = model.getParticles();
const unsigned int count = pd.size();
for (unsigned int i = 0; i < count; i++)
{
// Clear accelerations of dynamic particles
if (pd.getMass(i) != 0.0)
{
Vector3r &a = pd.getAcceleration(i);
a = m_gravity;
}
}
ParticleData &pg = model.getGhostParticles();
for (unsigned int i = 0; i < pg.size(); i++)
{
// Clear accelerations of dynamic particles
if (pg.getMass(i) != 0.0)
{
Vector3r &a = pg.getAcceleration(i);
//a = grav;
a.setZero();
}
}
}
示例11: solvePositionConstraint
bool TargetAngleMotorHingeJoint::solvePositionConstraint(SimulationModel &model)
{
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
RigidBody &rb1 = *rb[m_bodies[0]];
RigidBody &rb2 = *rb[m_bodies[1]];
Eigen::Vector3f corr_x1, corr_x2;
Eigen::Quaternionf corr_q1, corr_q2;
const bool res = PositionBasedRigidBodyDynamics::solve_TargetAngleMotorHingeJoint(
rb1.getInvMass(),
rb1.getPosition(),
rb1.getInertiaTensorInverseW(),
rb1.getRotation(),
rb2.getInvMass(),
rb2.getPosition(),
rb2.getInertiaTensorInverseW(),
rb2.getRotation(),
m_targetAngle,
m_jointInfo,
corr_x1,
corr_q1,
corr_x2,
corr_q2);
if (res)
{
if (rb1.getMass() != 0.0f)
{
rb1.getPosition() += corr_x1;
rb1.getRotation().coeffs() += corr_q1.coeffs();
rb1.getRotation().normalize();
rb1.rotationUpdated();
}
if (rb2.getMass() != 0.0f)
{
rb2.getPosition() += corr_x2;
rb2.getRotation().coeffs() += corr_q2.coeffs();
rb2.getRotation().normalize();
rb2.rotationUpdated();
}
}
return res;
}
示例12: solveVelocityConstraint
bool RigidBodyContactConstraint::solveVelocityConstraint(SimulationModel &model)
{
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
RigidBody &rb1 = *rb[m_bodies[0]];
RigidBody &rb2 = *rb[m_bodies[1]];
Vector3r corr_v1, corr_v2;
Vector3r corr_omega1, corr_omega2;
const bool res = PositionBasedRigidBodyDynamics::velocitySolve_RigidBodyContactConstraint(
rb1.getInvMass(),
rb1.getPosition(),
rb1.getVelocity(),
rb1.getInertiaTensorInverseW(),
rb1.getAngularVelocity(),
rb2.getInvMass(),
rb2.getPosition(),
rb2.getVelocity(),
rb2.getInertiaTensorInverseW(),
rb2.getAngularVelocity(),
m_stiffness,
m_frictionCoeff,
m_sum_impulses,
m_constraintInfo,
corr_v1,
corr_omega1,
corr_v2,
corr_omega2);
if (res)
{
if (rb1.getMass() != 0.0)
{
rb1.getVelocity() += corr_v1;
rb1.getAngularVelocity() += corr_omega1;
}
if (rb2.getMass() != 0.0)
{
rb2.getVelocity() += corr_v2;
rb2.getAngularVelocity() += corr_omega2;
}
}
return res;
}
示例13: renderModels
void renderModels()
{
// Draw simulation model
const ParticleData &pd = model.getParticles();
float surfaceColor[4] = { 0.2f, 0.5f, 1.0f, 1 };
if (shader)
{
shader->begin();
glUniform3fv(shader->getUniform("surface_color"), 1, surfaceColor);
glUniform1f(shader->getUniform("shininess"), 5.0f);
glUniform1f(shader->getUniform("specular_factor"), 0.2f);
GLfloat matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
glUniformMatrix4fv(shader->getUniform("modelview_matrix"), 1, GL_FALSE, matrix);
GLfloat pmatrix[16];
glGetFloatv(GL_PROJECTION_MATRIX, pmatrix);
glUniformMatrix4fv(shader->getUniform("projection_matrix"), 1, GL_FALSE, pmatrix);
}
for (unsigned int i = 0; i < model.getTetModels().size(); i++)
{
TetModel *tetModel = model.getTetModels()[i];
const IndexedFaceMesh &surfaceMesh = tetModel->getSurfaceMesh();
Visualization::drawMesh(pd, surfaceMesh, tetModel->getIndexOffset(), surfaceColor);
}
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
float rbColor[4] = { 0.4f, 0.4f, 0.4f, 1 };
for (size_t i = 0; i < rb.size(); i++)
{
const VertexData &vd = rb[i]->getGeometry().getVertexData();
const IndexedFaceMesh &mesh = rb[i]->getGeometry().getMesh();
if (shader)
glUniform3fv(shader->getUniform("surface_color"), 1, rbColor);
Visualization::drawTexturedMesh(vd, mesh, 0, rbColor);
}
if (shader)
shader->end();
}
示例14: solveVelocityConstraint
bool TargetVelocityMotorHingeJoint::solveVelocityConstraint(SimulationModel &model)
{
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
RigidBody &rb1 = *rb[m_bodies[0]];
RigidBody &rb2 = *rb[m_bodies[1]];
Eigen::Vector3f corr_v1, corr_v2;
Eigen::Vector3f corr_omega1, corr_omega2;
const bool res = PositionBasedRigidBodyDynamics::velocitySolve_TargetVelocityMotorHingeJoint(
rb1.getInvMass(),
rb1.getPosition(),
rb1.getVelocity(),
rb1.getInertiaTensorInverseW(),
rb1.getAngularVelocity(),
rb2.getInvMass(),
rb2.getPosition(),
rb2.getVelocity(),
rb2.getInertiaTensorInverseW(),
rb2.getAngularVelocity(),
m_targetAngularVelocity,
m_jointInfo,
corr_v1,
corr_omega1,
corr_v2,
corr_omega2);
if (res)
{
if (rb1.getMass() != 0.0f)
{
rb1.getVelocity() += corr_v1;
rb1.getAngularVelocity() += corr_omega1;
}
if (rb2.getMass() != 0.0f)
{
rb2.getVelocity() += corr_v2;
rb2.getAngularVelocity() += corr_omega2;
}
}
return res;
}
示例15: mouseMove
void mouseMove(int x, int y)
{
Eigen::Vector3f mousePos;
MiniGL::unproject(x, y, mousePos);
const Eigen::Vector3f diff = mousePos - oldMousePos;
TimeManager *tm = TimeManager::getCurrent();
const float h = tm->getTimeStepSize();
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
for (size_t j = 0; j < selectedBodies.size(); j++)
{
rb[selectedBodies[j]]->getVelocity() += 1.0f / h * diff;
}
ParticleData &pd = model.getParticles();
for (unsigned int j = 0; j < selectedParticles.size(); j++)
{
pd.getVelocity(selectedParticles[j]) += 5.0*diff / h;
}
oldMousePos = mousePos;
}