/******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009-2011, 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: http://cgogn.u-strasbg.fr/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/#include "Utils/frameManipulator.h"#include "Geometry/distances.h"#include "Geometry/intersection.h"#include <glm/ext.hpp>//#include <glm/gtc/matrix_transform.hpp>//#include "glm/gtc/type_precision.hpp"//#include "glm/gtc/type_ptr.hpp"

m_vboPos=newVBO();m_vboPos->setDataSize(3);m_vboCol=newVBO();m_vboCol->setDataSize(3);m_shader=newShaderSimpleColor();m_shader->setAttributePosition(m_vboPos);GLSLShader::registerShader(NULL,m_shader);std::vector<Geom::Vec3f>points;points.reserve(6*nb_segments+30);points.resize(6*nb_segments+6);unsignedintsecond=2*(nb_segments+1);unsignedintthird=4*(nb_segments+1);for(unsignedinti=0;i<=nb_segments;++i){floatalpha=float(i)*M_PI/float(nb_segments/2);floatx=(1.0f+ring_half_width)*cos(alpha);floaty=(1.0f+ring_half_width)*sin(alpha);floatxx=(1.0f-ring_half_width)*cos(alpha);floatyy=(1.0f-ring_half_width)*sin(alpha);points[2*i]=Geom::Vec3f(0.0f,x,y);points[2*i+1]=Geom::Vec3f(0.0f,xx,yy);points[second+2*i]=Geom::Vec3f(x,0.0f,y);points[second+2*i+1]=Geom::Vec3f(xx,0.0f,yy);points[third+2*i]=Geom::Vec3f(x,y,0.0f);points[third+2*i+1]=Geom::Vec3f(xx,yy,0.0f);}points.push_back(Geom::Vec3f(0.0f,0.0f,0.0f));points.push_back(Geom::Vec3f(0.23f,0.0f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.0f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.23f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.0f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.0f,0.23f));points.push_back(Geom::Vec3f(0.27f,0.0f,0.0f));points.push_back(Geom::Vec3f(0.75f,0.0f,0.0f));points.push_back(Geom::Vec3f(0.9f,0.0f,0.0f));points.push_back(Geom::Vec3f(0.7f,-0.03f,0.0f));points.push_back(Geom::Vec3f(0.7f,0.0f,-0.03f));points.push_back(Geom::Vec3f(0.7f,0.03f,0.0f));points.push_back(Geom::Vec3f(0.7f,0.0f,0.03f));points.push_back(Geom::Vec3f(0.7f,-0.03f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.27f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.75f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.9f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.7f,0.03f));points.push_back(Geom::Vec3f(0.03f,0.7f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.7f,-0.03f));points.push_back(Geom::Vec3f(-0.03f,0.7f,0.0f));points.push_back(Geom::Vec3f(0.0f,0.7f,0.03f));points.push_back(Geom::Vec3f(0.0f,0.0f,0.27f));points.push_back(Geom::Vec3f(0.0f,0.0f,0.75f));points.push_back(Geom::Vec3f(0.0f,0.0f,0.9f));points.push_back(Geom::Vec3f(0.03f,0.0f,0.7f));points.push_back(Geom::Vec3f(0.0f,0.03f,0.7f));points.push_back(Geom::Vec3f(-0.03f,0.0f,0.7f));points.push_back(Geom::Vec3f(0.0f,-0.03f,0.7f));points.push_back(Geom::Vec3f(0.03f,0.0f,0.7f));m_vboPos->bind();glBufferData(GL_ARRAY_BUFFER,points.size()*sizeof(Geom::Vec3f),&(points[0]),GL_STREAM_DRAW);}voidFrameManipulator::setSize(floatradius){m_scaleRendering=radius;}voidFrameManipulator::addSize(floatradius){m_scaleRendering+=radius;}floatFrameManipulator::getSize(){returnm_scaleRendering;}voidFrameManipulator::draw(){glm::mat4store=Utils::GLSLShader::currentTransfo();Utils::GLSLShader::currentTransfo()*=transfoRenderFrame();Utils::GLSLShader::updateCurrentMatrices();glPushAttrib(GL_LINE_BIT);m_shader->enableVertexAttribs();if(!m_locked_axis[Xr]){if(m_highlighted==Xr)m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));elsem_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f));glDrawArrays(GL_TRIANGLE_STRIP,0,2*nb_segments+2);}if(!m_locked_axis[Yr]){if(m_highlighted==Yr)m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));elsem_shader->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f));glDrawArrays(GL_TRIANGLE_STRIP,2*nb_segments+2,2*nb_segments+2);}if(!m_locked_axis[Zr]){if(m_highlighted==Zr)m_shader->setColor(Geom::Vec4f(1.0,1.0,0.0f,0.0f));elsem_shader->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f));glDrawArrays(GL_TRIANGLE_STRIP,4*nb_segments+4,2*nb_segments+2);}if(!m_locked_axis[Xs]){if((m_highlighted==CENTER)||(m_highlighted==Xs)){glLineWidth(6.0f);m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));}else{glLineWidth(3.0f);m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f));}glDrawArrays(GL_LINES,6*nb_segments+6,2);}if(!m_locked_axis[Ys]){if((m_highlighted==CENTER)||(m_highlighted==Ys)){glLineWidth(6.0f);m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));}else{glLineWidth(3.0f);m_shader->setColor(Geom::Vec4f(0.0f,0.7f,0.0f,0.0f));}glDrawArrays(GL_LINES,6*nb_segments+8,2);}if(!m_locked_axis[Zs]){if((m_highlighted==CENTER)||(m_highlighted==Zs)){glLineWidth(6.0f);m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));}else{glLineWidth(3.0f);m_shader->setColor(Geom::Vec4f(0.0f,0.0f,0.7f,0.0f));}glDrawArrays(GL_LINES,6*nb_segments+10,2);}if(!m_locked_axis[Xt]){if(m_highlighted==Xt){m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));glLineWidth(6.0f);}else{glLineWidth(3.0f);m_shader->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f));}glDrawArrays(GL_LINES,6*nb_segments+12,2);glDrawArrays(GL_TRIANGLE_FAN,6*nb_segments+14,6);}if(!m_locked_axis[Yt]){if(m_highlighted==Yt){glLineWidth(6.0f);m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));}else{glLineWidth(3.0f);m_shader->setColor(Geom::Vec4f(0.0f,1.0f,0.0f,0.0f));}glDrawArrays(GL_LINES,6*nb_segments+20,2);glDrawArrays(GL_TRIANGLE_FAN,6*nb_segments+22,6);}if(!m_locked_axis[Zt]){if(m_highlighted==Zt){glLineWidth(6.0f);m_shader->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f));}else{glLineWidth(3.0f);m_shader->setColor(Geom::Vec4f(0.0f,0.0f,1.0f,0.0f));}glDrawArrays(GL_LINES,6*nb_segments+28,2);glDrawArrays(GL_TRIANGLE_FAN,6*nb_segments+30,6);}m_shader->disableVertexAttribs();glPopAttrib();Utils::GLSLShader::currentTransfo()=store;}voidFrameManipulator::highlight(unsignedintaxis){if(m_highlighted==axis)m_highlighted=NONE;elsem_highlighted=axis;}unsignedintFrameManipulator::pick(constGeom::Vec3f&PP,constGeom::Vec3f&VV,floatepsilon){Geom::Vec3fP,V;Pickable::invertPV(PP,VV,transfoRenderFrame(),P,V);// origin of frameGeom::Vec3forigin(0.0f,0.0f,0.0f);// intersection possible between line and frame (10% margin)?floatdist2=Geom::squaredDistanceLine2Point<Geom::Vec3f>(P,V,V*V,origin);if(dist2>(1.05))returnNONE;// click on centerif(dist2<0.02f*0.02f){