本文整理汇总了C++中SimulationModel::getTriangleModels方法的典型用法代码示例。如果您正苦于以下问题:C++ SimulationModel::getTriangleModels方法的具体用法?C++ SimulationModel::getTriangleModels怎么用?C++ SimulationModel::getTriangleModels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimulationModel
的用法示例。
在下文中一共展示了SimulationModel::getTriangleModels方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderTriangleModels
void renderTriangleModels()
{
// 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.getTriangleModels().size(); i++)
{
// mesh
TriangleModel *triModel = model.getTriangleModels()[i];
const IndexedFaceMesh &mesh = triModel->getParticleMesh();
Visualization::drawTexturedMesh(pd, mesh, triModel->getIndexOffset(), surfaceColor);
}
if (shader)
shader->end();
}
示例2: 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.getTriangleModels().size(); i++)
model.getTriangleModels()[i]->updateMeshNormals(model.getParticles());
}
示例3: renderTriangleModels
void renderTriangleModels()
{
// Draw simulation model
const ParticleData &pd = model.getParticles();
for (unsigned int i = 0; i < model.getTriangleModels().size(); i++)
{
// mesh
const IndexedFaceMesh &mesh = model.getTriangleModels()[i]->getParticleMesh();
const unsigned int *faces = mesh.getFaces().data();
const unsigned int nFaces = mesh.numFaces();
const Eigen::Vector3f *vertexNormals = mesh.getVertexNormals().data();
const Eigen::Vector2f *uvs = mesh.getUVs().data();
float surfaceColor[4] = { 0.2f, 0.5f, 1.0f, 1 };
float speccolor[4] = { 1.0, 1.0, 1.0, 1.0 };
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, surfaceColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, surfaceColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, speccolor);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);
glColor3fv(surfaceColor);
MiniGL::bindTexture();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &pd.getPosition(model.getTriangleModels()[i]->getIndexOffset())[0]);
glTexCoordPointer(2, GL_FLOAT, 0, &uvs[0][0]);
glNormalPointer(GL_FLOAT, 0, &vertexNormals[0][0]);
glDrawElements(GL_TRIANGLES, (GLsizei)3 * mesh.numFaces(), GL_UNSIGNED_INT, mesh.getFaces().data());
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
MiniGL::unbindTexture();
}
}
示例4: renderTriangleModels
void renderTriangleModels()
{
// Draw simulation model
const ParticleData &pd = model.getParticles();
float surfaceColor[4] = { 0.2f, 0.5f, 1.0f, 1 };
if (shaderTex)
{
shaderTex->begin();
glUniform3fv(shaderTex->getUniform("surface_color"), 1, surfaceColor);
glUniform1f(shaderTex->getUniform("shininess"), 5.0f);
glUniform1f(shaderTex->getUniform("specular_factor"), 0.2f);
GLfloat matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
glUniformMatrix4fv(shaderTex->getUniform("modelview_matrix"), 1, GL_FALSE, matrix);
GLfloat pmatrix[16];
glGetFloatv(GL_PROJECTION_MATRIX, pmatrix);
glUniformMatrix4fv(shaderTex->getUniform("projection_matrix"), 1, GL_FALSE, pmatrix);
}
for (unsigned int i = 0; i < model.getTriangleModels().size(); i++)
{
// mesh
const IndexedFaceMesh &mesh = model.getTriangleModels()[i]->getParticleMesh();
Visualization::drawTexturedMesh(pd, mesh, surfaceColor);
}
if (shaderTex)
shaderTex->end();
float red[4] = { 0.8f, 0.0f, 0.0f, 1 };
for (unsigned int j = 0; j < selectedParticles.size(); j++)
{
MiniGL::drawSphere(pd.getPosition(selectedParticles[j]), 0.08f, red);
}
}
示例5: createMesh
/** Create a particle model mesh
*/
void createMesh()
{
TriangleModel::ParticleMesh::UVs uvs;
uvs.resize(nRows*nCols);
const Real dy = width / (Real)(nCols - 1);
const Real dx = height / (Real)(nRows - 1);
Vector3r points[nRows*nCols];
for (int i = 0; i < nRows; i++)
{
for (int j = 0; j < nCols; j++)
{
const Real y = (Real)dy*j;
const Real x = (Real)dx*i;
points[i*nCols + j] = Vector3r(x, 1.0, y);
uvs[i*nCols + j][0] = x/width;
uvs[i*nCols + j][1] = y/height;
}
}
const int nIndices = 6 * (nRows - 1)*(nCols - 1);
TriangleModel::ParticleMesh::UVIndices uvIndices;
uvIndices.resize(nIndices);
unsigned int indices[nIndices];
int index = 0;
for (int i = 0; i < nRows - 1; i++)
{
for (int j = 0; j < nCols - 1; j++)
{
int helper = 0;
if (i % 2 == j % 2)
helper = 1;
indices[index] = i*nCols + j;
indices[index + 1] = i*nCols + j + 1;
indices[index + 2] = (i + 1)*nCols + j + helper;
uvIndices[index] = i*nCols + j;
uvIndices[index + 1] = i*nCols + j + 1;
uvIndices[index + 2] = (i + 1)*nCols + j + helper;
index += 3;
indices[index] = (i + 1)*nCols + j + 1;
indices[index + 1] = (i + 1)*nCols + j;
indices[index + 2] = i*nCols + j + 1 - helper;
uvIndices[index] = (i + 1)*nCols + j + 1;
uvIndices[index + 1] = (i + 1)*nCols + j;
uvIndices[index + 2] = i*nCols + j + 1 - helper;
index += 3;
}
}
model.addTriangleModel(nRows*nCols, nIndices / 3, &points[0], &indices[0], uvIndices, uvs);
ParticleData &pd = model.getParticles();
for (unsigned int i = 0; i < pd.getNumberOfParticles(); i++)
{
pd.setMass(i, 1.0);
}
// Set mass of points to zero => make it static
pd.setMass(0, 0.0);
pd.setMass((nRows-1)*nCols, 0.0);
// init constraints
for (unsigned int cm = 0; cm < model.getTriangleModels().size(); cm++)
{
if (simulationMethod == 1)
{
const unsigned int offset = model.getTriangleModels()[cm]->getIndexOffset();
const unsigned int nEdges = model.getTriangleModels()[cm]->getParticleMesh().numEdges();
const IndexedFaceMesh::Edge *edges = model.getTriangleModels()[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);
}
}
else if (simulationMethod == 2)
{
const unsigned int offset = model.getTriangleModels()[cm]->getIndexOffset();
TriangleModel::ParticleMesh &mesh = model.getTriangleModels()[cm]->getParticleMesh();
const unsigned int *tris = mesh.getFaces().data();
const unsigned int nFaces = mesh.numFaces();
for (unsigned int i = 0; i < nFaces; i++)
{
const unsigned int v1 = tris[3 * i] + offset;
const unsigned int v2 = tris[3 * i + 1] + offset;
const unsigned int v3 = tris[3 * i + 2] + offset;
model.addFEMTriangleConstraint(v1, v2, v3);
}
}
//.........这里部分代码省略.........