Commit 95d087ee by Philipp Adolf

temp

parent 85836b9d
...@@ -8,7 +8,7 @@ QT += core gui opengl ...@@ -8,7 +8,7 @@ QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11 CONFIG += c++11 debug
TARGET = Subdivision TARGET = Subdivision
TEMPLATE = app TEMPLATE = app
......
...@@ -1040,6 +1040,38 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic ...@@ -1040,6 +1040,38 @@ void Subdivision::runEdgeShader(GLuint size, GLuint vb_handle, GLuint edge_indic
edgeShader->release(); edgeShader->release();
} }
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() + 1;
qDebug() << n;
qDebug() << currentCorner;
qDebug() << surroundingVertex;
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 *= a / n;
newPos += omega * a / n * currentCorner.pos;
return newPos;
}
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.resize(result.vertex_buffer.size()); result.vertex_buffer_irregular.resize(result.vertex_buffer.size());
...@@ -1048,69 +1080,30 @@ void Subdivision::updateIrregularForDraw(const QVector<Triangle> &triangles,QMap ...@@ -1048,69 +1080,30 @@ void Subdivision::updateIrregularForDraw(const QVector<Triangle> &triangles,QMap
Triangle triangle = it.next(); Triangle triangle = it.next();
Triangle::Neighbors ns = neighbors.value(triangle); Triangle::Neighbors ns = neighbors.value(triangle);
QVector<Triangle> neighboring_triangles;
// u // u
Vertex currentCorner = triangle.u(); QVector3D new_u_pos = updateIrregularVertexForDraw(triangle.u(), vertexNeighbors(triangle, ns.uv, neighbors));
neighboring_triangles = vertexNeighbors(triangle, ns.uv, neighbors);
QVector<Vertex> surroundingVertex;
QVectorIterator<Triangle> extra(neighboring_triangles);
while (extra.hasNext()) {
Triangle extra_triangle = extra.next();
if(currentCorner.samePos(extra_triangle.u()) ){
bool found = false;
for (int i = 0; i < surroundingVertex.length() && !found; ++i) {
if(extra_triangle.u().samePos(surroundingVertex[i])){
found = true;
}
}
if(!found)
surroundingVertex.push_back(extra_triangle.u());
}
if(currentCorner.samePos(extra_triangle.v()) )
found = false;
for (int i = 0; i < surroundingVertex.length() && !found; ++i) {
if(extra_triangle.v().samePos(surroundingVertex[i])){
found = true;
}
}
if(!found)
surroundingVertex.push_back(extra_triangle.v());
Triangle extra_triangle = extra.next();
if(currentCorner.samePos(extra_triangle.w()) )
found = false;
for (int i = 0; i < surroundingVertex.length() && !found; ++i) {
if(extra_triangle.w().samePos(surroundingVertex[i])){
found = true;
}
}
if(!found)
surroundingVertex.push_back(extra_triangle.w());
}
//v //v
QVector3D new_v_pos = updateIrregularVertexForDraw(triangle.v(), vertexNeighbors(triangle, ns.vw, neighbors));
//w //w
QVector3D new_w_pos = updateIrregularVertexForDraw(triangle.w(), vertexNeighbors(triangle, ns.wu, neighbors));
neighboring_triangles += vertexNeighbors(triangle, ns.vw, neighbors);
neighboring_triangles += vertexNeighbors(triangle, ns.wu, neighbors);
result.vertex_buffer_irregular[triangle.u_idx()] = result.vertex_buffer.at(triangle.u_idx()); result.vertex_buffer_irregular[triangle.u_idx()] = result.vertex_buffer.at(triangle.u_idx());
result.vertex_buffer_irregular[triangle.u_idx()].pos = new_u_pos;
result.vertex_buffer_irregular[triangle.v_idx()] = result.vertex_buffer.at(triangle.v_idx()); result.vertex_buffer_irregular[triangle.v_idx()] = result.vertex_buffer.at(triangle.v_idx());
result.vertex_buffer_irregular[triangle.v_idx()].pos = new_v_pos;
result.vertex_buffer_irregular[triangle.w_idx()] = result.vertex_buffer.at(triangle.w_idx()); result.vertex_buffer_irregular[triangle.w_idx()] = result.vertex_buffer.at(triangle.w_idx());
result.vertex_buffer_irregular[triangle.w_idx()].pos = new_w_pos;
} }
}
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;
} }
...@@ -70,7 +70,9 @@ private: ...@@ -70,7 +70,9 @@ private:
void runCopyShader(GLuint size, GLuint vb_in, GLuint vb_out); void runCopyShader(GLuint size, GLuint vb_in, GLuint vb_out);
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);
QVector3D updateIrregularVertexForDraw(Vertex currentCorner, QVector<Triangle> neighboring_triangles);
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);
......
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