Commit 1dad7e0b authored by Sylvain Thery's avatar Sylvain Thery

add locking in frame_manipulator

parent 8836ff92
......@@ -47,6 +47,7 @@
#include "glm/gtc/type_precision.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "Utils/textures.h"
using namespace CGoGN;
......@@ -297,12 +298,20 @@ void MyQT::cb_keyPress(int code)
if (m_lastPickedObject)
m_frame->setTransformation(m_lastPickedObject->transfo());
break;
case 'x':
if (m_frame->locked(Utils::FrameManipulator::Xt))
m_frame->unlock(Utils::FrameManipulator::Xt);
else
m_frame->lock(Utils::FrameManipulator::Xt);
break;
case 'w':
if (m_frame->locked(Utils::FrameManipulator::Xt))
m_frame->unlock(Utils::FrameManipulator::Translations);
else
m_frame->lock(Utils::FrameManipulator::Translations);
break;
case 'y':
if (m_frame->locked(Utils::FrameManipulator::Yt))
m_frame->unlock(Utils::FrameManipulator::Yt);
......@@ -370,7 +379,7 @@ int main(int argc, char **argv)
sqt.NBP = atoi(argv[1]);
sqt.setHelpMsg("Param :size of grid (number of objects)\nMpuse:\n"
sqt.setHelpMsg("Param :size of grid (number of objects)\nMpuse (with shift):\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");
......
......@@ -21,8 +21,8 @@
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef POLYHEDRONSVIEW_H_
#define POLYHEDRONSVIEW_H_
#ifndef FRAME_MANIP_EX_H_
#define FRAME_MANIP_EX_H_
#include <iostream>
......
......@@ -120,6 +120,7 @@ inline void GenericMap::embedOrbit(unsigned int orbit, Dart d, unsigned int em)
{
assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded");
FunctorSetEmb<GenericMap> fsetemb(*this, orbit, em);
std::cout << "EMBEDORBIT"<< std::endl;
foreach_dart_of_orbit(orbit, d, fsetemb);
}
......
......@@ -308,7 +308,7 @@ namespace Utils
class FrameManipulator//: public Pickable
{
public:
enum AXIS {NONE=0, CENTER, Xt, Yt, Zt, Xr, Yr, Zr, Xs, Ys, Zs};
enum AXIS {NONE=0, CENTER, Xt, Yt, Zt, Xr, Yr, Zr, Xs, Ys, Zs, Translations, Rotations, Scales};
protected:
......@@ -325,6 +325,11 @@ protected:
*/
bool m_locked_axis[11];
/**
* pinking only locking table
*/
bool m_lockedPicking_axis[11];
/**
* VBO for position
*/
......@@ -389,6 +394,8 @@ protected:
*/
glm::mat4 transfoRenderFrame();
bool axisPickable(unsigned int a) { return (!m_locked_axis[a]) && (!m_lockedPicking_axis[a]);}
public:
FrameManipulator();
......@@ -419,20 +426,55 @@ public:
/**
* lock an axis
* lock an axis (drawing & picking are disabled)
* @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
*/
void lock(unsigned int axis);
/**
* unlock an axis
* @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
*/
void unlock(unsigned int axis);
/**
* is an axis locked
* @param axis the axis to test
*/
bool locked(unsigned int axis);
/**
* lock an axis only for pinking
*/
void lockPicking(unsigned int axis);
/// lock translations for picking only
void lockPickingTranslations();
/// lock rotations for picking only
void lockPickingRotations();
/// lock scales for picking only
void lockPickingScales();
/**
* unlock an axis (only for pinking)
*/
void unlockPicking(unsigned int axis);
/// unlock translations for picking only
void unlockPickingTranslations();
/// unlock rotations for picking only
void unlockPickingRotations();
/// unlock scales for picking only
void unlockPickingScales();
/**
* is an axis locked (only for pinking)
*/
bool lockedPicking(unsigned int axis);
/**
* higlight an axis (change width rendering).
* To unhighlight, just highlight NONE or highlight a already highlighted axis
......
......@@ -32,7 +32,7 @@
//#include "glm/gtc/type_precision.hpp"
//#include "glm/gtc/type_ptr.hpp"
#include <cmath>
//#include <cmath>
namespace CGoGN
{
......@@ -49,7 +49,10 @@ FrameManipulator::FrameManipulator():
{
for (unsigned int i=0; i<11; ++i)
{
m_locked_axis[i]=false;
m_lockedPicking_axis[i]=false;
}
m_vboPos = new VBO();
m_vboPos->setDataSize(3);
......@@ -315,7 +318,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
// click on center
if (dist2 < 0.02f*0.02f)
{
if (! m_locked_axis[CENTER])
// if (! m_locked_axis[CENTER])
if (axisPickable(CENTER))
return CENTER;
else
return NONE;
......@@ -335,74 +339,90 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
Geom::Vec3f Qx;
Geom::Intersection inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(1.0f,0.0f,0.0f), Qx);
if (inter == Geom::FACE_INTERSECTION)
dist_target[3] = Qx.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[3] = sqrtf(dist2) - 1.0f;
if (axisPickable(Xr))
{
if (inter == Geom::FACE_INTERSECTION)
dist_target[3] = Qx.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[3] = sqrt(dist2) - 1.0f;
if (fabs(dist_target[3]) < ring_half_width )
dist_cam[3] = (P-Qx)*(P-Qx);
if (fabs(dist_target[3]) < ring_half_width )
dist_cam[3] = (P-Qx)*(P-Qx);
}
// plane Y=0
Geom::Vec3f Qy;
inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,1.0f,0.0f), Qy);
if (inter == Geom::FACE_INTERSECTION)
dist_target[4] = Qy.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[4] = sqrtf(dist2) - 1.0f;
if (axisPickable(Yr))
{
if (inter == Geom::FACE_INTERSECTION)
dist_target[4] = Qy.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[4] = sqrt(dist2) - 1.0f;
if (fabs(dist_target[4]) < ring_half_width )
dist_cam[4] = (P-Qy)*(P-Qy);
if (fabs(dist_target[4]) < ring_half_width )
dist_cam[4] = (P-Qy)*(P-Qy);
}
// plane Z=0
Geom::Vec3f Qz;
inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,0.0f,1.0f), Qz);
if (inter == Geom::FACE_INTERSECTION)
dist_target[5] = Qz.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[5] = sqrtf(dist2) - 1.0f;
if (fabs(dist_target[5]) < ring_half_width )
dist_cam[5] = (P-Qz)*(P-Qz);
if (axisPickable(Zr))
{
if (inter == Geom::FACE_INTERSECTION)
dist_target[5] = Qz.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[5] = sqrt(dist2) - 1.0f;
if (fabs(dist_target[5]) < ring_half_width )
dist_cam[5] = (P-Qz)*(P-Qz);
}
// axes:
Geom::Vec3f PX(1.0f,0.0f,0.0f);
dist_target[0] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ;
if (fabs(dist_target[0]) < 0.02f)
if (axisPickable(Xt) || axisPickable(Xs))
{
if ( (Qz - origin).norm() > m_lengthAxes[0])
dist_cam[0] = (P-PX)*(P-PX);
else
dist_cam[6] = (P-origin)*(P-origin);
}
Geom::Vec3f PX(1.0f,0.0f,0.0f);
dist_target[0] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ;
if (fabs(dist_target[0]) < 0.02f)
{
if ( (Qz - origin).norm() > m_lengthAxes[0])
dist_cam[0] = (P-PX)*(P-PX);
else
dist_cam[6] = (P-origin)*(P-origin);
}
}
Geom::Vec3f PY(0.0f,1.0f,0.0f);
dist_target[1] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ;
if (fabs(dist_target[1]) < 0.02f )
if (axisPickable(Yt) || axisPickable(Ys))
{
if ((Qz - origin).norm() > m_lengthAxes[1])
dist_cam[1] = (P-PY)*(P-PY);
else
dist_cam[7] = (P-origin)*(P-origin);
Geom::Vec3f PY(0.0f,1.0f,0.0f);
dist_target[1] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ;
if (fabs(dist_target[1]) < 0.02f )
{
if ((Qz - origin).norm() > m_lengthAxes[1])
dist_cam[1] = (P-PY)*(P-PY);
else
dist_cam[7] = (P-origin)*(P-origin);
}
}
Geom::Vec3f PZ(0.0f,0.0f,1.0f);
dist_target[2] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PZ));
if (fabs(dist_target[2]) < 0.02f )
if (axisPickable(Zt) || axisPickable(Zs))
{
if ((Qx - origin).norm() > m_lengthAxes[2])
dist_cam[2] = (P-PZ)*(P-PZ);
else
dist_cam[8] = (P-origin)*(P-origin);
Geom::Vec3f PZ(0.0f,0.0f,1.0f);
dist_target[2] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PZ));
if (fabs(dist_target[2]) < 0.02f )
{
if ((Qx - origin).norm() > m_lengthAxes[2])
dist_cam[2] = (P-PZ)*(P-PZ);
else
dist_cam[8] = (P-origin)*(P-origin);
}
}
// find min dist_cam value;
unsigned int min_index=0;
float min_val = dist_cam[0];
......@@ -417,7 +437,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
if (min_val < std::numeric_limits<float>::max())
{
if (! m_locked_axis[Xt+min_index])
// if (! m_locked_axis[Xt+min_index])
if (axisPickable(Xt+min_index))
return Xt+min_index;
}
......@@ -454,13 +475,17 @@ void FrameManipulator::setLengthAxes()
float sc1 = m_scale[1]/avgScale;
float sc2 = m_scale[2]/avgScale;
positions[ind] = 0.23f*sc0;
ind+=7;
positions[ind] = 0.23f*sc1;
ind+=7;
positions[ind] = 0.23f*sc2;
ind++;
positions[ind] = 0.27f*sc0;
if (m_locked_axis[Xs])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc0;
ind+=3;
positions[ind] = 0.75f*sc0;
ind+=3;
......@@ -478,7 +503,10 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le;
ind+=4;
positions[ind] = 0.27f*sc1;
if (m_locked_axis[Ys])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc1;
ind+=3;
positions[ind] = 0.75f*sc1;
ind+=3;
......@@ -496,7 +524,10 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le;
ind+=4;
positions[ind] = 0.27f*sc2;
if (m_locked_axis[Zs])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc2;
ind+=3;
positions[ind] = 0.75f*sc2;
ind+=3;
......@@ -620,20 +651,131 @@ void FrameManipulator::setTransformation( const glm::mat4& transfo)
void FrameManipulator::lock(unsigned int axis)
{
m_locked_axis[axis] = true;
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_locked_axis[Xt] = true;
m_locked_axis[Yt] = true;
m_locked_axis[Zt] = true;
break;
case Rotations:
m_locked_axis[Xr] = true;
m_locked_axis[Yr] = true;
m_locked_axis[Zr] = true;
break;
case Scales:
m_locked_axis[Xs] = true;
m_locked_axis[Ys] = true;
m_locked_axis[Zs] = true;
break;
default:
m_locked_axis[axis] = true;
break;
}
setLengthAxes();
}
void FrameManipulator::unlock(unsigned int axis)
{
m_locked_axis[axis] = false;
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_locked_axis[Xt] = false;
m_locked_axis[Yt] = false;
m_locked_axis[Zt] = false;
break;
case Rotations:
m_locked_axis[Xr] = false;
m_locked_axis[Yr] = false;
m_locked_axis[Zr] = false;
break;
case Scales:
m_locked_axis[Xs] = false;
m_locked_axis[Ys] = false;
m_locked_axis[Zs] = false;
break;
default:
m_locked_axis[axis] = false;
break;
}
setLengthAxes();
}
bool FrameManipulator::locked(unsigned int axis)
{
assert(axis <=Zs);
return m_locked_axis[axis];
}
void FrameManipulator::lockPicking(unsigned int axis)
{
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_lockedPicking_axis[Xt] = true;
m_lockedPicking_axis[Yt] = true;
m_lockedPicking_axis[Zt] = true;
break;
case Rotations:
m_lockedPicking_axis[Xr] = true;
m_lockedPicking_axis[Yr] = true;
m_lockedPicking_axis[Zr] = true;
break;
case Scales:
m_lockedPicking_axis[Xs] = true;
m_lockedPicking_axis[Ys] = true;
m_lockedPicking_axis[Zs] = true;
break;
default:
m_lockedPicking_axis[axis] = true;
break;
}
setLengthAxes();
}
void FrameManipulator::unlockPicking(unsigned int axis)
{
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_lockedPicking_axis[Xt] = false;
m_lockedPicking_axis[Yt] = false;
m_lockedPicking_axis[Zt] = false;
break;
case Rotations:
m_lockedPicking_axis[Xr] = false;
m_lockedPicking_axis[Yr] = false;
m_lockedPicking_axis[Zr] = false;
break;
case Scales:
m_lockedPicking_axis[Xs] = false;
m_lockedPicking_axis[Ys] = false;
m_lockedPicking_axis[Zs] = false;
break;
default:
m_lockedPicking_axis[axis] = false;
break;
}
setLengthAxes();
}
bool FrameManipulator::lockedPicking(unsigned int axis)
{
return m_lockedPicking_axis[axis];
}
Geom::Vec3f FrameManipulator::getAxis(unsigned int ax)
{
unsigned int i = (ax-Xt)%3;
......@@ -726,7 +868,7 @@ void FrameManipulator::rotateInScreen(int dx, int dy)
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]));
glm::mat4 tr = glm::rotate(glm::mat4(1.0f),float(sqrt(dx*dx+dy*dy))/2.0f,glm::vec3(axisRotation[0],axisRotation[1],axisRotation[2]));
m_rotations = tr*m_rotations;
}
......
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