Commit 79d7fc0c authored by Pierre Kraemer's avatar Pierre Kraemer

associate a manipulated frame to each map

parent 014790e9
......@@ -62,7 +62,8 @@ private:
virtual bool enable();
virtual void disable();
virtual void redraw(View *view);
virtual void draw(View *view) {}
virtual void drawMap(View* view, MapHandlerGen* map);
virtual void keyPress(View* view, QKeyEvent* event) {}
virtual void keyRelease(View* view, QKeyEvent* event) {}
......
......@@ -59,51 +59,46 @@ void SurfaceRenderPlugin::disable()
mapRemoved(map);
}
void SurfaceRenderPlugin::redraw(View* view)
void SurfaceRenderPlugin::drawMap(View* view, MapHandlerGen* map)
{
const QHash<MapHandlerGen*, MapParameters>& viewParamSet = h_viewParameterSet[view];
foreach(MapHandlerGen* m, view->getLinkedMaps())
const MapParameters& p = h_viewParameterSet[view][map];
if(p.positionVBO)
{
const MapParameters& p = viewParamSet[m];
if(p.positionVBO)
if(p.renderVertices)
{
if(p.renderVertices)
{
m_pointSprite->setSize(m->getBBdiagSize() / 200.0f * p.verticesScaleFactor);
m_pointSprite->setAttributePosition(p.positionVBO);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f));
m->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS);
}
if(p.renderEdges)
{
glLineWidth(1.0f);
m_simpleColorShader->setAttributePosition(p.positionVBO);
m->draw(m_simpleColorShader, CGoGN::Algo::Render::GL2::LINES);
}
if(p.renderFaces)
m_pointSprite->setSize(map->getBBdiagSize() / 200.0f * p.verticesScaleFactor);
m_pointSprite->setAttributePosition(p.positionVBO);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f));
map->draw(m_pointSprite, CGoGN::Algo::Render::GL2::POINTS);
}
if(p.renderEdges)
{
glLineWidth(1.0f);
m_simpleColorShader->setAttributePosition(p.positionVBO);
map->draw(m_simpleColorShader, CGoGN::Algo::Render::GL2::LINES);
}
if(p.renderFaces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
switch(p.faceStyle)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
switch(p.faceStyle)
{
case MapParameters::FLAT :
m_flatShader->setAttributePosition(p.positionVBO);
m->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES);
break ;
case MapParameters::PHONG :
if(p.normalVBO != NULL)
{
m_phongShader->setAttributePosition(p.positionVBO) ;
m_phongShader->setAttributeNormal(p.normalVBO) ;
m->draw(m_phongShader, CGoGN::Algo::Render::GL2::TRIANGLES);
}
break ;
}
glDisable(GL_POLYGON_OFFSET_FILL);
case MapParameters::FLAT :
m_flatShader->setAttributePosition(p.positionVBO);
map->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES);
break ;
case MapParameters::PHONG :
if(p.normalVBO != NULL)
{
m_phongShader->setAttributePosition(p.positionVBO) ;
m_phongShader->setAttributeNormal(p.normalVBO) ;
map->draw(m_phongShader, CGoGN::Algo::Render::GL2::TRIANGLES);
}
break ;
}
glDisable(GL_POLYGON_OFFSET_FILL);
}
}
}
......
......@@ -11,11 +11,13 @@
#include "Topology/generic/attribmap.h"
#include "Topology/generic/functor.h"
#include "Topology/generic/attributeHandler.h"
#include "Utils/vbo.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/drawer.h"
#include "Algo/Geometry/boundingbox.h"
#include "Utils/vbo.h"
#include "Utils/drawer.h"
namespace CGoGN
{
......@@ -45,6 +47,7 @@ public slots:
const qglviewer::Vec& getBBmin() const { return m_bbMin; }
const qglviewer::Vec& getBBmax() const { return m_bbMax; }
float getBBdiagSize() const { return m_bbDiagSize; }
Utils::GLSLShader* getBBDrawerShader() const
{
if(m_bbDrawer)
......@@ -53,6 +56,20 @@ public slots:
return NULL;
}
qglviewer::ManipulatedFrame* getFrame() const { return m_frame; }
glm::mat4 getFrameMatrix() const
{
GLdouble m[16];
m_frame->getMatrix(m);
glm::mat4 matrix;
for(unsigned int i = 0; i < 4; ++i)
{
for(unsigned int j = 0; j < 4; ++j)
matrix[i][j] = (float)m[i*4+j];
}
return matrix;
}
const QList<View*>& getLinkedViews() const { return l_views; }
bool isLinkedToView(View* view) const { return l_views.contains(view); }
......@@ -149,9 +166,11 @@ protected:
qglviewer::Vec m_bbMin;
qglviewer::Vec m_bbMax;
float m_bbDiagSize;
Utils::Drawer* m_bbDrawer;
qglviewer::ManipulatedFrame* m_frame;
Algo::Render::GL2::MapRender* m_render;
Utils::Drawer* m_bbDrawer;
QList<View*> l_views;
......
......@@ -57,7 +57,10 @@ void MapHandler<PFP>::draw(Utils::GLSLShader* shader, int primitive)
if(!m_render->isPrimitiveUpToDate(primitive))
m_render->initPrimitives<PFP>(*(static_cast<typename PFP::MAP*>(m_map)), primitive) ;
glPushMatrix();
glMultMatrixd(m_frame->matrix());
m_render->draw(shader, primitive);
glPopMatrix();
}
template <typename PFP>
......@@ -68,7 +71,12 @@ void MapHandler<PFP>::drawBB()
m_bbDrawer = new Utils::Drawer();
updateBBDrawer();
}
glPushMatrix();
glMultMatrixd(m_frame->matrix());
QGLViewer::drawAxis();
m_bbDrawer->callList();
glPopMatrix();
}
template <typename PFP>
......
......@@ -29,7 +29,8 @@ public slots:
const QList<Utils::GLSLShader*> getShaders() const { return l_shaders; }
private:
virtual void redraw(View* view) = 0;
virtual void draw(View* view) = 0;
virtual void drawMap(View* view, MapHandlerGen* map) = 0;
virtual void keyPress(View* view, QKeyEvent* event) = 0;
virtual void keyRelease(View* view, QKeyEvent* event) = 0;
......
......@@ -86,6 +86,8 @@ private:
void updateCurrentCameraBB();
private slots:
void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
void ui_verticalSplitView(int x, int y, int globalX, int globalY);
void ui_horizontalSplitView(int x, int y, int globalX, int globalY);
void ui_closeView(int x, int y, int globalX, int globalY);
......
......@@ -10,9 +10,12 @@ MapHandlerGen::MapHandlerGen(const QString& name, SCHNApps* s, GenericMap* map)
m_name(name),
m_schnapps(s),
m_map(map),
m_frame(NULL),
m_render(NULL),
m_bbDrawer(NULL)
{}
{
m_frame = new qglviewer::ManipulatedFrame();
}
MapHandlerGen::~MapHandlerGen()
{
......
......@@ -34,7 +34,7 @@ View::View(const QString& name, SCHNApps* s, const QGLWidget* shareWidget) :
m_currentCamera = m_schnapps->addCamera();
connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)), this, SLOT(updateGL()));
connect(m_schnapps, SIGNAL(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)), this, SLOT(selectedMapChanged(MapHandlerGen*,MapHandlerGen*)));
}
View::~View()
......@@ -196,23 +196,6 @@ void View::preDraw()
{
m_currentCamera->setScreenWidthAndHeight(width(), height());
glm::mat4 mm = getCurrentModelViewMatrix();
glm::mat4 pm = getCurrentProjectionMatrix();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
{
Utils::GLSLShader* bbShader = map->getBBDrawerShader();
if(bbShader)
bbShader->updateMatrices(pm, mm);
}
foreach(PluginInteraction* plugin, l_plugins)
{
foreach(Utils::GLSLShader* shader, plugin->getShaders())
shader->updateMatrices(pm, mm);
}
QGLViewer::preDraw();
}
......@@ -227,12 +210,33 @@ void View::draw()
}
}
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map && isLinkedToMap(map))
map->drawBB();
glm::mat4 mm = getCurrentModelViewMatrix();
glm::mat4 pm = getCurrentProjectionMatrix();
MapHandlerGen* selectedMap = m_schnapps->getSelectedMap();
foreach(MapHandlerGen* map, l_maps)
{
glm::mat4 map_mm = mm * map->getFrameMatrix();
if(map == selectedMap)
{
Utils::GLSLShader* bbShader = map->getBBDrawerShader();
if(bbShader)
bbShader->updateMatrices(pm, map_mm);
map->drawBB();
}
foreach(PluginInteraction* plugin, l_plugins)
{
foreach(Utils::GLSLShader* shader, plugin->getShaders())
shader->updateMatrices(pm, map_mm);
plugin->drawMap(this, map);
}
}
foreach(PluginInteraction* plugin, l_plugins)
plugin->redraw(this);
plugin->draw(this);
}
void View::postDraw()
......@@ -424,6 +428,13 @@ void View::updateCurrentCameraBB()
camera()->showEntireScene();
}
void View::selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur)
{
if(cur && isLinkedToMap(cur))
setManipulatedFrame(cur->getFrame());
updateGL();
}
void View::ui_verticalSplitView(int x, int y, int globalX, int globalY)
{
m_schnapps->splitView(m_name, Qt::Horizontal);
......
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