本文整理汇总了C++中SimulationModel::getTetModels方法的典型用法代码示例。如果您正苦于以下问题:C++ SimulationModel::getTetModels方法的具体用法?C++ SimulationModel::getTetModels怎么用?C++ SimulationModel::getTetModels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimulationModel
的用法示例。
在下文中一共展示了SimulationModel::getTetModels方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: timeStep
void timeStep ()
{
if (doPause)
return;
// Simulation code
for (unsigned int i = 0; i < 8; i++)
sim.step(model);
for (unsigned int i = 0; i < model.getTetModels().size(); i++)
model.getTetModels()[i]->updateMeshNormals(model.getParticles());
}
示例2: 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);
}
}
示例3: 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();
}
示例4: timeStep
void timeStep ()
{
const Real pauseAt = base->getValue<Real>(DemoBase::PAUSE_AT);
if ((pauseAt > 0.0) && (pauseAt < TimeManager::getCurrent()->getTime()))
base->setValue(DemoBase::PAUSE, true);
if (base->getValue<bool>(DemoBase::PAUSE))
return;
// Simulation code
SimulationModel *model = Simulation::getCurrent()->getModel();
const unsigned int numSteps = base->getValue<unsigned int>(DemoBase::NUM_STEPS_PER_RENDER);
for (unsigned int i = 0; i < numSteps; i++)
{
START_TIMING("SimStep");
Simulation::getCurrent()->getTimeStep()->step(*model);
STOP_TIMING_AVG;
}
for (unsigned int i = 0; i < model->getTetModels().size(); i++)
{
model->getTetModels()[i]->updateMeshNormals(model->getParticles());
}
}
示例5: createMesh
void createMesh()
{
Vector3r points[width*height*depth];
for (unsigned int i = 0; i < width; i++)
{
for (unsigned int j = 0; j < height; j++)
{
for (unsigned int k = 0; k < depth; k++)
{
points[i*height*depth + j*depth + k] = 0.3*Vector3r((Real)i, (Real)j, (Real)k);
}
}
}
vector<unsigned int> indices;
for (unsigned int i = 0; i < width - 1; i++)
{
for (unsigned int j = 0; j < height - 1; j++)
{
for (unsigned int k = 0; k < depth - 1; k++)
{
// For each block, the 8 corners are numerated as:
// 4*-----*7
// /| /|
// / | / |
// 5*-----*6 |
// | 0*--|--*3
// | / | /
// |/ |/
// 1*-----*2
unsigned int p0 = i*height*depth + j*depth + k;
unsigned int p1 = p0 + 1;
unsigned int p3 = (i + 1)*height*depth + j*depth + k;
unsigned int p2 = p3 + 1;
unsigned int p7 = (i + 1)*height*depth + (j + 1)*depth + k;
unsigned int p6 = p7 + 1;
unsigned int p4 = i*height*depth + (j + 1)*depth + k;
unsigned int p5 = p4 + 1;
// Ensure that neighboring tetras are sharing faces
if ((i + j + k) % 2 == 1)
{
indices.push_back(p2); indices.push_back(p1); indices.push_back(p6); indices.push_back(p3);
indices.push_back(p6); indices.push_back(p3); indices.push_back(p4); indices.push_back(p7);
indices.push_back(p4); indices.push_back(p1); indices.push_back(p6); indices.push_back(p5);
indices.push_back(p3); indices.push_back(p1); indices.push_back(p4); indices.push_back(p0);
indices.push_back(p6); indices.push_back(p1); indices.push_back(p4); indices.push_back(p3);
}
else
{
indices.push_back(p0); indices.push_back(p2); indices.push_back(p5); indices.push_back(p1);
indices.push_back(p7); indices.push_back(p2); indices.push_back(p0); indices.push_back(p3);
indices.push_back(p5); indices.push_back(p2); indices.push_back(p7); indices.push_back(p6);
indices.push_back(p7); indices.push_back(p0); indices.push_back(p5); indices.push_back(p4);
indices.push_back(p0); indices.push_back(p2); indices.push_back(p7); indices.push_back(p5);
}
}
}
}
SimulationModel *model = Simulation::getCurrent()->getModel();
model->addTetModel(width*height*depth, (unsigned int)indices.size() / 4u, points, indices.data());
ParticleData &pd = model->getParticles();
for (unsigned int i = 0; i < pd.getNumberOfParticles(); i++)
{
pd.setMass(i, 1.0);
}
for (unsigned int i = 0; i < 1; i++)
{
for (unsigned int j = 0; j < height; j++)
{
for (unsigned int k = 0; k < depth; k++)
pd.setMass(i*height*depth + j*depth + k, 0.0);
}
}
// init constraints
for (unsigned int cm = 0; cm < model->getTetModels().size(); cm++)
{
const unsigned int nTets = model->getTetModels()[cm]->getParticleMesh().numTets();
const unsigned int *tets = model->getTetModels()[cm]->getParticleMesh().getTets().data();
const IndexedTetMesh::VertexTets *vTets = model->getTetModels()[cm]->getParticleMesh().getVertexTets().data();
if (simulationMethod == 1)
{
const unsigned int offset = model->getTetModels()[cm]->getIndexOffset();
const unsigned int nEdges = model->getTetModels()[cm]->getParticleMesh().numEdges();
const IndexedTetMesh::Edge *edges = model->getTetModels()[cm]->getParticleMesh().getEdges().data();
for (unsigned int i = 0; i < nEdges; i++)
{
const unsigned int v1 = edges[i].m_vert[0] + offset;
const unsigned int v2 = edges[i].m_vert[1] + offset;
model->addDistanceConstraint(v1, v2);
}
for (unsigned int i = 0; i < nTets; i++)
{
const unsigned int v1 = tets[4 * i];
const unsigned int v2 = tets[4 * i + 1];
const unsigned int v3 = tets[4 * i + 2];
//.........这里部分代码省略.........