Commit 8b23ebca authored by Maire Nicolas's avatar Maire Nicolas

Premiers essais d'utilisation de la souris pour déplacer le plan de clipping....

Premiers essais d'utilisation de la souris pour déplacer le plan de clipping. Il reste beaucoup de boulot tout de même.
parent 51ad10fa
......@@ -81,7 +81,7 @@ void StageShader::slot_doubleSpinBox_Plane(double c)
float bPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_bPlane->value();
float cPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_cPlane->value();
float dPlane = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_dPlane->value();
m_shader->setPlaneClippingParams(Geom::Vec4f(aPlane, bPlane, cPlane, dPlane));
m_shader->setClippingPlaneEquation(Geom::Vec4f(aPlane, bPlane, cPlane, dPlane));
updateGL();
}
......
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <iostream>
#include "Utils/qtSimple.h"
#include "ui_stage_shader_number_two.h"
#include "Utils/qtui.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Algo/Import/import.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2<Map2> MAP ;
};
typedef PFP::MAP MAP ;
class Stage_shader_number_two : public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MAP myMap ;
SelectorTrue allDarts ;
Utils::QT::uiDockInterface dock ;
enum renderMode { FLAT, PHONG } ;
Geom::Vec4f colDif ;
Geom::Vec4f colSpec ;
Geom::Vec4f colClear ;
Geom::Vec4f colNormal ;
float shininess ;
Geom::BoundingBox<PFP::VEC3> bb ;
float normalBaseSize ;
float normalScaleFactor ;
float vertexBaseSize ;
float vertexScaleFactor ;
float faceShrinkage ;
int m_renderStyle ;
bool m_drawVertices ;
bool m_drawEdges ;
bool m_drawFaces ;
bool m_drawNormals ;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
Algo::Render::GL2::MapRender* m_render ;
Utils::VBO* m_positionVBO ;
Utils::VBO* m_normalVBO ;
Utils::ShaderPhong* m_phongShader ;
Utils::ShaderFlat* m_flatShader ;
Utils::ShaderVectorPerVertex* m_vectorShader ;
Utils::ShaderSimpleColor* m_simpleColorShader ;
Utils::PointSprite* m_pointSprite ;
Stage_shader_number_two() ;
void initGUI() ;
void cb_initGL() ;
void cb_redraw() ;
void cb_Open() ;
void cb_keyPress(int code);
void cb_mousePress(int button, int x, int y);
void cb_mouseMove(int button, int x, int y);
void importMesh(std::string& filename) ;
int m_mouseLastX, m_mouseLastY;
public slots:
void slot_drawVertices(bool b) ;
void slot_verticesSize(int i) ;
void slot_drawEdges(bool b) ;
void slot_drawFaces(bool b) ;
void slot_faceLighting(int i) ;
void slot_drawNormals(bool b) ;
void slot_normalsSize(int i) ;
void slot_doubleSpinBox_Plane(double c);
void slot_doubleSpinBox_ColorAttenuationFactor(double c);
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockWidget</class>
<widget class="QDockWidget" name="DockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>174</width>
<height>393</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>174</width>
<height>393</height>
</size>
</property>
<property name="windowTitle">
<string>Commands</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Visu</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="check_drawVertices">
<property name="text">
<string>draw vertices</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_verticesSize">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawEdges">
<property name="text">
<string>draw edges</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawFaces">
<property name="text">
<string>draw faces</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_faceLighting">
<item>
<property name="text">
<string>FLAT</string>
</property>
</item>
<item>
<property name="text">
<string>PHONG</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawNormals">
<property name="text">
<string>draw normals</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_normalsSize">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Clipping</string>
</attribute>
<widget class="QLabel" name="label_Plane">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>69</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Plane :</string>
</property>
</widget>
<widget class="QLabel" name="label_plane_a">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>21</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>a :</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_plane_a">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>63</width>
<height>28</height>
</rect>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="minimum">
<double>-99.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_plane_b">
<property name="geometry">
<rect>
<x>80</x>
<y>50</y>
<width>63</width>
<height>28</height>
</rect>
</property>
<property name="minimum">
<double>-99.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_plane_b">
<property name="geometry">
<rect>
<x>90</x>
<y>30</y>
<width>21</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>b :</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_plane_c">
<property name="geometry">
<rect>
<x>10</x>
<y>110</y>
<width>63</width>
<height>28</height>
</rect>
</property>
<property name="minimum">
<double>-99.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_plane_c">
<property name="geometry">
<rect>
<x>20</x>
<y>90</y>
<width>21</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>c :</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_plane_d">
<property name="geometry">
<rect>
<x>80</x>
<y>110</y>
<width>63</width>
<height>28</height>
</rect>
</property>
<property name="minimum">
<double>-99.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_plane_d">
<property name="geometry">
<rect>
<x>90</x>
<y>90</y>
<width>21</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>d :</string>
</property>
</widget>
<widget class="QLabel" name="label_color_attenuation">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>141</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Color attenuation :</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_color_attenuation">
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<width>63</width>
<height>28</height>
</rect>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>check_drawFaces</sender>
<signal>toggled(bool)</signal>
<receiver>combo_faceLighting</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>65</x>
<y>98</y>
</hint>
<hint type="destinationlabel">
<x>65</x>
<y>127</y>
</hint>
</hints>
</connection>
<connection>
<sender>check_drawNormals</sender>
<signal>toggled(bool)</signal>
<receiver>slider_normalsSize</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>75</x>
<y>191</y>
</hint>
<hint type="destinationlabel">
<x>75</x>
<y>222</y>
</hint>
</hints>
</connection>
<connection>
<sender>check_drawVertices</sender>
<signal>toggled(bool)</signal>
<receiver>slider_verticesSize</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>75</x>
<y>44</y>
</hint>
<hint type="destinationlabel">
<x>75</x>
<y>75</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -27,8 +27,12 @@
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include "glm/glm.hpp"
#include "Geometry/matrix.h"
#include "Utils/trackball.h"
#include "Utils/cgognStream.h"
#include "Utils/shaderMutator.h"
#include "Utils/drawer.h"
#include <string>
namespace CGoGN
......@@ -46,18 +50,44 @@ public:
*/
ClippingShader();
/**
* destructor
*/
~ClippingShader();
/**
* set the plane equation for plane clipping
* @param newClipPlane plane equation
* @param clipPlane plane equation
*/
void setPlaneClippingParams(Geom::Vec4f clipPlane);
void setClippingPlaneEquation(Geom::Vec4f clipPlane);
/**
* get the plane equation for plane clipping
*/
Geom::Vec4f getClippingPlaneEquation();
/**
* set the plane quaternion for plane clipping
* @param quat plane quaternion
*/
void setClippingPlaneQuaternion(float quat[4]);
/**
* get the plane quaternion for plane clipping
*/
Geom::Vec4f getClippingPlaneQuaternion();
/**
* set the color attenuation factor for clipping
* @param newColorAttenuationFactor color attenuation factor
* @param colorAttenuationFactor color attenuation factor
*/
void setClippingColorAttenuationFactor(float colorAttenuationFactor);
/**
* get the color attenuation factor for clipping
*/
float getClippingColorAttenuationFactor();
/**
* insert plane clipping instructions into vertex and fragment shader source code
* - does not modify the geometry shader source code
......@@ -66,18 +96,28 @@ public:
void addPlaneClippingToShaderSource();
/**
* update uniforms (get their locations and resent their values) for clipping
* update uniforms (get their locations and resend their values) for clipping
*/
void updateClippingUniforms();
/**
* displays a quad corresponding to the current clipping plane position and orientation
*/
void displayClippingPlane();
private:
/**
* clip plane vector (a, b, c, d)
*/
Geom::Vec4f m_clipPlane;
Geom::Vec4f m_clipPlaneEquation;
/**
* clip plane quaternion
*/
float m_clipPlaneQuaternion[4];
/**
* clip plane vector uniform id
*/
......@@ -93,6 +133,11 @@ private:
*/
GLint m_unif_colorAttenuationFactor;
/**
* plane drawer
*/
Drawer* m_planeDrawer;
};
......
......@@ -33,19 +33,74 @@ namespace Utils
ClippingShader::ClippingShader()
{
// Default values for plane clipping
m_clipPlane = Geom::Vec4f(0.5, 0.5, 0.5, 0.0);
m_clipPlaneEquation = Geom::Vec4f(0.0, 0.0, 1.0, 0.0);
m_unif_clipPlane = 0;
m_clipPlaneQuaternion[0] = 1.0;
m_clipPlaneQuaternion[1] = 0.0;
m_clipPlaneQuaternion[2] = 0.0;
m_clipPlaneQuaternion[3] = 0.0;
// Default values for color attenuation
m_colorAttenuationFactor = 0.0;
m_unif_colorAttenuationFactor = 0;
// Plane Drawer
float planeSize = 100.0;
m_planeDrawer = new Drawer();
m_planeDrawer->newList(GL_COMPILE);
m_planeDrawer->begin(GL_QUADS);
m_planeDrawer->color3f(0.7, 0.7, 0.2);
m_planeDrawer->vertex3f(-planeSize/2.0, -planeSize/2.0, 0.0);
m_planeDrawer->vertex3f(-planeSize/2.0, planeSize/2.0, 0.0);
m_planeDrawer->vertex3f(planeSize/2.0, planeSize/2.0, 0.0);
m_planeDrawer->vertex3f(planeSize/2.0, -planeSize/2.0, 0.0);
m_planeDrawer->end();
m_planeDrawer->endList();
}
ClippingShader::~ClippingShader()
{
delete m_planeDrawer;
}
void ClippingShader::setPlaneClippingParams(Geom::Vec4f clipPlane)
void ClippingShader::setClippingPlaneEquation(Geom::Vec4f clipPlane)
{
m_clipPlane = clipPlane;
m_clipPlaneEquation = clipPlane;
// Recalculate quaternion rotation
float m[4][4];
build_rotmatrix(m, m_clipPlaneQuaternion);
Geom::Matrix44f rotMat;
int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
rotMat(i, j) = m[i][j];
Geom::Vec4f rotatedVec = rotMat * m_clipPlaneEquation;
// Send the resulting plane equation to shader
bind();
glUniform4fv(m_unif_clipPlane, 1, m_clipPlane.data());
glUniform4fv(m_unif_clipPlane, 1, rotatedVec.data());
}
Geom::Vec4f ClippingShader::getClippingPlaneEquation()
{
return m_clipPlaneEquation;
}
void ClippingShader::setClippingPlaneQuaternion(float quat[4])
{
m_clipPlaneQuaternion[0] = quat[0];
m_clipPlaneQuaternion[1] = quat[1];
m_clipPlaneQuaternion[2] = quat[2];
m_clipPlaneQuaternion[3] = quat[3];
// Recalculate and resend the clipping plane equation
setClippingPlaneEquation(m_clipPlaneEquation);
}
Geom::Vec4f ClippingShader::getClippingPlaneQuaternion()
{
return Geom::Vec4f (m_clipPlaneQuaternion[0], m_clipPlaneQuaternion[1], m_clipPlaneQuaternion[2], m_clipPlaneQuaternion[3]);
}
void ClippingShader::setClippingColorAttenuationFactor(float colorAttenuationFactor)
......@@ -55,6 +110,11 @@ void ClippingShader::setClippingColorAttenuationFactor(float colorAttenuationFac
glUniform1f(m_unif_colorAttenuationFactor, m_colorAttenuationFactor);
}
float ClippingShader::getClippingColorAttenuationFactor()
{
return m_colorAttenuationFactor;
}
void ClippingShader::addPlaneClippingToShaderSource()
{
// Shader name
......@@ -191,10 +251,16 @@ void ClippingShader::updateClippingUniforms()
}
// Set uniforms values
setPlaneClippingParams(m_clipPlane);
setClippingPlaneEquation(m_clipPlaneEquation);
setClippingPlaneQuaternion(m_clipPlaneQuaternion);
setClippingColorAttenuationFactor(m_colorAttenuationFactor);
}
void ClippingShader::displayClippingPlane()
{
m_planeDrawer->callList();
}
} // namespace Utils
} // namespace CGoGN
......
......@@ -289,7 +289,8 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event)
}
if (m_cbs)
m_cbs->cb_mouseMove(event->button(), event->x(), getHeight() - event->y());
//m_cbs->cb_mouseMove(event->button(), event->x(), getHeight() - event->y());
m_cbs->cb_mouseMove(m_current_button, event->x(), getHeight() - event->y()); // TODO ???
}
void GLWidget::wheelEvent(QWheelEvent* event)
......
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