frameManipulator.h 6.72 KB
Newer Older
1 2 3
/*******************************************************************************
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
4
 * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *                                                                              *
 * 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.           *
 *                                                                              *
20
 * Web site: http://cgogn.unistra.fr/                                           *
21 22 23 24 25 26 27 28
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/


#ifndef __FRAMEMANIPULATOR_H_
#define __FRAMEMANIPULATOR_H_

Thery Sylvain's avatar
Thery Sylvain committed
29
#include "Utils/vbo_base.h"
30 31
#include "glm/glm.hpp"
#include "Utils/Shaders/shaderSimpleColor.h"
32
#include "Utils/Shaders/shaderBoldLines.h"
33 34
#include "Utils/pickables.h"

Sylvain Thery's avatar
Sylvain Thery committed
35 36
#include "Utils/dll.h"

37 38 39 40 41 42
namespace CGoGN
{

namespace Utils
{

Sylvain Thery's avatar
Sylvain Thery committed
43
class CGoGN_UTILS_API FrameManipulator//: public Pickable
44 45
{
public:
46
	enum AXIS {NONE=0, CENTER, Xt, Yt, Zt, Xr, Yr, Zr, Xs, Ys, Zs, Translations, Rotations, Scales};
47 48 49 50 51 52 53 54

protected:

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

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

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

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

67 68 69 70 71 72 73 74
	/**
	 * VBO for position
	 */
	Utils::VBO* m_vboPos;

	/**
	 * VBO for color
	 */
75
//	Utils::VBO* m_vboCol;
76 77 78 79 80

	/**
	 * Shader
	 */
	Utils::ShaderSimpleColor* m_shader;
81
	Utils::ShaderBoldLines* m_shaderBL;
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 130 131

	/**
	 * 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();

Sylvain Thery's avatar
Sylvain Thery committed
132
	inline bool axisPickable(unsigned int a) { return (!m_locked_axis[a]) && (!m_lockedPicking_axis[a]);}
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 162 163
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);


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

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

175 176
	 /**
	  * is an axis locked
177
	  * @param axis the axis to test
178 179 180
	  */
	 bool locked(unsigned int axis);

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
	 /**
	  * 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);

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
	/**
	 * 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);

Sylvain Thery's avatar
Sylvain Thery committed
232
	inline Geom::Vec3f getPosition() { return Geom::Vec3f(m_trans[0], m_trans[1], m_trans[2]); }
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

	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);

Sylvain Thery's avatar
Sylvain Thery committed
269 270 271
	inline static bool rotationAxis(unsigned int axis) { return (axis >= Xr) && (axis <= Zr); }
	inline static bool translationAxis(unsigned int axis) { return (axis >= Xt) && (axis <= Zt); }
	inline static bool scaleAxis(unsigned int axis) { return ((axis >= Xs) && (axis <= Zs)) || (axis == CENTER); }
272

273 274 275 276 277 278
	/**
	 * translate from screen mouse move
	 */
	void translateInScreen(int dx, int dy);

	void rotateInScreen(int dx, int dy);
279 280 281 282 283 284
};


}
}
#endif