Commit b0186557 by Philipp Adolf

Move irregular vertices for drawing

parent 9b2e2969
...@@ -1041,5 +1041,58 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic ...@@ -1041,5 +1041,58 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic
} }
void Subdivision::updateIrregularForDraw(const QVector<Triangle> &triangles,QMap<Triangle, Triangle::Neighbors> &neighbors, Result &result){ void Subdivision::updateIrregularForDraw(const QVector<Triangle> &triangles,QMap<Triangle, Triangle::Neighbors> &neighbors, Result &result){
result.vertex_buffer_irregular = result.vertex_buffer; result.vertex_buffer_irregular.resize(result.vertex_buffer.size());
QVectorIterator<Triangle> it(triangles);
while (it.hasNext()) {
Triangle triangle = it.next();
result.vertex_buffer_irregular[triangle.u_idx()] = result.vertex_buffer.at(triangle.u_idx());
result.vertex_buffer_irregular[triangle.v_idx()] = result.vertex_buffer.at(triangle.v_idx());
result.vertex_buffer_irregular[triangle.w_idx()] = result.vertex_buffer.at(triangle.w_idx());
Triangle::Neighbors ns = neighbors.value(triangle);
result.vertex_buffer_irregular[triangle.u_idx()].pos = updateIrregularVertexForDraw(triangle.u(), vertexNeighbors(triangle, ns.uv, neighbors));
result.vertex_buffer_irregular[triangle.v_idx()].pos = updateIrregularVertexForDraw(triangle.v(), vertexNeighbors(triangle, ns.vw, neighbors));
result.vertex_buffer_irregular[triangle.w_idx()].pos = updateIrregularVertexForDraw(triangle.w(), vertexNeighbors(triangle, ns.wu, neighbors));
}
}
bool Subdivision::containsVertex(QVector<Vertex> &vertices, Vertex vertex) {
for (int i = 0; i < vertices.length(); i++) {
if (vertex.samePos(vertices[i])) {
return true;
}
}
return false;
}
QVector3D Subdivision::updateIrregularVertexForDraw(Vertex currentCorner, QVector<Triangle> neighboring_triangles) {
QVector<Vertex> surroundingVertex;
QVectorIterator<Triangle> extra(neighboring_triangles);
while (extra.hasNext()) {
Triangle extra_triangle = extra.next();
if (!currentCorner.samePos(extra_triangle.u()) && !containsVertex(surroundingVertex, extra_triangle.u()))
surroundingVertex.push_back(extra_triangle.u());
if (!currentCorner.samePos(extra_triangle.v()) && !containsVertex(surroundingVertex, extra_triangle.v()))
surroundingVertex.push_back(extra_triangle.v());
if (!currentCorner.samePos(extra_triangle.w()) && !containsVertex(surroundingVertex, extra_triangle.w()))
surroundingVertex.push_back(extra_triangle.w());
}
QVector3D newPos(0.0, 0.0, 0.0);
double n = surroundingVertex.length();
double a = 5.0/8.0 - pow((3.0 / 8.0 + 2.0/8.0 * cos(2.0 * M_PI / n)), 2.0);
double omega = 3.0 * n / (8.0 * a);
for (int i = 0; i < surroundingVertex.length(); i++) {
newPos += surroundingVertex[i].pos;
}
newPos *= 1.0 / (omega + n);
newPos += omega / (omega + n) * currentCorner.pos;
return newPos;
} }
...@@ -71,6 +71,8 @@ private: ...@@ -71,6 +71,8 @@ private:
void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle, GLuint offset_handle); void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle, GLuint offset_handle);
void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset_handle); void runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indices_handle, GLuint output_handle, GLuint offset_handle);
void updateIrregularForDraw(const QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, Result &result); void updateIrregularForDraw(const QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, Result &result);
bool containsVertex(QVector<Vertex> &vertices, Vertex vertex);
QVector3D updateIrregularVertexForDraw(Vertex currentCorner, QVector<Triangle> neighboring_triangles);
QVector<unsigned int> patchIBToTriangleIB(QVector<unsigned int> ib); QVector<unsigned int> patchIBToTriangleIB(QVector<unsigned int> ib);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment