Skip to content

Commit

Permalink
Added capability to render multiple arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 15, 2023
1 parent f483d1b commit 96be82f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
46 changes: 29 additions & 17 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,39 @@ Geodesic_arcs::Geodesic_arcs()

vector<Curve> xcvs;
xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 1, 0)));
xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 1, 0), Dir3(0, 0, -1)));
xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 0, 1)));
xcvs.push_back(ctr_cv(ctr_p(0, 1, 0), ctr_p(0, 0, 1)));
//xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 1, 0), Dir3(0, 0, -1)));
//xcvs.push_back(ctr_cv(Dir3(0, 0, -1)));

auto approx = traits.approximate_2_object();

const double error = 0.001;
std::vector<Approximate_point_2> v;

const auto& xcv = xcvs[1];
//for (const auto& xcv : xcvs)

std::vector<QVector3D> vertex_data;

m_arc_offsets.clear();
m_arc_offsets.push_back(0);
for (const auto& xcv : xcvs)
{
std::vector<Approximate_point_2> v;
auto oi2 = approx(xcv, error, std::back_insert_iterator(v));

for (auto it = v.begin(); it != v.end(); ++it)
cout << *it << endl;
cout << "num points output = " << v.size() << endl;
}

//for (auto it = v.begin(); it != v.end(); ++it)
// cout << *it << endl;
//cout << "num points output = " << v.size() << endl;
for (const auto& p : v)
{
const QVector3D arc_point(p.dx(), p.dy(), p.dz());
vertex_data.push_back(arc_point);
}
//m_num_arc_points = v.size(); // CAREFUL: not size of vertex_data!!!
const auto current_vertex_data_size = vertex_data.size();
m_arc_offsets.push_back(current_vertex_data_size);
std::cout << "current_vertex_data_size = " << current_vertex_data_size << std::endl;

std::vector<QVector3D> vertex_data;
for (const auto& p : v)
{
const QVector3D arc_point(p.dx(), p.dy(), p.dz());
vertex_data.push_back(arc_point);
}
m_num_arc_points = v.size(); // CAREFUL: not size of vertex_data!!!
std::cout << "offset count = " << m_arc_offsets.size() << std::endl;


// DEFINE OPENGL BUFFERS
Expand Down Expand Up @@ -131,7 +138,12 @@ void Geodesic_arcs::draw()
{
glBindVertexArray(m_vao);
{
glDrawArrays(GL_LINE_STRIP, 0, m_num_arc_points);
for (int i = 1; i < m_arc_offsets.size(); i++)
{
const auto first = m_arc_offsets[i - 1];
const auto count = m_arc_offsets[i] - first;
glDrawArrays(GL_LINE_STRIP, first, count);
}
}
glBindVertexArray(0);
}
3 changes: 2 additions & 1 deletion Arrangement_on_surface_2/demo/earth/Geodesic_arcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define GEODESIC_ARCS_H

#include "Common_defs.h"

#include <vector>

class Geodesic_arcs : protected OpenGLFunctionsBase
{
Expand All @@ -14,6 +14,7 @@ class Geodesic_arcs : protected OpenGLFunctionsBase

private:
GLuint m_vao, m_vbo, m_num_arc_points;
std::vector<GLuint> m_arc_offsets;
};


Expand Down
3 changes: 2 additions & 1 deletion Arrangement_on_surface_2/demo/earth/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ void MainWidget::paintGL()
const auto cos_beta = sin_alpha;
const auto p = (r * cos_beta) * n;
QVector4D plane(n.x(), n.y(), n.z(), -QVector3D::dotProduct(p, n));
const QVector4D arc_color(1, 0.5, 0, 1);
const QVector4D arc_color(0, 0.5, 1, 1);
glLineWidth(5);
sp.set_uniform("u_color", arc_color);
sp.set_uniform("u_plane", plane);
m_geodesic_arcs->draw();
Expand Down

0 comments on commit 96be82f

Please sign in to comment.