本文整理汇总了C++中SurfaceMesh::getVertices方法的典型用法代码示例。如果您正苦于以下问题:C++ SurfaceMesh::getVertices方法的具体用法?C++ SurfaceMesh::getVertices怎么用?C++ SurfaceMesh::getVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SurfaceMesh
的用法示例。
在下文中一共展示了SurfaceMesh::getVertices方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildOpenGLSurfaceMesh
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal>& mesh)
{
//Represents our filled in OpenGL vertex and index buffer objects.
OpenGLSurfaceMesh result;
//The source
result.sourceMesh = &mesh;
//Convienient access to the vertices and indices
const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
const vector<uint32_t>& vecIndices = mesh.getIndices();
//If we have any indices...
if(!vecIndices.empty())
{
//Create an OpenGL index buffer
glGenBuffers(1, &result.indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.indexBuffer);
//Get a pointer to the first index
GLvoid* pIndices = (GLvoid*)(&(vecIndices[0]));
//Fill the OpenGL index buffer with our data.
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
}
result.noOfIndices = vecIndices.size();
glGenBuffers(1, &result.vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, result.vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(GLfloat) * 9, 0, GL_STATIC_DRAW);
GLfloat* ptr = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
for(vector<PositionMaterialNormal>::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
{
const PositionMaterialNormal& vertex = *iterVertex;
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
*ptr = v3dFinalVertexPos.getX();
ptr++;
*ptr = v3dFinalVertexPos.getY();
ptr++;
*ptr = v3dFinalVertexPos.getZ();
ptr++;
*ptr = vertex.getNormal().getX();
ptr++;
*ptr = vertex.getNormal().getY();
ptr++;
*ptr = vertex.getNormal().getZ();
ptr++;
uint8_t material = vertex.getMaterial() + 0.5;
OpenGLColour colour = convertMaterialIDToColour(material);
*ptr = colour.red;
ptr++;
*ptr = colour.green;
ptr++;
*ptr = colour.blue;
ptr++;
}
glUnmapBuffer(GL_ARRAY_BUFFER);
return result;
}