Commit 2c03ba24 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Merge cgogn.u-strasbg.fr:~aubry/CGoGN

parents 216ad474 3e8be8d2
...@@ -174,9 +174,6 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -174,9 +174,6 @@ void MyQT::cb_mousePress(int button, int x, int y)
m_pickedAxis=fr_picked; m_pickedAxis=fr_picked;
} }
// project center & axis on screen for easy manipulation
if (m_pickedAxis != Utils::FrameManipulator::NONE)
m_frame->storeProjection(m_pickedAxis);
// highlighting // highlighting
m_frame->highlight(m_pickedAxis); m_frame->highlight(m_pickedAxis);
...@@ -192,33 +189,60 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -192,33 +189,60 @@ void MyQT::cb_mousePress(int button, int x, int y)
} }
} }
// store origin & selected axis on on screen projection for easy manipulation.
m_frame->storeProjection(m_pickedAxis);
updateGL(); updateGL();
} }
void MyQT::cb_mouseMove(int button, int x, int y) void MyQT::cb_mouseMove(int buttons, int x, int y)
{ {
if (!Shift()) if (!Shift())
return; return;
// rotation selected ?
if (Utils::FrameManipulator::rotationAxis(m_pickedAxis)) if (Utils::FrameManipulator::rotationAxis(m_pickedAxis))
{ {
float angle = m_frame->angleFromMouse(x,y,x-m_begX, y-m_begY); if (buttons&1)
m_frame->rotate(m_pickedAxis, angle); {
float angle = m_frame->angleFromMouse(x,y,x-m_begX, y-m_begY);
m_frame->rotate(m_pickedAxis, angle);
}
else if (buttons&2)
m_frame->rotateInScreen(x-m_begX, y-m_begY);
m_lastPickedObject->transfo() = m_frame->transfo(); m_lastPickedObject->transfo() = m_frame->transfo();
} }
// translation selected
else if (Utils::FrameManipulator::translationAxis(m_pickedAxis)) else if (Utils::FrameManipulator::translationAxis(m_pickedAxis))
{ {
float dist = m_frame->distanceFromMouse(x-m_begX, y-m_begY); if (buttons&1)
m_frame->translate(m_pickedAxis, dist); {
float dist = m_frame->distanceFromMouse(x-m_begX, y-m_begY);
m_frame->translate(m_pickedAxis, dist);
}
else if (buttons&2)
m_frame->translateInScreen(x-m_begX, y-m_begY);
m_lastPickedObject->transfo() = m_frame->transfo(); m_lastPickedObject->transfo() = m_frame->transfo();
} }
// scale selected
else if (Utils::FrameManipulator::scaleAxis(m_pickedAxis) ) else if (Utils::FrameManipulator::scaleAxis(m_pickedAxis) )
{ {
float scale = m_frame->scaleFromMouse(x-m_begX, y-m_begY); float scale = m_frame->scaleFromMouse(x-m_begX, y-m_begY);
m_frame->scale(m_pickedAxis, scale ); m_frame->scale(m_pickedAxis, scale );
m_lastPickedObject->transfo() = m_frame->transfo(); m_lastPickedObject->transfo() = m_frame->transfo();
} }
// // nothing selected: using screen translation/rotation (button left/right)
// else if (m_lastPickedObject)
// {
// if (buttons&1)
// m_frame->translateInScreen(x-m_begX, y-m_begY);
// else if (buttons&2)
// m_frame->rotateInScreen(x-m_begX, y-m_begY);
// m_lastPickedObject->transfo() = m_frame->transfo();
// }
m_begX = x; m_begX = x;
m_begY = y; m_begY = y;
...@@ -274,42 +298,61 @@ void MyQT::cb_keyPress(int code) ...@@ -274,42 +298,61 @@ void MyQT::cb_keyPress(int code)
m_frame->setTransformation(m_lastPickedObject->transfo()); m_frame->setTransformation(m_lastPickedObject->transfo());
break; break;
case 'x': case 'x':
m_frame->lock(Utils::FrameManipulator::Xt); if (m_frame->locked(Utils::FrameManipulator::Xt))
m_frame->unlock(Utils::FrameManipulator::Xt);
else
m_frame->lock(Utils::FrameManipulator::Xt);
break; break;
case 'y': case 'y':
m_frame->lock(Utils::FrameManipulator::Yt); if (m_frame->locked(Utils::FrameManipulator::Yt))
m_frame->unlock(Utils::FrameManipulator::Yt);
else
m_frame->lock(Utils::FrameManipulator::Yt);
break; break;
case 'z': case 'z':
m_frame->lock(Utils::FrameManipulator::Zt); if (m_frame->locked(Utils::FrameManipulator::Zt))
break; m_frame->unlock(Utils::FrameManipulator::Zt);
case 'X': else
m_frame->unlock(Utils::FrameManipulator::Xt); m_frame->lock(Utils::FrameManipulator::Zt);
break;
case 'Y':
m_frame->unlock(Utils::FrameManipulator::Yt);
break;
case 'Z':
m_frame->unlock(Utils::FrameManipulator::Zt);
break; break;
case 'a': case 'a':
m_frame->lock(Utils::FrameManipulator::Xr); if (m_frame->locked(Utils::FrameManipulator::Xr))
m_frame->unlock(Utils::FrameManipulator::Xr);
else
m_frame->lock(Utils::FrameManipulator::Xr);
break; break;
case 'b': case 'b':
m_frame->lock(Utils::FrameManipulator::Yr); if (m_frame->locked(Utils::FrameManipulator::Yr))
m_frame->unlock(Utils::FrameManipulator::Yr);
else
m_frame->lock(Utils::FrameManipulator::Yr);
break; break;
case 'c': case 'c':
m_frame->lock(Utils::FrameManipulator::Zr); if (m_frame->locked(Utils::FrameManipulator::Zr))
m_frame->unlock(Utils::FrameManipulator::Zr);
else
m_frame->lock(Utils::FrameManipulator::Zr);
break; break;
case 'A':
m_frame->unlock(Utils::FrameManipulator::Xr); case 's':
if (m_frame->locked(Utils::FrameManipulator::Xs))
m_frame->unlock(Utils::FrameManipulator::Xs);
else
m_frame->lock(Utils::FrameManipulator::Xs);
break; break;
case 'B': case 't':
m_frame->unlock(Utils::FrameManipulator::Yr); if (m_frame->locked(Utils::FrameManipulator::Ys))
m_frame->unlock(Utils::FrameManipulator::Ys);
else
m_frame->lock(Utils::FrameManipulator::Ys);
break; break;
case 'C': case 'u':
m_frame->unlock(Utils::FrameManipulator::Zr); if (m_frame->locked(Utils::FrameManipulator::Zs))
m_frame->unlock(Utils::FrameManipulator::Zs);
else
m_frame->lock(Utils::FrameManipulator::Zs);
break; break;
} }
updateGL(); updateGL();
} }
...@@ -326,6 +369,11 @@ int main(int argc, char **argv) ...@@ -326,6 +369,11 @@ int main(int argc, char **argv)
if (argc>1) if (argc>1)
sqt.NBP = atoi(argv[1]); sqt.NBP = atoi(argv[1]);
sqt.setHelpMsg("Param :size of grid (number of objects)\nMpuse:\n"
" -click on object: selection\n -left click on frame: constraint 3d Rotation/Translation/Scale\n"
" -right click on frame :free 2D Rotation/Translation\nKeys:\n x/y/z lock/unlock translation\n a/b/c lock/unlock rotation\n s/t/u lock/unlock scaling");
// bounding box // bounding box
Geom::Vec3f lPosObj = Geom::Vec3f(0.0f,0.0f,0.0f); Geom::Vec3f lPosObj = Geom::Vec3f(0.0f,0.0f,0.0f);
float lWidthObj = sqt.NBP*4.0f; float lWidthObj = sqt.NBP*4.0f;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <vector> #include <vector>
#include <list> #include <list>
#include <utility>
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
#include "Topology/generic/functor.h" #include "Topology/generic/functor.h"
...@@ -67,7 +68,8 @@ enum bufferIndex ...@@ -67,7 +68,8 @@ enum bufferIndex
POINT_INDICES = 0, POINT_INDICES = 0,
LINE_INDICES = 1, LINE_INDICES = 1,
TRIANGLE_INDICES = 2, TRIANGLE_INDICES = 2,
FLAT_BUFFER = 3 FLAT_BUFFER = 3,
SIZE_BUFFER
} ; } ;
...@@ -78,12 +80,14 @@ protected: ...@@ -78,12 +80,14 @@ protected:
/** /**
* vbo buffers * vbo buffers
*/ */
GLuint m_indexBuffers[4] ; GLuint m_indexBuffers[SIZE_BUFFER] ;
/** /**
* nb indices * nb indices
*/ */
GLuint m_nbIndices[4] ; GLuint m_nbIndices[SIZE_BUFFER] ;
typedef std::pair<GLuint*, unsigned int> buffer_array;
public: public:
/** /**
...@@ -101,6 +105,9 @@ public: ...@@ -101,6 +105,9 @@ public:
*/ */
~MapRender() ; ~MapRender() ;
buffer_array get_index_buffer() { return std::make_pair(m_indexBuffers, SIZE_BUFFER); }
buffer_array get_nb_index_buffer() { return std::make_pair(m_nbIndices, SIZE_BUFFER); }
protected: protected:
/** /**
* addition of indices table of one triangle * addition of indices table of one triangle
......
...@@ -428,6 +428,11 @@ public: ...@@ -428,6 +428,11 @@ public:
*/ */
void unlock(unsigned int axis); void unlock(unsigned int axis);
/**
* is an axis locked
*/
bool locked(unsigned int axis);
/** /**
* higlight an axis (change width rendering). * higlight an axis (change width rendering).
* To unhighlight, just highlight NONE or highlight a already highlighted axis * To unhighlight, just highlight NONE or highlight a already highlighted axis
...@@ -508,6 +513,12 @@ public: ...@@ -508,6 +513,12 @@ public:
static bool translationAxis(unsigned int axis) { return (axis>=Xt) && (axis<=Zt);} static bool translationAxis(unsigned int axis) { return (axis>=Xt) && (axis<=Zt);}
static bool scaleAxis(unsigned int axis) { return ((axis>=Xs) && (axis<=Zs))|| (axis==CENTER);} static bool scaleAxis(unsigned int axis) { return ((axis>=Xs) && (axis<=Zs))|| (axis==CENTER);}
/**
* translate from screen mouse move
*/
void translateInScreen(int dx, int dy);
void rotateInScreen(int dx, int dy);
}; };
......
...@@ -618,17 +618,21 @@ void FrameManipulator::setTransformation( const glm::mat4& transfo) ...@@ -618,17 +618,21 @@ void FrameManipulator::setTransformation( const glm::mat4& transfo)
m_rotations[2][2] = Rz[2]; m_rotations[2][2] = Rz[2];
} }
void FrameManipulator::lock(unsigned int axis) void FrameManipulator::lock(unsigned int axis)
{ {
m_locked_axis[axis] = true; m_locked_axis[axis] = true;
} }
void FrameManipulator::unlock(unsigned int axis) void FrameManipulator::unlock(unsigned int axis)
{ {
m_locked_axis[axis] = false; m_locked_axis[axis] = false;
} }
bool FrameManipulator::locked(unsigned int axis)
{
return m_locked_axis[axis];
}
Geom::Vec3f FrameManipulator::getAxis(unsigned int ax) Geom::Vec3f FrameManipulator::getAxis(unsigned int ax)
{ {
...@@ -641,19 +645,20 @@ Geom::Vec3f FrameManipulator::getAxis(unsigned int ax) ...@@ -641,19 +645,20 @@ Geom::Vec3f FrameManipulator::getAxis(unsigned int ax)
void FrameManipulator::storeProjection(unsigned int ax) void FrameManipulator::storeProjection(unsigned int ax)
{ {
Geom::Vec3f O = getPosition(); Geom::Vec3f O = getPosition();
Geom::Vec3f A = getAxis(ax);
A += O;
glm::i32vec4 viewport; glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0])); glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
glm::vec3 winO = glm::project(glm::vec3(O[0],O[1],O[2]), GLSLShader::currentModelView(), GLSLShader::currentProjection(), viewport); glm::vec3 winO = glm::project(glm::vec3(O[0],O[1],O[2]), GLSLShader::currentModelView(), GLSLShader::currentProjection(), viewport);
glm::vec3 winA = glm::project(glm::vec3(A[0],A[1],A[2]), GLSLShader::currentModelView(), GLSLShader::currentProjection(), viewport); m_projectedOrigin = Geom::Vec3f(winO[0], winO[1], winO[2]);
if (ax>CENTER)
{
Geom::Vec3f A = getAxis(ax);
A += O;
glm::vec3 winA = glm::project(glm::vec3(A[0],A[1],A[2]), GLSLShader::currentModelView(), GLSLShader::currentProjection(), viewport);
m_projectedSelectedAxis = Geom::Vec3f(winA[0]-winO[0], winA[1]-winO[1],winA[2]-winO[2]);
}
m_projectedOrigin = Geom::Vec3f(winO[0],winO[1],0.0f);
if (winA[2]-winO[2] < 0.0f)
m_projectedSelectedAxis = Geom::Vec3f(winA[0]-winO[0], winA[1]-winO[1],-1.0f);
else
m_projectedSelectedAxis = Geom::Vec3f(winA[0]-winO[0], winA[1]-winO[1],1.0f);
} }
...@@ -693,5 +698,40 @@ float FrameManipulator::scaleFromMouse(int dx, int dy) ...@@ -693,5 +698,40 @@ float FrameManipulator::scaleFromMouse(int dx, int dy)
return 1.0f + sc; return 1.0f + sc;
} }
void FrameManipulator::translateInScreen(int dx, int dy)
{
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
Geom::Vec3f NO = m_projectedOrigin+Geom::Vec3f(float(dx), float(dy), 0.0f);
glm::vec3 P = glm::unProject(glm::vec3(NO[0],NO[1],NO[2]), GLSLShader::currentModelView(), GLSLShader::currentProjection(), viewport);
m_trans[0] = P[0];
m_trans[1] = P[1];
m_trans[2] = P[2];
storeProjection(NONE);
}
void FrameManipulator::rotateInScreen(int dx, int dy)
{
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
Geom::Vec3f NO = m_projectedOrigin+Geom::Vec3f(float(-dy), float(dx), 0.0f);
glm::vec3 P = glm::unProject(glm::vec3(NO[0],NO[1],NO[2]), GLSLShader::currentModelView(), GLSLShader::currentProjection(), viewport);
Geom::Vec3f axisRotation(P[0]-m_trans[0], P[1]-m_trans[1], P[2]-m_trans[2]);
axisRotation.normalize();
glm::mat4 tr = glm::rotate(glm::mat4(1.0f),float(sqrtf(dx*dx+dy*dy))/2.0f,glm::vec3(axisRotation[0],axisRotation[1],axisRotation[2]));
m_rotations = tr*m_rotations;
}
} }
} }
...@@ -331,15 +331,11 @@ void Sphere::changeTopo(unsigned int parp, unsigned int mer) ...@@ -331,15 +331,11 @@ void Sphere::changeTopo(unsigned int parp, unsigned int mer)
parfactor = 2; parfactor = 2;
unsigned int merAll = merfactor * mer; unsigned int merAll = merfactor * mer;
unsigned int parAll = parfactor* par; unsigned int parAll = parfactor* (par+1);
parAll += 1;
std::vector<Geom::Vec3f> points; std::vector<Geom::Vec3f> points;
points.reserve(parAll*merAll+2); points.reserve(parAll*merAll+2);
for (unsigned int i=0; i<parAll; ++i) for (unsigned int i=0; i<parAll; ++i)
{ {
float beta = float(i+1)*M_PI/float(parAll+1); float beta = float(i+1)*M_PI/float(parAll+1);
...@@ -372,7 +368,7 @@ void Sphere::changeTopo(unsigned int parp, unsigned int mer) ...@@ -372,7 +368,7 @@ void Sphere::changeTopo(unsigned int parp, unsigned int mer)
for (unsigned int i=0; i<par; ++i) for (unsigned int i=0; i<par; ++i)
{ {
unsigned int k = i*parfactor*merAll + parfactor/2*merAll; unsigned int k = i*parfactor*merAll + parfactor*merAll;
for (unsigned int j=0; j<merAll; ++j) for (unsigned int j=0; j<merAll; ++j)
{ {
tableIndices.push_back(k+j); tableIndices.push_back(k+j);
...@@ -869,7 +865,7 @@ void IcoSphere::subdivide(std::vector<unsigned int>& triangles, std::vector<Geom ...@@ -869,7 +865,7 @@ void IcoSphere::subdivide(std::vector<unsigned int>& triangles, std::vector<Geom
void IcoSphere::changeTopo(unsigned int sub) void IcoSphere::changeTopo(unsigned int sub)
{ {
unsigned int subd = (unsigned int)(log(sub/2)/log(2.0))-1; int subd = int(log(sub/2)/log(2.0))-1;
if (subd<0) if (subd<0)
subd=0; subd=0;
......
...@@ -294,7 +294,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event) ...@@ -294,7 +294,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event)
} }
if (m_cbs) if (m_cbs)
m_cbs->cb_mouseMove(event->button(), event->x(), getHeight() - event->y()); m_cbs->cb_mouseMove(event->buttons(), event->x(), getHeight() - event->y());
} }
void GLWidget::wheelEvent(QWheelEvent* event) 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