MouseController.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. // Propogate 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 "../matlab_format.h"
  171. #include <iostream>
  172. #include <algorithm>
  173. #include <functional>
  174. inline void igl::opengl2::MouseController::propogate_to_descendants_if(
  175. const VectorXb & S,
  176. const Eigen::VectorXi & P,
  177. VectorXb & T)
  178. {
  179. using namespace std;
  180. const int n = S.rows();
  181. assert(P.rows() == n);
  182. // dynamic programming
  183. T = S;
  184. vector<bool> seen(n,false);
  185. // Recursively look up chain and see if ancestor is selected
  186. const function<bool(int)> look_up = [&](int e) -> bool
  187. {
  188. if(e==-1)
  189. {
  190. return false;
  191. }
  192. if(!seen[e])
  193. {
  194. seen[e] = true;
  195. T(e) |= look_up(P(e));
  196. }
  197. return T(e);
  198. };
  199. for(int e = 0;e<n;e++)
  200. {
  201. if(!seen[e])
  202. {
  203. T(e) = look_up(e);
  204. }
  205. }
  206. }
  207. inline void igl::opengl2::MouseController::color_if(
  208. const VectorXb & S,
  209. const Eigen::Vector4f & selected_color,
  210. const Eigen::Vector4f & unselected_color,
  211. Eigen::MatrixXf & C)
  212. {
  213. C.resize(S.rows(),4);
  214. for(int e=0;e<S.rows();e++)
  215. {
  216. C.row(e) = S(e)?selected_color:unselected_color;
  217. }
  218. }
  219. inline igl::opengl2::MouseController::MouseController():
  220. m_is_selecting(false),
  221. m_selection(),
  222. m_down_x(-1),m_down_y(-1),m_drag_x(-1),m_drag_y(-1),
  223. m_width(-1),m_height(-1),
  224. m_widget(),
  225. m_widget_rot_at_selection(),
  226. //m_trans_widget_trans_at_selection(),
  227. m_trans_widget(),
  228. m_rotations(),
  229. m_translations(),
  230. m_rotations_at_selection(),
  231. m_root_enabled(true),
  232. m_widget_mode(WIDGET_MODE_ROTATE)
  233. {
  234. }
  235. inline void igl::opengl2::MouseController::reshape(const int w, const int h)
  236. {
  237. m_width = w;
  238. m_height = h;
  239. }
  240. inline bool igl::opengl2::MouseController::down(const int x, const int y)
  241. {
  242. using namespace std;
  243. m_down_x = m_drag_x =x;
  244. m_down_y = m_drag_y =y;
  245. const bool widget_down = any_selection() &&
  246. (
  247. (m_widget_mode == WIDGET_MODE_ROTATE && m_widget.down(x,m_height-y)) ||
  248. (m_widget_mode == WIDGET_MODE_TRANSLATE &&
  249. m_trans_widget.down(x,m_height-y))
  250. );
  251. if(!widget_down)
  252. {
  253. m_is_selecting = true;
  254. }
  255. return m_is_selecting || widget_down;
  256. }
  257. inline bool igl::opengl2::MouseController::drag(const int x, const int y)
  258. {
  259. using namespace std;
  260. using namespace Eigen;
  261. m_drag_x = x;
  262. m_drag_y = y;
  263. if(m_is_selecting)
  264. {
  265. return m_is_selecting;
  266. }else
  267. {
  268. switch(m_widget_mode)
  269. {
  270. default: // fall through
  271. case WIDGET_MODE_ROTATE:
  272. {
  273. if(!m_widget.drag(x,m_height-y))
  274. {
  275. return false;
  276. }
  277. assert(any_selection());
  278. assert(m_selection.size() == (int)m_rotations.size());
  279. assert(m_selection.size() == (int)m_translations.size());
  280. for(int e = 0;e<m_selection.size();e++)
  281. {
  282. if(m_selection(e))
  283. {
  284. // Let:
  285. // w.θr = w.θ ⋅ w.θ₀*
  286. // w.θr takes (absolute) frame of w.θ₀ to w.θ:
  287. // w.θ = w.θr ⋅ w.θ₀
  288. // Define:
  289. // w.θ₀ = θfk ⋅ θx,
  290. // the absolute rotation of the x axis to the deformed bone at
  291. // selection. Likewise,
  292. // w.θ = θfk' ⋅ θx,
  293. // the current absolute rotation of the x axis to the deformed bone.
  294. // Define recursively:
  295. // θfk = θfk(p) ⋅ Θr,
  296. // then because we're only changeing this relative rotation
  297. // θfk' = θfk(p) ⋅ Θr ⋅ θr* ⋅ θr'
  298. // θfk' = θfk ⋅ θr* ⋅ θr'
  299. // w.θ ⋅ θx* = θfk ⋅ θr* ⋅ θr'
  300. // θr ⋅ θfk* ⋅ w.θ ⋅ θx* = θr'
  301. // θr ⋅ θfk* ⋅ w.θr ⋅ w.θ₀ ⋅ θx* = θr'
  302. // θr ⋅ θfk* ⋅ w.θr ⋅ θfk ⋅θx ⋅ θx* = θr'
  303. // θr ⋅ θfk* ⋅ w.θr ⋅ θfk = θr'
  304. // which I guess is the right multiply change after being changed to
  305. // the bases of θfk, the rotation of the bone relative to its rest
  306. // frame.
  307. //
  308. const Quaterniond & frame = m_fk_rotations_at_selection[e];
  309. m_rotations[e] =
  310. m_rotations_at_selection[e] *
  311. frame.conjugate() *
  312. (m_widget.rot*m_widget_rot_at_selection.conjugate()) *
  313. frame;
  314. }
  315. }
  316. }
  317. case WIDGET_MODE_TRANSLATE:
  318. {
  319. if(!m_trans_widget.drag(x,m_height-y))
  320. {
  321. return false;
  322. }
  323. assert(any_selection());
  324. assert(m_selection.size() == (int)m_rotations.size());
  325. assert(m_selection.size() == (int)m_translations.size());
  326. for(int e = 0;e<m_selection.size();e++)
  327. {
  328. if(m_selection(e))
  329. {
  330. m_translations[e] =
  331. m_translations_at_selection[e] +
  332. m_parent_rotations_at_selection[e].conjugate()*
  333. m_trans_widget.m_trans;
  334. }
  335. }
  336. }
  337. }
  338. return true;
  339. }
  340. }
  341. inline bool igl::opengl2::MouseController::up(const int x, const int y)
  342. {
  343. m_is_selecting = false;
  344. m_widget.up(x,m_height-y);
  345. m_trans_widget.up(x,m_height-y);
  346. return false;
  347. }
  348. inline void igl::opengl2::MouseController::draw() const
  349. {
  350. if(any_selection())
  351. {
  352. switch(m_widget_mode)
  353. {
  354. default:
  355. case WIDGET_MODE_ROTATE:
  356. m_widget.draw();
  357. break;
  358. case WIDGET_MODE_TRANSLATE:
  359. m_trans_widget.draw();
  360. break;
  361. }
  362. }
  363. if(m_is_selecting)
  364. {
  365. // Remember settings
  366. GLboolean dt;
  367. glGetBooleanv(GL_DEPTH_TEST,&dt);
  368. int old_vp[4];
  369. glGetIntegerv(GL_VIEWPORT,old_vp);
  370. // True screen space
  371. glViewport(0,0,m_width,m_height);
  372. glMatrixMode(GL_PROJECTION);
  373. glPushMatrix();
  374. glLoadIdentity();
  375. gluOrtho2D(0,m_width,0,m_height);
  376. glMatrixMode(GL_MODELVIEW);
  377. glPushMatrix();
  378. glLoadIdentity();
  379. glDisable(GL_DEPTH_TEST);
  380. draw_rectangular_marquee(
  381. m_down_x,
  382. m_height-m_down_y,
  383. m_drag_x,
  384. m_height-m_drag_y);
  385. // Restore settings
  386. glMatrixMode(GL_PROJECTION);
  387. glPopMatrix();
  388. glMatrixMode(GL_MODELVIEW);
  389. glPopMatrix();
  390. glViewport(old_vp[0],old_vp[1],old_vp[2],old_vp[3]);
  391. dt?glEnable(GL_DEPTH_TEST):glDisable(GL_DEPTH_TEST);
  392. }
  393. }
  394. inline void igl::opengl2::MouseController::set_selection_from_last_drag(
  395. const Eigen::MatrixXd & C,
  396. const Eigen::MatrixXi & BE,
  397. const Eigen::VectorXi & P,
  398. const Eigen::VectorXi & RP)
  399. {
  400. using namespace Eigen;
  401. using namespace std;
  402. m_rotations_at_selection = m_rotations;
  403. m_translations_at_selection = m_translations;
  404. assert(BE.rows() == P.rows());
  405. m_selection = VectorXb::Zero(BE.rows());
  406. // m_rotation[e] is the relative rotation stored at bone e (as seen by the
  407. // joint traveling with its parent)
  408. // vQ[e] is the absolute rotation of a bone at rest to its current position:
  409. // vQ[e] = vQ[p(e)] * m_rotation[e]
  410. vector<Quaterniond,aligned_allocator<Quaterniond> > vQ;
  411. vector<Vector3d> vT;
  412. forward_kinematics(C,BE,P,m_rotations,m_translations,vQ,vT);
  413. // Loop over deformed bones
  414. for(int e = 0;e<BE.rows();e++)
  415. {
  416. Affine3d a = Affine3d::Identity();
  417. a.translate(vT[e]);
  418. a.rotate(vQ[e]);
  419. Vector3d s = a * (Vector3d)C.row(BE(e,0));
  420. Vector3d d = a * (Vector3d)C.row(BE(e,1));
  421. Vector3d projs = project(s);
  422. Vector3d projd = project(d);
  423. m_selection(e) = line_segment_in_rectangle(
  424. projs.head(2),projd.head(2),
  425. Vector2d(m_down_x,m_height-m_down_y),
  426. Vector2d(m_drag_x,m_height-m_drag_y));
  427. }
  428. return set_selection(m_selection,C,BE,P,RP);
  429. }
  430. inline void igl::opengl2::MouseController::set_selection(
  431. const Eigen::VectorXi & S,
  432. const Eigen::MatrixXd & C,
  433. const Eigen::MatrixXi & BE,
  434. const Eigen::VectorXi & P,
  435. const Eigen::VectorXi & RP)
  436. {
  437. using namespace Eigen;
  438. using namespace std;
  439. vector<Quaterniond,aligned_allocator<Quaterniond> > & vQ =
  440. m_fk_rotations_at_selection;
  441. vector<Vector3d> & vT = m_fk_translations_at_selection;
  442. forward_kinematics(C,BE,P,m_rotations,m_translations,vQ,vT);
  443. m_parent_rotations_at_selection.resize(
  444. m_rotations.size(),Quaterniond::Identity());
  445. for(size_t r = 0;r<vQ.size();r++)
  446. {
  447. if(P(r)>=0)
  448. {
  449. m_parent_rotations_at_selection[r] = vQ[P(r)];
  450. }
  451. }
  452. if(&m_selection != &S)
  453. {
  454. m_selection = S;
  455. }
  456. assert(m_selection.rows() == BE.rows());
  457. assert(BE.rows() == P.rows());
  458. assert(BE.rows() == RP.rows());
  459. // Zero-out S up a path of ones from e
  460. auto propagate = [&](const int e, const VectorXb & S, VectorXb & N)
  461. {
  462. if(S(e))
  463. {
  464. int f = e;
  465. while(true)
  466. {
  467. int p = P(f);
  468. if(p==-1||!S(p))
  469. {
  470. break;
  471. }
  472. N(f) = false;
  473. f = p;
  474. }
  475. }
  476. };
  477. VectorXb prev_selection = m_selection;
  478. // Combine upward, group rigid parts, repeat
  479. while(true)
  480. {
  481. // Spread selection accross rigid pieces
  482. VectorXb SRP(VectorXb::Zero(RP.maxCoeff()+1));
  483. for(int e = 0;e<BE.rows();e++)
  484. {
  485. SRP(RP(e)) |= m_selection(e);
  486. }
  487. for(int e = 0;e<BE.rows();e++)
  488. {
  489. m_selection(e) = SRP(RP(e));
  490. }
  491. // Clear selections below m_selection ancestors
  492. VectorXb new_selection = m_selection;
  493. for(int e = 0;e<P.rows();e++)
  494. {
  495. propagate(e,m_selection,new_selection);
  496. }
  497. m_selection = new_selection;
  498. if(m_selection==prev_selection)
  499. {
  500. break;
  501. }
  502. prev_selection = m_selection;
  503. }
  504. // Now selection should contain just bone roots of m_selection subtrees
  505. if(m_selection.array().any())
  506. {
  507. // Taking average
  508. Vector3d avg_pos(0,0,0);
  509. //m_trans_widget_trans_at_selection.setConstant(0);
  510. m_widget_rot_at_selection.coeffs().setConstant(0);
  511. m_widget.rot.coeffs().array().setConstant(0);
  512. Quaterniond cur_rot(0,0,0,0);
  513. int num_selection = 0;
  514. // Compute average widget for selection
  515. for(int e = 0;e<BE.rows();e++)
  516. {
  517. if(m_selection(e))
  518. {
  519. Vector3d s = C.row(BE(e,0));
  520. Vector3d d = C.row(BE(e,1));
  521. auto b = (d-s).transpose().eval();
  522. {
  523. Affine3d a = Affine3d::Identity();
  524. a.translate(vT[e]);
  525. a.rotate(vQ[e]);
  526. avg_pos += a*s;
  527. }
  528. // Rotation of x axis to this bone
  529. Quaterniond rot_at_bind;
  530. rot_at_bind.setFromTwoVectors(Vector3d(1,0,0),b);
  531. const Quaterniond abs_rot = vQ[e] * rot_at_bind;
  532. m_widget_rot_at_selection.coeffs() += abs_rot.coeffs();
  533. //m_trans_widget_trans_at_selection += vT[e];
  534. num_selection++;
  535. }
  536. }
  537. // Take average
  538. avg_pos.array() /= (double)num_selection;
  539. //m_trans_widget_trans_at_selection.array() /= (double)num_selection;
  540. m_widget_rot_at_selection.coeffs().array() /= (double)num_selection;
  541. m_widget_rot_at_selection.normalize();
  542. m_widget.rot = m_widget_rot_at_selection;
  543. m_widget.pos = avg_pos;
  544. m_trans_widget.m_pos = avg_pos;
  545. //m_trans_widget.m_trans = m_trans_widget_trans_at_selection;
  546. m_trans_widget.m_trans.setConstant(0);
  547. }
  548. m_widget.m_is_enabled = true;
  549. m_trans_widget.m_is_enabled = true;
  550. for(int s = 0;s<m_selection.rows();s++)
  551. {
  552. // a root is selected then disable.
  553. if(!m_root_enabled && m_selection(s) && P(s) == -1)
  554. {
  555. m_widget.m_is_enabled = false;
  556. m_trans_widget.m_is_enabled = false;
  557. break;
  558. }
  559. }
  560. }
  561. inline void igl::opengl2::MouseController::set_size(const int n)
  562. {
  563. using namespace Eigen;
  564. clear_selection();
  565. m_rotations.clear();
  566. m_rotations.resize(n,Quaterniond::Identity());
  567. m_translations.clear();
  568. m_translations.resize(n,Vector3d(0,0,0));
  569. m_selection = VectorXb::Zero(n);
  570. }
  571. inline void igl::opengl2::MouseController::reset()
  572. {
  573. reset_rotations();
  574. reset_translations();
  575. }
  576. inline void igl::opengl2::MouseController::reset_selected()
  577. {
  578. reset_selected_rotations();
  579. reset_selected_translations();
  580. }
  581. inline void igl::opengl2::MouseController::reset_rotations()
  582. {
  583. using namespace Eigen;
  584. using namespace std;
  585. fill(m_rotations.begin(),m_rotations.end(),Quaterniond::Identity());
  586. // cop out. just clear selection
  587. clear_selection();
  588. }
  589. inline void igl::opengl2::MouseController::reset_selected_rotations()
  590. {
  591. using namespace Eigen;
  592. for(int e = 0;e<m_selection.size();e++)
  593. {
  594. if(m_selection(e))
  595. {
  596. m_rotations[e] = Quaterniond::Identity();
  597. }
  598. }
  599. }
  600. inline void igl::opengl2::MouseController::reset_translations()
  601. {
  602. using namespace Eigen;
  603. using namespace std;
  604. fill(m_translations.begin(),m_translations.end(),Vector3d(0,0,0));
  605. // cop out. just clear selection
  606. clear_selection();
  607. }
  608. inline void igl::opengl2::MouseController::reset_selected_translations()
  609. {
  610. using namespace Eigen;
  611. for(int e = 0;e<m_selection.size();e++)
  612. {
  613. if(m_selection(e))
  614. {
  615. m_translations[e] = Vector3d(0,0,0);
  616. }
  617. }
  618. }
  619. inline bool igl::opengl2::MouseController::set_rotations(const RotationList & vQ)
  620. {
  621. if(vQ.size() != m_rotations.size())
  622. {
  623. return false;
  624. }
  625. assert(!any_selection());
  626. m_rotations = vQ;
  627. return true;
  628. }
  629. inline bool igl::opengl2::MouseController::set_translations(const TranslationList & vT)
  630. {
  631. if(vT.size() != m_translations.size())
  632. {
  633. return false;
  634. }
  635. assert(!any_selection());
  636. m_translations = vT;
  637. return true;
  638. }
  639. inline void igl::opengl2::MouseController::clear_selection()
  640. {
  641. m_selection.setConstant(false);
  642. }
  643. inline bool igl::opengl2::MouseController::any_selection() const
  644. {
  645. return m_selection.array().any();
  646. }
  647. inline void igl::opengl2::MouseController::set_widget_mode(const WidgetMode & mode)
  648. {
  649. switch(m_widget_mode)
  650. {
  651. default:
  652. case WIDGET_MODE_TRANSLATE:
  653. m_widget.pos = m_trans_widget.m_pos+m_trans_widget.m_trans;
  654. break;
  655. case WIDGET_MODE_ROTATE:
  656. break;
  657. }
  658. m_widget_mode = mode;
  659. }
  660. #endif