MouseController.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_OPENGL2_MOUSECONTROLLER_H
  9. #define IGL_OPENGL2_MOUSECONTROLLER_H
  10. // Needs to be included before others
  11. #include <Eigen/StdVector>
  12. #include "RotateWidget.h"
  13. #include "TranslateWidget.h"
  14. #include <Eigen/Core>
  15. #include <Eigen/Geometry>
  16. #include <vector>
  17. // Class for control a skeletal FK rig with the mouse.
  18. namespace igl
  19. {
  20. namespace opengl2
  21. {
  22. class MouseController
  23. {
  24. public:
  25. typedef Eigen::VectorXi VectorXb;
  26. // Propagate selection to descendants so that selected bones and their
  27. // subtrees are all selected.
  28. //
  29. // Input:
  30. // S #S list of whether selected
  31. // P #S list of bone parents
  32. // Output:
  33. // T #S list of whether selected
  34. static inline void propogate_to_descendants_if(
  35. const VectorXb & S,
  36. const Eigen::VectorXi & P,
  37. VectorXb & T);
  38. // Create a matrix of colors for the selection and their descendants.
  39. //
  40. // Inputs:
  41. // selection #S list of whether a bone is selected
  42. // selected_color color for selected bones
  43. // unselected_color color for unselected bones
  44. // Outputs:
  45. // C #P by 4 list of colors
  46. static inline void color_if(
  47. const VectorXb & S,
  48. const Eigen::Vector4f & selected_color,
  49. const Eigen::Vector4f & unselected_color,
  50. Eigen::MatrixXf & C);
  51. enum WidgetMode
  52. {
  53. WIDGET_MODE_ROTATE = 0,
  54. WIDGET_MODE_TRANSLATE = 1,
  55. NUM_WIDGET_MODES = 2,
  56. };
  57. private:
  58. // m_is_selecting whether currently selecting
  59. // m_selection #m_rotations list of whether a bone is selected
  60. // m_down_x x-coordinate of mouse location at down
  61. // m_down_y y-coordinate 〃
  62. // m_drag_x x-coordinate of mouse location at drag
  63. // m_drag_y y-coordinate 〃
  64. // m_widget rotation widget for selected bone
  65. // m_width width of containing window
  66. // m_height height 〃
  67. // m_rotations list of rotations for each bone
  68. // m_rotations_at_selection list of rotations for each bone at time of
  69. // selection
  70. // m_translations list of translations for each bone
  71. // m_fk_rotations_at_selection list of rotations for each bone at time of
  72. // selection
  73. // m_root_enabled Whether root is enabled
  74. bool m_is_selecting;
  75. VectorXb m_selection;
  76. int m_down_x,m_down_y,m_drag_x,m_drag_y;
  77. int m_width,m_height;
  78. igl::opengl2::RotateWidget m_widget;
  79. igl::opengl2::TranslateWidget m_trans_widget;
  80. Eigen::Quaterniond m_widget_rot_at_selection;
  81. //Eigen::Vector3d m_trans_widget_trans_at_selection;
  82. typedef std::vector<
  83. Eigen::Quaterniond,
  84. Eigen::aligned_allocator<Eigen::Quaterniond> > RotationList;
  85. typedef std::vector< Eigen::Vector3d > TranslationList;
  86. RotationList
  87. m_rotations,
  88. m_rotations_at_selection,
  89. m_fk_rotations_at_selection,
  90. m_parent_rotations_at_selection;
  91. TranslationList
  92. m_translations,
  93. m_translations_at_selection,
  94. m_fk_translations_at_selection;
  95. bool m_root_enabled;
  96. WidgetMode m_widget_mode;
  97. public:
  98. MouseController();
  99. // Returns const reference to m_selection
  100. inline const VectorXb & selection() const{return m_selection;};
  101. // 〃 m_is_selecting
  102. inline const bool & is_selecting() const{return m_is_selecting;}
  103. inline bool is_widget_down() const{return m_widget.is_down();}
  104. inline bool is_trans_widget_down() const{return m_trans_widget.is_down();}
  105. // 〃 m_rotations
  106. inline const RotationList & rotations() const{return m_rotations;}
  107. inline const TranslationList & translations() const{return m_translations;}
  108. // Returns non-const reference to m_root_enabled
  109. inline bool & root_enabled(){ return m_root_enabled;}
  110. inline void reshape(const int w, const int h);
  111. // Process down, drag, up mouse events
  112. //
  113. // Inputs:
  114. // x x-coordinate of mouse click with respect to container
  115. // y y-coordinate 〃
  116. // Returns true if accepted (action taken).
  117. inline bool down(const int x, const int y);
  118. inline bool drag(const int x, const int y);
  119. inline bool up(const int x, const int y);
  120. // Draw selection box and widget
  121. inline void draw() const;
  122. // Set `m_selection` based on the last drag selection and initialize
  123. // widget.
  124. //
  125. // Inputs:
  126. // C #C by dim list of joint positions at rest
  127. // BE #BE by 2 list of bone indices at rest
  128. // P #P list of bone parents
  129. inline void set_selection_from_last_drag(
  130. const Eigen::MatrixXd & C,
  131. const Eigen::MatrixXi & BE,
  132. const Eigen::VectorXi & P,
  133. const Eigen::VectorXi & RP);
  134. // Set from explicit selection
  135. inline void set_selection(
  136. const Eigen::VectorXi & S,
  137. const Eigen::MatrixXd & C,
  138. const Eigen::MatrixXi & BE,
  139. const Eigen::VectorXi & P,
  140. const Eigen::VectorXi & RP);
  141. // Set size of skeleton
  142. //
  143. // Inputs:
  144. // n number of bones
  145. inline void set_size(const int n);
  146. // Resets m_rotation elements to identity
  147. inline void reset();
  148. inline void reset_selected();
  149. inline void reset_rotations();
  150. inline void reset_selected_rotations();
  151. inline void reset_translations();
  152. inline void reset_selected_translations();
  153. inline bool set_rotations(const RotationList & vQ);
  154. inline bool set_translations(const TranslationList & vT);
  155. // Sets all entries in m_selection to false
  156. inline void clear_selection();
  157. // Returns true iff some element in m_selection is true
  158. inline bool any_selection() const;
  159. inline void set_widget_mode(const WidgetMode & mode);
  160. public:
  161. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  162. };
  163. }
  164. }
  165. // Implementation
  166. #include "../line_segment_in_rectangle.h"
  167. #include "draw_rectangular_marquee.h"
  168. #include "project.h"
  169. #include "../forward_kinematics.h"
  170. #include <iostream>
  171. #include <algorithm>
  172. #include <functional>
  173. inline void igl::opengl2::MouseController::propogate_to_descendants_if(
  174. const VectorXb & S,
  175. const Eigen::VectorXi & P,
  176. VectorXb & T)
  177. {
  178. using namespace std;
  179. const int n = S.rows();
  180. assert(P.rows() == n);
  181. // dynamic programming
  182. T = S;
  183. vector<bool> seen(n,false);
  184. // Recursively look up chain and see if ancestor is selected
  185. const function<bool(int)> look_up = [&](int e) -> bool
  186. {
  187. if(e==-1)
  188. {
  189. return false;
  190. }
  191. if(!seen[e])
  192. {
  193. seen[e] = true;
  194. T(e) |= look_up(P(e));
  195. }
  196. return T(e);
  197. };
  198. for(int e = 0;e<n;e++)
  199. {
  200. if(!seen[e])
  201. {
  202. T(e) = look_up(e);
  203. }
  204. }
  205. }
  206. inline void igl::opengl2::MouseController::color_if(
  207. const VectorXb & S,
  208. const Eigen::Vector4f & selected_color,
  209. const Eigen::Vector4f & unselected_color,
  210. Eigen::MatrixXf & C)
  211. {
  212. C.resize(S.rows(),4);
  213. for(int e=0;e<S.rows();e++)
  214. {
  215. C.row(e) = S(e)?selected_color:unselected_color;
  216. }
  217. }
  218. inline igl::opengl2::MouseController::MouseController():
  219. m_is_selecting(false),
  220. m_selection(),
  221. m_down_x(-1),m_down_y(-1),m_drag_x(-1),m_drag_y(-1),
  222. m_width(-1),m_height(-1),
  223. m_widget(),
  224. m_widget_rot_at_selection(),
  225. //m_trans_widget_trans_at_selection(),
  226. m_trans_widget(),
  227. m_rotations(),
  228. m_translations(),
  229. m_rotations_at_selection(),
  230. m_root_enabled(true),
  231. m_widget_mode(WIDGET_MODE_ROTATE)
  232. {
  233. }
  234. inline void igl::opengl2::MouseController::reshape(const int w, const int h)
  235. {
  236. m_width = w;
  237. m_height = h;
  238. }
  239. inline bool igl::opengl2::MouseController::down(const int x, const int y)
  240. {
  241. using namespace std;
  242. m_down_x = m_drag_x =x;
  243. m_down_y = m_drag_y =y;
  244. const bool widget_down = any_selection() &&
  245. (
  246. (m_widget_mode == WIDGET_MODE_ROTATE && m_widget.down(x,m_height-y)) ||
  247. (m_widget_mode == WIDGET_MODE_TRANSLATE &&
  248. m_trans_widget.down(x,m_height-y))
  249. );
  250. if(!widget_down)
  251. {
  252. m_is_selecting = true;
  253. }
  254. return m_is_selecting || widget_down;
  255. }
  256. inline bool igl::opengl2::MouseController::drag(const int x, const int y)
  257. {
  258. using namespace std;
  259. using namespace Eigen;
  260. m_drag_x = x;
  261. m_drag_y = y;
  262. if(m_is_selecting)
  263. {
  264. return m_is_selecting;
  265. }else
  266. {
  267. switch(m_widget_mode)
  268. {
  269. default: // fall through
  270. case WIDGET_MODE_ROTATE:
  271. {
  272. if(!m_widget.drag(x,m_height-y))
  273. {
  274. return false;
  275. }
  276. assert(any_selection());
  277. assert(m_selection.size() == (int)m_rotations.size());
  278. assert(m_selection.size() == (int)m_translations.size());
  279. for(int e = 0;e<m_selection.size();e++)
  280. {
  281. if(m_selection(e))
  282. {
  283. // Let:
  284. // w.θr = w.θ ⋅ w.θ₀*
  285. // w.θr takes (absolute) frame of w.θ₀ to w.θ:
  286. // w.θ = w.θr ⋅ w.θ₀
  287. // Define:
  288. // w.θ₀ = θfk ⋅ θx,
  289. // the absolute rotation of the x axis to the deformed bone at
  290. // selection. Likewise,
  291. // w.θ = θfk' ⋅ θx,
  292. // the current absolute rotation of the x axis to the deformed bone.
  293. // Define recursively:
  294. // θfk = θfk(p) ⋅ Θr,
  295. // then because we're only changeing this relative rotation
  296. // θfk' = θfk(p) ⋅ Θr ⋅ θr* ⋅ θr'
  297. // θfk' = θfk ⋅ θr* ⋅ θr'
  298. // w.θ ⋅ θx* = θfk ⋅ θr* ⋅ θr'
  299. // θr ⋅ θfk* ⋅ w.θ ⋅ θx* = θr'
  300. // θr ⋅ θfk* ⋅ w.θr ⋅ w.θ₀ ⋅ θx* = θr'
  301. // θr ⋅ θfk* ⋅ w.θr ⋅ θfk ⋅θx ⋅ θx* = θr'
  302. // θr ⋅ θfk* ⋅ w.θr ⋅ θfk = θr'
  303. // which I guess is the right multiply change after being changed to
  304. // the bases of θfk, the rotation of the bone relative to its rest
  305. // frame.
  306. //
  307. const Quaterniond & frame = m_fk_rotations_at_selection[e];
  308. m_rotations[e] =
  309. m_rotations_at_selection[e] *
  310. frame.conjugate() *
  311. (m_widget.rot*m_widget_rot_at_selection.conjugate()) *
  312. frame;
  313. }
  314. }
  315. }
  316. case WIDGET_MODE_TRANSLATE:
  317. {
  318. if(!m_trans_widget.drag(x,m_height-y))
  319. {
  320. return false;
  321. }
  322. assert(any_selection());
  323. assert(m_selection.size() == (int)m_rotations.size());
  324. assert(m_selection.size() == (int)m_translations.size());
  325. for(int e = 0;e<m_selection.size();e++)
  326. {
  327. if(m_selection(e))
  328. {
  329. m_translations[e] =
  330. m_translations_at_selection[e] +
  331. m_parent_rotations_at_selection[e].conjugate()*
  332. m_trans_widget.m_trans;
  333. }
  334. }
  335. }
  336. }
  337. return true;
  338. }
  339. }
  340. inline bool igl::opengl2::MouseController::up(const int x, const int y)
  341. {
  342. m_is_selecting = false;
  343. m_widget.up(x,m_height-y);
  344. m_trans_widget.up(x,m_height-y);
  345. return false;
  346. }
  347. inline void igl::opengl2::MouseController::draw() const
  348. {
  349. if(any_selection())
  350. {
  351. switch(m_widget_mode)
  352. {
  353. default:
  354. case WIDGET_MODE_ROTATE:
  355. m_widget.draw();
  356. break;
  357. case WIDGET_MODE_TRANSLATE:
  358. m_trans_widget.draw();
  359. break;
  360. }
  361. }
  362. if(m_is_selecting)
  363. {
  364. // Remember settings
  365. GLboolean dt;
  366. glGetBooleanv(GL_DEPTH_TEST,&dt);
  367. int old_vp[4];
  368. glGetIntegerv(GL_VIEWPORT,old_vp);
  369. // True screen space
  370. glViewport(0,0,m_width,m_height);
  371. glMatrixMode(GL_PROJECTION);
  372. glPushMatrix();
  373. glLoadIdentity();
  374. gluOrtho2D(0,m_width,0,m_height);
  375. glMatrixMode(GL_MODELVIEW);
  376. glPushMatrix();
  377. glLoadIdentity();
  378. glDisable(GL_DEPTH_TEST);
  379. draw_rectangular_marquee(
  380. m_down_x,
  381. m_height-m_down_y,
  382. m_drag_x,
  383. m_height-m_drag_y);
  384. // Restore settings
  385. glMatrixMode(GL_PROJECTION);
  386. glPopMatrix();
  387. glMatrixMode(GL_MODELVIEW);
  388. glPopMatrix();
  389. glViewport(old_vp[0],old_vp[1],old_vp[2],old_vp[3]);
  390. dt?glEnable(GL_DEPTH_TEST):glDisable(GL_DEPTH_TEST);
  391. }
  392. }
  393. inline void igl::opengl2::MouseController::set_selection_from_last_drag(
  394. const Eigen::MatrixXd & C,
  395. const Eigen::MatrixXi & BE,
  396. const Eigen::VectorXi & P,
  397. const Eigen::VectorXi & RP)
  398. {
  399. using namespace Eigen;
  400. using namespace std;
  401. m_rotations_at_selection = m_rotations;
  402. m_translations_at_selection = m_translations;
  403. assert(BE.rows() == P.rows());
  404. m_selection = VectorXb::Zero(BE.rows());
  405. // m_rotation[e] is the relative rotation stored at bone e (as seen by the
  406. // joint traveling with its parent)
  407. // vQ[e] is the absolute rotation of a bone at rest to its current position:
  408. // vQ[e] = vQ[p(e)] * m_rotation[e]
  409. vector<Quaterniond,aligned_allocator<Quaterniond> > vQ;
  410. vector<Vector3d> vT;
  411. forward_kinematics(C,BE,P,m_rotations,m_translations,vQ,vT);
  412. // Loop over deformed bones
  413. for(int e = 0;e<BE.rows();e++)
  414. {
  415. Affine3d a = Affine3d::Identity();
  416. a.translate(vT[e]);
  417. a.rotate(vQ[e]);
  418. Vector3d s = a * (Vector3d)C.row(BE(e,0));
  419. Vector3d d = a * (Vector3d)C.row(BE(e,1));
  420. Vector3d projs = project(s);
  421. Vector3d projd = project(d);
  422. m_selection(e) = line_segment_in_rectangle(
  423. projs.head(2),projd.head(2),
  424. Vector2d(m_down_x,m_height-m_down_y),
  425. Vector2d(m_drag_x,m_height-m_drag_y));
  426. }
  427. return set_selection(m_selection,C,BE,P,RP);
  428. }
  429. inline void igl::opengl2::MouseController::set_selection(
  430. const Eigen::VectorXi & S,
  431. const Eigen::MatrixXd & C,
  432. const Eigen::MatrixXi & BE,
  433. const Eigen::VectorXi & P,
  434. const Eigen::VectorXi & RP)
  435. {
  436. using namespace Eigen;
  437. using namespace std;
  438. vector<Quaterniond,aligned_allocator<Quaterniond> > & vQ =
  439. m_fk_rotations_at_selection;
  440. vector<Vector3d> & vT = m_fk_translations_at_selection;
  441. forward_kinematics(C,BE,P,m_rotations,m_translations,vQ,vT);
  442. m_parent_rotations_at_selection.resize(
  443. m_rotations.size(),Quaterniond::Identity());
  444. for(size_t r = 0;r<vQ.size();r++)
  445. {
  446. if(P(r)>=0)
  447. {
  448. m_parent_rotations_at_selection[r] = vQ[P(r)];
  449. }
  450. }
  451. if(&m_selection != &S)
  452. {
  453. m_selection = S;
  454. }
  455. assert(m_selection.rows() == BE.rows());
  456. assert(BE.rows() == P.rows());
  457. assert(BE.rows() == RP.rows());
  458. // Zero-out S up a path of ones from e
  459. auto propagate = [&](const int e, const VectorXb & S, VectorXb & N)
  460. {
  461. if(S(e))
  462. {
  463. int f = e;
  464. while(true)
  465. {
  466. int p = P(f);
  467. if(p==-1||!S(p))
  468. {
  469. break;
  470. }
  471. N(f) = false;
  472. f = p;
  473. }
  474. }
  475. };
  476. VectorXb prev_selection = m_selection;
  477. // Combine upward, group rigid parts, repeat
  478. while(true)
  479. {
  480. // Spread selection across rigid pieces
  481. VectorXb SRP(VectorXb::Zero(RP.maxCoeff()+1));
  482. for(int e = 0;e<BE.rows();e++)
  483. {
  484. SRP(RP(e)) |= m_selection(e);
  485. }
  486. for(int e = 0;e<BE.rows();e++)
  487. {
  488. m_selection(e) = SRP(RP(e));
  489. }
  490. // Clear selections below m_selection ancestors
  491. VectorXb new_selection = m_selection;
  492. for(int e = 0;e<P.rows();e++)
  493. {
  494. propagate(e,m_selection,new_selection);
  495. }
  496. m_selection = new_selection;
  497. if(m_selection==prev_selection)
  498. {
  499. break;
  500. }
  501. prev_selection = m_selection;
  502. }
  503. // Now selection should contain just bone roots of m_selection subtrees
  504. if(m_selection.array().any())
  505. {
  506. // Taking average
  507. Vector3d avg_pos(0,0,0);
  508. //m_trans_widget_trans_at_selection.setConstant(0);
  509. m_widget_rot_at_selection.coeffs().setConstant(0);
  510. m_widget.rot.coeffs().array().setConstant(0);
  511. Quaterniond cur_rot(0,0,0,0);
  512. int num_selection = 0;
  513. // Compute average widget for selection
  514. for(int e = 0;e<BE.rows();e++)
  515. {
  516. if(m_selection(e))
  517. {
  518. Vector3d s = C.row(BE(e,0));
  519. Vector3d d = C.row(BE(e,1));
  520. auto b = (d-s).transpose().eval();
  521. {
  522. Affine3d a = Affine3d::Identity();
  523. a.translate(vT[e]);
  524. a.rotate(vQ[e]);
  525. avg_pos += a*s;
  526. }
  527. // Rotation of x axis to this bone
  528. Quaterniond rot_at_bind;
  529. rot_at_bind.setFromTwoVectors(Vector3d(1,0,0),b);
  530. const Quaterniond abs_rot = vQ[e] * rot_at_bind;
  531. m_widget_rot_at_selection.coeffs() += abs_rot.coeffs();
  532. //m_trans_widget_trans_at_selection += vT[e];
  533. num_selection++;
  534. }
  535. }
  536. // Take average
  537. avg_pos.array() /= (double)num_selection;
  538. //m_trans_widget_trans_at_selection.array() /= (double)num_selection;
  539. m_widget_rot_at_selection.coeffs().array() /= (double)num_selection;
  540. m_widget_rot_at_selection.normalize();
  541. m_widget.rot = m_widget_rot_at_selection;
  542. m_widget.pos = avg_pos;
  543. m_trans_widget.m_pos = avg_pos;
  544. //m_trans_widget.m_trans = m_trans_widget_trans_at_selection;
  545. m_trans_widget.m_trans.setConstant(0);
  546. }
  547. m_widget.m_is_enabled = true;
  548. m_trans_widget.m_is_enabled = true;
  549. for(int s = 0;s<m_selection.rows();s++)
  550. {
  551. // a root is selected then disable.
  552. if(!m_root_enabled && m_selection(s) && P(s) == -1)
  553. {
  554. m_widget.m_is_enabled = false;
  555. m_trans_widget.m_is_enabled = false;
  556. break;
  557. }
  558. }
  559. }
  560. inline void igl::opengl2::MouseController::set_size(const int n)
  561. {
  562. using namespace Eigen;
  563. clear_selection();
  564. m_rotations.clear();
  565. m_rotations.resize(n,Quaterniond::Identity());
  566. m_translations.clear();
  567. m_translations.resize(n,Vector3d(0,0,0));
  568. m_selection = VectorXb::Zero(n);
  569. }
  570. inline void igl::opengl2::MouseController::reset()
  571. {
  572. reset_rotations();
  573. reset_translations();
  574. }
  575. inline void igl::opengl2::MouseController::reset_selected()
  576. {
  577. reset_selected_rotations();
  578. reset_selected_translations();
  579. }
  580. inline void igl::opengl2::MouseController::reset_rotations()
  581. {
  582. using namespace Eigen;
  583. using namespace std;
  584. fill(m_rotations.begin(),m_rotations.end(),Quaterniond::Identity());
  585. // cop out. just clear selection
  586. clear_selection();
  587. }
  588. inline void igl::opengl2::MouseController::reset_selected_rotations()
  589. {
  590. using namespace Eigen;
  591. for(int e = 0;e<m_selection.size();e++)
  592. {
  593. if(m_selection(e))
  594. {
  595. m_rotations[e] = Quaterniond::Identity();
  596. }
  597. }
  598. }
  599. inline void igl::opengl2::MouseController::reset_translations()
  600. {
  601. using namespace Eigen;
  602. using namespace std;
  603. fill(m_translations.begin(),m_translations.end(),Vector3d(0,0,0));
  604. // cop out. just clear selection
  605. clear_selection();
  606. }
  607. inline void igl::opengl2::MouseController::reset_selected_translations()
  608. {
  609. using namespace Eigen;
  610. for(int e = 0;e<m_selection.size();e++)
  611. {
  612. if(m_selection(e))
  613. {
  614. m_translations[e] = Vector3d(0,0,0);
  615. }
  616. }
  617. }
  618. inline bool igl::opengl2::MouseController::set_rotations(const RotationList & vQ)
  619. {
  620. if(vQ.size() != m_rotations.size())
  621. {
  622. return false;
  623. }
  624. assert(!any_selection());
  625. m_rotations = vQ;
  626. return true;
  627. }
  628. inline bool igl::opengl2::MouseController::set_translations(const TranslationList & vT)
  629. {
  630. if(vT.size() != m_translations.size())
  631. {
  632. return false;
  633. }
  634. assert(!any_selection());
  635. m_translations = vT;
  636. return true;
  637. }
  638. inline void igl::opengl2::MouseController::clear_selection()
  639. {
  640. m_selection.setConstant(false);
  641. }
  642. inline bool igl::opengl2::MouseController::any_selection() const
  643. {
  644. return m_selection.array().any();
  645. }
  646. inline void igl::opengl2::MouseController::set_widget_mode(const WidgetMode & mode)
  647. {
  648. switch(m_widget_mode)
  649. {
  650. default:
  651. case WIDGET_MODE_TRANSLATE:
  652. m_widget.pos = m_trans_widget.m_pos+m_trans_widget.m_trans;
  653. break;
  654. case WIDGET_MODE_ROTATE:
  655. break;
  656. }
  657. m_widget_mode = mode;
  658. }
  659. #endif