frameManipulator.h 6.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*******************************************************************************
 * 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                                        *
 *                                                                              *
 *******************************************************************************/


#ifndef __FRAMEMANIPULATOR_H_
#define __FRAMEMANIPULATOR_H_

#include "Utils/vbo.h"
#include "glm/glm.hpp"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/pickables.h"

namespace CGoGN
{

namespace Utils
{



class FrameManipulator//: public Pickable
{
public:
45
	enum AXIS {NONE=0, CENTER, Xt, Yt, Zt, Xr, Yr, Zr, Xs, Ys, Zs, Translations, Rotations, Scales};
46 47 48 49 50 51 52 53

protected:

	/**
	 * number of segment for circle drawing
	 */
	static const unsigned int nb_segments = 64;

thery's avatar
thery committed
54
	static const float ring_half_width;
55 56 57 58 59 60

	/**
	 * locking table
	 */
	bool m_locked_axis[11];

61 62 63 64 65
	/**
	 * pinking only locking table
	 */
	bool m_lockedPicking_axis[11];

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
	/**
	 * VBO for position
	 */
	Utils::VBO* m_vboPos;

	/**
	 * VBO for color
	 */
	Utils::VBO* m_vboCol;

	/**
	 * Shader
	 */
	Utils::ShaderSimpleColor* m_shader;

	/**
	 * the axis to be highlighted
	 */
	unsigned int m_highlighted;

	/**
	 * Rotation matrices
	 */
	glm::mat4 m_rotations;

	/**
	 * scale rendering factor
	 */
	float m_scaleRendering;

	/**
	 * translation
	 */
	glm::vec3 m_trans;

	/**
	 * scale
	 */
	glm::vec3 m_scale;

	/**
	 * epsilon distance for picking
	 */
	float m_epsilon;

	/**
	 * compute and set length axes / scale factors
	 */
	void setLengthAxes();

	/**
	 * length of axes
	 */
	Geom::Vec3f m_lengthAxes;

	Geom::Vec3f m_projectedSelectedAxis;

	Geom::Vec3f m_projectedOrigin;

	/**
	 * get the matrix transformation with the scale factor for rendering
	 */
	glm::mat4 transfoRenderFrame();

130 131
	bool axisPickable(unsigned int a) { return (!m_locked_axis[a]) && (!m_lockedPicking_axis[a]);}

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
public:
	FrameManipulator();

	/**
	 * set size of frame (for rendering)
	 */
	void setSize(float radius);

	/**
	 * add a (signed) val to the size of frame
	 */
	void addSize(float val);

	/**
	 * get the size of frame
	 */
	float getSize();

	/**
	 * draw the frame
	 */
	void draw();

	/**
	 * try picking the frame
	 */
	 unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);


	 /**
162 163
	  * 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)
164 165 166 167 168
	  */
	 void lock(unsigned int axis);

	 /**
	  * unlock an axis
169
	  * @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
170 171 172
	  */
	 void unlock(unsigned int axis);

Sylvain Thery's avatar
Sylvain Thery committed
173 174
	 /**
	  * is an axis locked
175
	  * @param axis the axis to test
Sylvain Thery's avatar
Sylvain Thery committed
176 177 178
	  */
	 bool locked(unsigned int axis);

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	 /**
	  * lock an axis only for pinking
	  */
	 void lockPicking(unsigned int axis);

	 /**
	  * unlock an axis (only for pinking)
	  */
	 void unlockPicking(unsigned int axis);

	 /**
	  * is an axis locked (only for pinking)
	  */
	 bool lockedPicking(unsigned int axis);

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	/**
	 * higlight an axis (change width rendering).
	 * To unhighlight, just highlight NONE or highlight a already highlighted  axis
	 */
	void highlight(unsigned int axis);

	/**
	 * rotate the frame around one of its axis
	 */
	void rotate(unsigned int axis, float angle);

	/**
	 * translate the frame around one of its axis
	 * @param axis
	 * @param x ratio of frame radius
	 */
	void translate(unsigned int axis, float x);

	/**
	 * scale the frame in direction of one axis
	 * @param axis (Xs/Ys/Zs/CENTER)
	 * @param sc scale factor to apply on
	 */
	void scale(unsigned int axis, float sc);

	/**
	 * get the matrix transformation
	 */
	glm::mat4 transfo();

	/**
	 * set the position of frame
	 * @param P the position of origin
	 */
	void setTranslation(const Geom::Vec3f& P);

	Geom::Vec3f getPosition() { return Geom::Vec3f(m_trans[0],m_trans[1],m_trans[2]);}

	Geom::Vec3f getAxis(unsigned int ax);

//	void project(unsigned int ax, Geom::Vec3f& origin, Geom::Vec3f& vect);

	void storeProjection(unsigned int ax);

	/**
	 * set the scale of frame
	 * @param P the vector of scale factors
	 */
	void setScale(const Geom::Vec3f& S);

	/**
	 * set the orientation of frame (Z is deduced)
	 * @param X the vector X of frame
	 * @param Y the vector Y of frame
	 * @return return false if parameters are not unit orthogonal vectors
	 */
	bool setOrientation(const Geom::Vec3f& X, const Geom::Vec3f& Y);

	/**
	 * set transformation matrix
	 */
	void setTransformation( const glm::mat4& transfo);



	float angleFromMouse(int x, int y, int dx, int dy);

	float distanceFromMouse(int dx, int dy);

	float scaleFromMouse(int dx, int dy);

//	float factorCenterFromMouse(int dx, int dy);

	static bool rotationAxis(unsigned int axis) { return (axis>=Xr) && (axis<=Zr);}
	static bool translationAxis(unsigned int axis) { return (axis>=Xt) && (axis<=Zt);}
	static bool scaleAxis(unsigned int axis) { return ((axis>=Xs) && (axis<=Zs))|| (axis==CENTER);}

Sylvain Thery's avatar
Sylvain Thery committed
271 272 273 274 275 276
	/**
	 * translate from screen mouse move
	 */
	void translateInScreen(int dx, int dy);

	void rotateInScreen(int dx, int dy);
277 278 279 280 281 282
};


}
}
#endif