Commit e616076c authored by Maire Nicolas's avatar Maire Nicolas

Merge branch 'master' of cgogn:~cgogn/CGoGN

parents 24437f2d b36a3172
...@@ -120,6 +120,9 @@ class Matrix ...@@ -120,6 +120,9 @@ class Matrix
// Matrix / Scalar multiplication // Matrix / Scalar multiplication
Matrix<M,N,T> operator*(T s) const; Matrix<M,N,T> operator*(T s) const;
// Matrix / Scalar division
Matrix<M,N,T> operator/(T s) const;
/**********************************************/ /**********************************************/
/* UTILITY FUNCTIONS */ /* UTILITY FUNCTIONS */
/**********************************************/ /**********************************************/
......
...@@ -299,6 +299,16 @@ Matrix<M,N,T> Matrix<M,N,T>::operator*(T s) const ...@@ -299,6 +299,16 @@ Matrix<M,N,T> Matrix<M,N,T>::operator*(T s) const
return res ; return res ;
} }
template <unsigned int M, unsigned int N, typename T>
Matrix<M,N,T> Matrix<M,N,T>::operator/(T s) const
{
Matrix<M,N,T> res ;
for(unsigned int i = 0; i < M; ++i)
for(unsigned int j = 0; j < N; ++j)
res(i,j) = m_data[i][j] / s ;
return res ;
}
/**********************************************/ /**********************************************/
/* UTILITY FUNCTIONS */ /* UTILITY FUNCTIONS */
/**********************************************/ /**********************************************/
......
...@@ -182,28 +182,11 @@ public: ...@@ -182,28 +182,11 @@ public:
*/ */
void lockPicking(unsigned int axis); 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) * unlock an axis (only for pinking)
*/ */
void unlockPicking(unsigned int axis); 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) * is an axis locked (only for pinking)
*/ */
...@@ -234,9 +217,6 @@ public: ...@@ -234,9 +217,6 @@ public:
*/ */
void scale(unsigned int axis, float sc); void scale(unsigned int axis, float sc);
/** /**
* get the matrix transformation * get the matrix transformation
*/ */
......
...@@ -429,7 +429,7 @@ public: ...@@ -429,7 +429,7 @@ public:
* @param par number of parallels * @param par number of parallels
* @param mer number of meridians * @param mer number of meridians
*/ */
IcoSphere(unsigned int sub=1); IcoSphere(unsigned int sub=5);
/** /**
......
...@@ -135,12 +135,15 @@ FrameManipulator::FrameManipulator(): ...@@ -135,12 +135,15 @@ FrameManipulator::FrameManipulator():
void FrameManipulator::setSize(float radius) void FrameManipulator::setSize(float radius)
{ {
m_scaleRendering = radius; if (m_scaleRendering >0.0f)
m_scaleRendering = radius;
} }
void FrameManipulator::addSize(float radius) void FrameManipulator::addSize(float radius)
{ {
m_scaleRendering += radius; m_scaleRendering += radius;
if (m_scaleRendering <= 0.0f)
m_scaleRendering -= radius;
} }
float FrameManipulator::getSize() float FrameManipulator::getSize()
...@@ -186,10 +189,17 @@ void FrameManipulator::draw() ...@@ -186,10 +189,17 @@ void FrameManipulator::draw()
glDrawArrays(GL_TRIANGLE_STRIP, 4*nb_segments+4, 2*nb_segments+2); glDrawArrays(GL_TRIANGLE_STRIP, 4*nb_segments+4, 2*nb_segments+2);
} }
if ((!m_locked_axis[CENTER]) && (m_highlighted == CENTER))
{
glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
glDrawArrays(GL_LINES, 6*nb_segments+6, 6);
}
else
{
if (!m_locked_axis[Xs]) if (!m_locked_axis[Xs])
{ {
if ((m_highlighted == CENTER) || (m_highlighted == Xs)) if (m_highlighted == Xs)
{ {
glLineWidth(6.0f); glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
...@@ -204,7 +214,7 @@ void FrameManipulator::draw() ...@@ -204,7 +214,7 @@ void FrameManipulator::draw()
if (!m_locked_axis[Ys]) if (!m_locked_axis[Ys])
{ {
if ((m_highlighted == CENTER) || (m_highlighted == Ys)) if (m_highlighted == Ys)
{ {
glLineWidth(6.0f); glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
...@@ -219,7 +229,7 @@ void FrameManipulator::draw() ...@@ -219,7 +229,7 @@ void FrameManipulator::draw()
if (!m_locked_axis[Zs]) if (!m_locked_axis[Zs])
{ {
if ((m_highlighted == CENTER) || (m_highlighted == Zs)) if (m_highlighted == Zs)
{ {
glLineWidth(6.0f); glLineWidth(6.0f);
m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));
...@@ -231,6 +241,8 @@ void FrameManipulator::draw() ...@@ -231,6 +241,8 @@ void FrameManipulator::draw()
} }
glDrawArrays(GL_LINES, 6*nb_segments+10, 2); glDrawArrays(GL_LINES, 6*nb_segments+10, 2);
} }
}
if (!m_locked_axis[Xt]) if (!m_locked_axis[Xt])
{ {
...@@ -312,13 +324,17 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV ...@@ -312,13 +324,17 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
// intersection possible between line and frame (10% margin)? // intersection possible between line and frame (10% margin)?
float dist2 = Geom::squaredDistanceLine2Point<Geom::Vec3f>(P,V,V*V,origin); float dist2 = Geom::squaredDistanceLine2Point<Geom::Vec3f>(P,V,V*V,origin);
if (dist2 > (1.05))
float distMax= std::max(m_lengthAxes[0],std::max(m_lengthAxes[1],m_lengthAxes[2]));
distMax *=3.6f;
distMax= std::max(distMax,1.0f+ring_half_width);
if (dist2 > distMax*distMax)
return NONE; return NONE;
// click on center // click on center
if (dist2 < 0.02f*0.02f) if (dist2 < 0.02f*0.02f)
{ {
// if (! m_locked_axis[CENTER])
if (axisPickable(CENTER)) if (axisPickable(CENTER))
return CENTER; return CENTER;
else else
...@@ -384,42 +400,57 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV ...@@ -384,42 +400,57 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
if (axisPickable(Xt) || axisPickable(Xs)) if (axisPickable(Xt) || axisPickable(Xs))
{ {
Geom::Vec3f PX(1.0f,0.0f,0.0f); Geom::Vec3f PX(3.6f*m_lengthAxes[0],0.0f,0.0f);
dist_target[0] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ; dist_target[0] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ;
if (fabs(dist_target[0]) < 0.02f) if (fabs(dist_target[0]) < 0.02f)
{ {
if ( (Qz - origin).norm() > m_lengthAxes[0]) if (axisPickable(Xt) && !axisPickable(Xs))
dist_cam[0] = (P-PX)*(P-PX); dist_cam[0] = (P-PX)*(P-PX);
else else
dist_cam[6] = (P-origin)*(P-origin); {
if ( Qz.norm() > m_lengthAxes[0])
dist_cam[0] = (P-PX)*(P-PX);
else
dist_cam[6] = P*P;
}
} }
} }
if (axisPickable(Yt) || axisPickable(Ys)) if (axisPickable(Yt) || axisPickable(Ys))
{ {
Geom::Vec3f PY(0.0f,1.0f,0.0f); Geom::Vec3f PY(0.0f,3.6f*m_lengthAxes[1],0.0f);
dist_target[1] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ; dist_target[1] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ;
if (fabs(dist_target[1]) < 0.02f ) if (fabs(dist_target[1]) < 0.02f)
{ {
if ((Qz - origin).norm() > m_lengthAxes[1]) if (axisPickable(Yt) && !axisPickable(Ys))
dist_cam[1] = (P-PY)*(P-PY); dist_cam[1] = (P-PY)*(P-PY);
else else
dist_cam[7] = (P-origin)*(P-origin); {
if (Qz.norm() > m_lengthAxes[1])
dist_cam[1] = (P-PY)*(P-PY);
else
dist_cam[7] = P*P;
}
} }
} }
if (axisPickable(Zt) || axisPickable(Zs)) if (axisPickable(Zt) || axisPickable(Zs))
{ {
Geom::Vec3f PZ(0.0f,0.0f,1.0f); Geom::Vec3f PZ(0.0f,0.0f,3.6f*m_lengthAxes[2]);
dist_target[2] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PZ)); dist_target[2] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PZ));
if (fabs(dist_target[2]) < 0.02f ) if (fabs(dist_target[2]) < 0.02f )
{ {
if ((Qx - origin).norm() > m_lengthAxes[2]) if (axisPickable(Zt) && !axisPickable(Zs))
dist_cam[2] = (P-PZ)*(P-PZ); dist_cam[2] = (P-PZ)*(P-PZ);
else else
dist_cam[8] = (P-origin)*(P-origin); {
if (Qx.norm() > m_lengthAxes[2])
dist_cam[2] = (P-PZ)*(P-PZ);
else
dist_cam[8] = P*P;
}
} }
} }
...@@ -482,7 +513,7 @@ void FrameManipulator::setLengthAxes() ...@@ -482,7 +513,7 @@ void FrameManipulator::setLengthAxes()
ind+=7; ind+=7;
positions[ind] = 0.23f*sc2; positions[ind] = 0.23f*sc2;
ind++; ind++;
if (m_locked_axis[Xs]) if ((m_locked_axis[Xs])&&(m_highlighted!=CENTER))
positions[ind] = 0.0f; positions[ind] = 0.0f;
else else
positions[ind] = 0.27f*sc0; positions[ind] = 0.27f*sc0;
...@@ -503,7 +534,7 @@ void FrameManipulator::setLengthAxes() ...@@ -503,7 +534,7 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le; positions[ind] = le;
ind+=4; ind+=4;
if (m_locked_axis[Ys]) if ((m_locked_axis[Ys])&&(m_highlighted!=CENTER))
positions[ind] = 0.0f; positions[ind] = 0.0f;
else else
positions[ind] = 0.27f*sc1; positions[ind] = 0.27f*sc1;
...@@ -524,7 +555,7 @@ void FrameManipulator::setLengthAxes() ...@@ -524,7 +555,7 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le; positions[ind] = le;
ind+=4; ind+=4;
if (m_locked_axis[Zs]) if ((m_locked_axis[Zs])&&(m_highlighted!=CENTER))
positions[ind] = 0.0f; positions[ind] = 0.0f;
else else
positions[ind] = 0.27f*sc2; positions[ind] = 0.27f*sc2;
......
...@@ -112,6 +112,7 @@ void Pickable::draw() ...@@ -112,6 +112,7 @@ void Pickable::draw()
Utils::GLSLShader::updateCurrentMatrices(); Utils::GLSLShader::updateCurrentMatrices();
m_drawable->draw(); m_drawable->draw();
Utils::GLSLShader::currentTransfo() = store; Utils::GLSLShader::currentTransfo() = store;
Utils::GLSLShader::updateCurrentMatrices();
} }
...@@ -310,6 +311,10 @@ Sphere::Sphere(unsigned int par, unsigned int mer) ...@@ -310,6 +311,10 @@ Sphere::Sphere(unsigned int par, unsigned int mer)
void Sphere::changeTopo(unsigned int parp, unsigned int mer) void Sphere::changeTopo(unsigned int parp, unsigned int mer)
{ {
if (parp<2)
parp=2;
if (mer<2)
mer=2;
// to obtain right number of slice // to obtain right number of slice
unsigned int par = parp-1; unsigned int par = parp-1;
...@@ -438,6 +443,11 @@ Cone::Cone(unsigned int par, unsigned int mer) ...@@ -438,6 +443,11 @@ Cone::Cone(unsigned int par, unsigned int mer)
void Cone::changeTopo(unsigned int par, unsigned int mer) void Cone::changeTopo(unsigned int par, unsigned int mer)
{ {
if (par<2)
par=2;
if (mer<2)
mer=2;
unsigned int merfactor=1; unsigned int merfactor=1;
if (mer<8) if (mer<8)
...@@ -558,10 +568,14 @@ Cylinder::Cylinder(unsigned int par, unsigned int mer) ...@@ -558,10 +568,14 @@ Cylinder::Cylinder(unsigned int par, unsigned int mer)
void Cylinder::changeTopo(unsigned int parp, unsigned int mer) void Cylinder::changeTopo(unsigned int parp, unsigned int mer)
{ {
if (parp<2)
parp=2;
if (mer<2)
mer=2;
// to obtain right number of slice (with almost same code as sphere) // to obtain right number of slice (with almost same code as sphere)
unsigned int par = parp+1; unsigned int par = parp+1;
unsigned int merfactor=1; unsigned int merfactor=1;
if (mer<8) if (mer<8)
...@@ -865,6 +879,8 @@ void IcoSphere::subdivide(std::vector<unsigned int>& triangles, std::vector<Geom ...@@ -865,6 +879,8 @@ void IcoSphere::subdivide(std::vector<unsigned int>& triangles, std::vector<Geom
void IcoSphere::changeTopo(unsigned int sub) void IcoSphere::changeTopo(unsigned int sub)
{ {
if (sub<2)
sub=2;
int subd = 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;
......
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