Commit c2f693a5 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

continued with plotter

parent 6fba1fd9
...@@ -2082,7 +2082,7 @@ requires is_vec<t_vec> ...@@ -2082,7 +2082,7 @@ requires is_vec<t_vec>
} }
// normals // face normals
auto itervert = vertices.begin(); auto itervert = vertices.begin();
// iterate over triplets forming triangles // iterate over triplets forming triangles
while(itervert != vertices.end()) while(itervert != vertices.end())
...@@ -2531,6 +2531,72 @@ requires is_vec<t_vec> ...@@ -2531,6 +2531,72 @@ requires is_vec<t_vec>
} }
/**
* create the faces of a dodecahedron
* returns [vertices, face vertex indices, face normals, face uvs]
*/
template<class t_vec, template<class...> class t_cont = std::vector>
std::tuple<t_cont<t_vec>, t_cont<t_cont<std::size_t>>, t_cont<t_vec>, t_cont<t_cont<t_vec>>>
create_dodecahedron(typename t_vec::value_type l = 1)
requires is_vec<t_vec>
{
using T = typename t_vec::value_type;
const T g = golden<T>;
t_cont<t_vec> vertices =
{
create<t_vec>({ 1, 1, 1 }), create<t_vec>({ 1, 1, -1 }),
create<t_vec>({ 1, -1, 1 }), create<t_vec>({ 1, -1, -1 }),
create<t_vec>({ -1, 1, 1 }), create<t_vec>({ -1, 1, -1 }),
create<t_vec>({ -1, -1, 1 }), create<t_vec>({ -1, -1, -1 }),
create<t_vec>({ 0, T{1}/g, g }), create<t_vec>({ 0, T{1}/g, -g }),
create<t_vec>({ 0, -T{1}/g, g }), create<t_vec>({ 0, -T{1}/g, -g }),
create<t_vec>({ g, 0, T{1}/g }), create<t_vec>({ g, 0, -T{1}/g }),
create<t_vec>({ -g, 0, T{1}/g }), create<t_vec>({ -g, 0, -T{1}/g }),
create<t_vec>({ T{1}/g, g, 0 }), create<t_vec>({ T{1}/g, -g, 0 }),
create<t_vec>({ -T{1}/g, g, 0 }), create<t_vec>({ -T{1}/g, -g, 0 }),
};
t_cont<t_cont<std::size_t>> faces =
{
{ 0, 16, 18, 4, 8 }, { 0, 8, 10, 2, 12 }, { 0, 12, 13, 1, 16 },
{ 1, 9, 5, 18, 16 }, { 1, 13, 3, 11, 9 }, { 2, 17, 3, 13, 12 },
{ 3, 17, 19, 7, 11 }, { 2, 10, 6, 19, 17 }, { 4, 14, 6, 10, 8 },
{ 4, 18, 5, 15, 14 }, { 5, 9, 11, 7, 15 }, { 6, 14, 15, 7, 19 },
};
t_cont<t_vec> normals;
normals.reserve(faces.size());
for(const auto& face : faces)
{
auto iter = face.begin();
const t_vec& vec1 = *(vertices.begin() + *iter); std::advance(iter,1);
const t_vec& vec2 = *(vertices.begin() + *iter); std::advance(iter,1);
const t_vec& vec3 = *(vertices.begin() + *iter);
const t_vec vec12 = vec2 - vec1;
const t_vec vec13 = vec3 - vec1;
t_vec n = cross<t_vec>({vec12, vec13});
n /= norm<t_vec>(n);
normals.emplace_back(std::move(n));
}
// TODO
t_cont<t_cont<t_vec>> uvs =
{
};
return std::make_tuple(vertices, faces, normals, uvs);
}
/** /**
* create the faces of a octahedron * create the faces of a octahedron
* returns [vertices, face vertex indices, face normals, face uvs] * returns [vertices, face vertex indices, face normals, face uvs]
......
...@@ -368,7 +368,7 @@ std::size_t GlPlot_impl::AddSphere(t_real_gl rad, t_real_gl x, t_real_gl y, t_re ...@@ -368,7 +368,7 @@ std::size_t GlPlot_impl::AddSphere(t_real_gl rad, t_real_gl x, t_real_gl y, t_re
auto solid = m::create_icosahedron<t_vec3_gl>(1); auto solid = m::create_icosahedron<t_vec3_gl>(1);
auto [triagverts, norms, uvs] = m::spherify<t_vec3_gl>( auto [triagverts, norms, uvs] = m::spherify<t_vec3_gl>(
m::subdivide_triangles<t_vec3_gl>( m::subdivide_triangles<t_vec3_gl>(
m::create_triangles<t_vec3_gl>(solid), 2), rad); m::create_triangles<t_vec3_gl>(solid), 1), rad);
QMutexLocker _locker{&m_mutexObj}; QMutexLocker _locker{&m_mutexObj};
...@@ -564,7 +564,7 @@ void main() ...@@ -564,7 +564,7 @@ void main()
// 3d objects // 3d objects
AddCoordinateCross(-2.5, 2.5); AddCoordinateCross(-m_CoordMax, m_CoordMax);
// options // options
...@@ -916,7 +916,7 @@ void GlPlot_impl::paintGL() ...@@ -916,7 +916,7 @@ void GlPlot_impl::paintGL()
// coordinate labels // coordinate labels
painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0.,0.,0.,1.})), "0"); painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0.,0.,0.,1.})), "0");
for(t_real_gl f=-2.; f<=2.; f+=0.5) for(t_real_gl f=-std::floor(m_CoordMax); f<=std::floor(m_CoordMax); f+=0.5)
{ {
if(m::equals<t_real_gl>(f, 0)) if(m::equals<t_real_gl>(f, 0))
continue; continue;
...@@ -928,9 +928,9 @@ void GlPlot_impl::paintGL() ...@@ -928,9 +928,9 @@ void GlPlot_impl::paintGL()
painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0.,0.,f,1.})), ostrF.str().c_str()); painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0.,0.,f,1.})), ostrF.str().c_str());
} }
painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({3.,0.,0.,1.})), "x"); painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({m_CoordMax*t_real_gl(1.2), 0., 0., 1.})), "x");
painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0.,3.,0.,1.})), "y"); painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0., m_CoordMax*t_real_gl(1.2), 0., 1.})), "y");
painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0.,0.,3.,1.})), "z"); painter.drawText(GlToScreenCoords(m::create<t_vec_gl>({0., 0., m_CoordMax*t_real_gl(1.2), 1.})), "z");
// render object labels // render object labels
...@@ -1106,7 +1106,7 @@ GlPlot::GlPlot(QWidget *pParent) : QOpenGLWidget(pParent), ...@@ -1106,7 +1106,7 @@ GlPlot::GlPlot(QWidget *pParent) : QOpenGLWidget(pParent),
connect(this, &QOpenGLWidget::aboutToResize, this, &GlPlot::beforeResizing); connect(this, &QOpenGLWidget::aboutToResize, this, &GlPlot::beforeResizing);
connect(this, &QOpenGLWidget::resized, this, &GlPlot::afterResizing); connect(this, &QOpenGLWidget::resized, this, &GlPlot::afterResizing);
setUpdateBehavior(QOpenGLWidget::PartialUpdate); //setUpdateBehavior(QOpenGLWidget::PartialUpdate);
setMouseTracking(true); setMouseTracking(true);
if constexpr(m_isthreaded) if constexpr(m_isthreaded)
......
...@@ -148,6 +148,7 @@ protected: ...@@ -148,6 +148,7 @@ protected:
t_vec_gl m_vecCamY = m::create<t_vec_gl>({0.,1.,0.,0.}); t_vec_gl m_vecCamY = m::create<t_vec_gl>({0.,1.,0.,0.});
t_real_gl m_phi_saved = 0, m_theta_saved = 0; t_real_gl m_phi_saved = 0, m_theta_saved = 0;
t_real_gl m_zoom = 1.; t_real_gl m_zoom = 1.;
t_real_gl m_CoordMax = 2.5; // extent of coordinate axes
std::atomic<bool> m_bPlatformSupported = true; std::atomic<bool> m_bPlatformSupported = true;
std::atomic<bool> m_bInitialised = false; std::atomic<bool> m_bInitialised = false;
...@@ -219,6 +220,7 @@ public: ...@@ -219,6 +220,7 @@ public:
void SetObjectVisible(std::size_t idx, bool visible); void SetObjectVisible(std::size_t idx, bool visible);
void SetScreenDims(int w, int h); void SetScreenDims(int w, int h);
void SetCoordMax(t_real_gl d) { m_CoordMax = d; }
public /*slots*/: public /*slots*/:
void paintGL(); void paintGL();
......
...@@ -224,6 +224,7 @@ StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent}, ...@@ -224,6 +224,7 @@ StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent},
m_dlgPlot->setWindowTitle("3D View"); m_dlgPlot->setWindowTitle("3D View");
m_plot = std::make_shared<GlPlot>(this); m_plot = std::make_shared<GlPlot>(this);
m_plot->GetImpl()->SetCoordMax(1.);
m_plot->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Expanding}); m_plot->setSizePolicy(QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Expanding});
connect(m_plot.get(), &GlPlot::AfterGLInitialisation, this, &StructFactDlg::AfterGLInitialisation); connect(m_plot.get(), &GlPlot::AfterGLInitialisation, this, &StructFactDlg::AfterGLInitialisation);
...@@ -459,7 +460,7 @@ void StructFactDlg::Add3DItem(int row) ...@@ -459,7 +460,7 @@ void StructFactDlg::Add3DItem(int row)
col.getRgbF(&r, &g, &b); col.getRgbF(&r, &g, &b);
auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere, 0,0,0, r,g,b,1); auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere, 0,0,0, r,g,b,1);
//auto obj = m_plot->GetImpl()->AddSphere(0.1, 0,0,0, r,g,b,1); //auto obj = m_plot->GetImpl()->AddSphere(0.05, 0,0,0, r,g,b,1);
m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(posx, posy, posz)*m::hom_scaling<t_mat_gl>(scale,scale,scale)); m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(posx, posy, posz)*m::hom_scaling<t_mat_gl>(scale,scale,scale));
m_plot->GetImpl()->SetObjectLabel(obj, itemName->text().toStdString()); m_plot->GetImpl()->SetObjectLabel(obj, itemName->text().toStdString());
m_plot->update(); m_plot->update();
...@@ -1239,7 +1240,7 @@ void StructFactDlg::AfterGLInitialisation() ...@@ -1239,7 +1240,7 @@ void StructFactDlg::AfterGLInitialisation()
if(!m_plot) return; if(!m_plot) return;
// reference sphere for linked objects // reference sphere for linked objects
m_sphere = m_plot->GetImpl()->AddSphere(0.1, 0.,0.,0., 1.,1.,1.,1.); m_sphere = m_plot->GetImpl()->AddSphere(0.05, 0.,0.,0., 1.,1.,1.,1.);
m_plot->GetImpl()->SetObjectVisible(m_sphere, false); m_plot->GetImpl()->SetObjectVisible(m_sphere, false);
// add all 3d objects // add all 3d objects
......
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