example.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. // Small GLUT application to test different scene rotation paradigms
  2. //
  3. #include <igl/readOBJ.h>
  4. #include <igl/writeOBJ.h>
  5. #include <igl/writeOFF.h>
  6. #include <igl/readWRL.h>
  7. #include <igl/report_gl_error.h>
  8. #include <igl/triangulate.h>
  9. #include <igl/readOFF.h>
  10. #include <igl/readMESH.h>
  11. #include <igl/draw_mesh.h>
  12. #include <igl/draw_floor.h>
  13. #include <igl/pathinfo.h>
  14. #include <igl/list_to_matrix.h>
  15. #include <igl/quat_to_mat.h>
  16. #include <igl/per_face_normals.h>
  17. #include <igl/material_colors.h>
  18. #include <igl/trackball.h>
  19. #include <igl/snap_to_canonical_view_quat.h>
  20. #include <igl/REDRUM.h>
  21. #include <igl/Camera.h>
  22. #include <igl/ReAntTweakBar.h>
  23. #include <igl/get_seconds.h>
  24. #include <igl/jet.h>
  25. #include <igl/randperm.h>
  26. #include <igl/normalize_row_lengths.h>
  27. #include <igl/boost/components.h>
  28. #include <igl/boost/bfs_orient.h>
  29. #include <igl/orient_outward.h>
  30. #include <Eigen/Core>
  31. #include <Eigen/Geometry>
  32. #include <GLUT/glut.h>
  33. #include <ctime>
  34. #include <string>
  35. #include <vector>
  36. #include <stack>
  37. #include <iostream>
  38. Eigen::MatrixXd V;
  39. Eigen::VectorXd Vmid,Vmin,Vmax;
  40. double bbd = 1.0;
  41. Eigen::MatrixXi F;
  42. Eigen::VectorXi CC;
  43. struct State
  44. {
  45. igl::Camera camera;
  46. Eigen::MatrixXd N;
  47. Eigen::MatrixXd C;
  48. } s;
  49. // See README for descriptions
  50. enum RotationType
  51. {
  52. ROTATION_TYPE_IGL_TRACKBALL = 0,
  53. ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
  54. NUM_ROTATION_TYPES = 2,
  55. } rotation_type;
  56. std::stack<State> undo_stack;
  57. std::stack<State> redo_stack;
  58. bool wireframe_visible = false;
  59. bool fill_visible = true;
  60. bool is_rotating = false;
  61. int down_x,down_y;
  62. igl::Camera down_camera;
  63. bool is_animating = false;
  64. double animation_start_time = 0;
  65. double ANIMATION_DURATION = 0.5;
  66. Eigen::Quaterniond animation_from_quat;
  67. Eigen::Quaterniond animation_to_quat;
  68. int width,height;
  69. Eigen::Vector4f light_pos(-0.1,-0.1,0.9,0);
  70. #define REBAR_NAME "temp.rbr"
  71. igl::ReTwBar rebar;
  72. void push_undo()
  73. {
  74. undo_stack.push(s);
  75. // Clear
  76. redo_stack = std::stack<State>();
  77. }
  78. void TW_CALL set_camera_rotation(const void * value, void *clientData)
  79. {
  80. using namespace std;
  81. // case current value to double
  82. const double * quat = (const double *)(value);
  83. std::copy(quat,quat+4,s.camera.rotation);
  84. }
  85. void TW_CALL set_rotation_type(const void * value, void * clientData)
  86. {
  87. using namespace Eigen;
  88. using namespace std;
  89. using namespace igl;
  90. const RotationType old_rotation_type = rotation_type;
  91. rotation_type = *(const RotationType *)(value);
  92. if(rotation_type == ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP &&
  93. old_rotation_type != ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP)
  94. {
  95. push_undo();
  96. copy(s.camera.rotation,s.camera.rotation+4,animation_from_quat.coeffs().data());
  97. const Vector3d up = animation_from_quat.matrix() * Vector3d(0,1,0);
  98. Vector3d proj_up(0,up(1),up(2));
  99. if(proj_up.norm() == 0)
  100. {
  101. proj_up = Vector3d(0,1,0);
  102. }
  103. proj_up.normalize();
  104. Quaterniond dq;
  105. dq = Quaterniond::FromTwoVectors(up,proj_up);
  106. animation_to_quat = dq * animation_from_quat;
  107. // start animation
  108. animation_start_time = get_seconds();
  109. is_animating = true;
  110. }
  111. }
  112. void TW_CALL get_rotation_type(void * value, void *clientData)
  113. {
  114. RotationType * rt = (RotationType *)(value);
  115. *rt = rotation_type;
  116. }
  117. void TW_CALL get_camera_rotation(void * value, void *clientData)
  118. {
  119. using namespace std;
  120. // case current value to double
  121. double * quat = (double *)(value);
  122. std::copy(s.camera.rotation,s.camera.rotation+4,quat);
  123. }
  124. void reshape(int width, int height)
  125. {
  126. ::width = width;
  127. ::height = height;
  128. glViewport(0,0,width,height);
  129. // Send the new window size to AntTweakBar
  130. TwWindowSize(width, height);
  131. }
  132. void push_scene()
  133. {
  134. using namespace igl;
  135. using namespace std;
  136. const double angle = s.camera.angle;
  137. glMatrixMode(GL_PROJECTION);
  138. glPushMatrix();
  139. glLoadIdentity();
  140. double zNear = 1e-2;
  141. double zFar = 100;
  142. double aspect = ((double)width)/((double)height);
  143. // Amount of scaling needed to "fix" perspective z-shift
  144. double z_fix = 1.0;
  145. // 5 is far enough to see unit "things" well
  146. const double camera_z = 2;
  147. // Test if should be using true orthographic projection
  148. if(angle == 0)
  149. {
  150. glOrtho(
  151. -0.5*camera_z*aspect,
  152. 0.5*camera_z*aspect,
  153. -0.5*camera_z,
  154. 0.5*camera_z,
  155. zNear,
  156. zFar);
  157. }else
  158. {
  159. // Make sure aspect is sane
  160. aspect = aspect < 0.01 ? 0.01 : aspect;
  161. gluPerspective(angle,aspect,zNear,zFar);
  162. z_fix = 2.*tan(angle/2./360.*2.*M_PI);
  163. }
  164. glMatrixMode(GL_MODELVIEW);
  165. glPushMatrix();
  166. glLoadIdentity();
  167. gluLookAt(0,0,camera_z,0,0,0,0,1,0);
  168. // Adjust scale to correct perspective
  169. glScaled(z_fix,z_fix,z_fix);
  170. // scale, pan
  171. glScaled( s.camera.zoom, s.camera.zoom, s.camera.zoom);
  172. double mat[4*4];
  173. quat_to_mat(s.camera.rotation,mat);
  174. glMultMatrixd(mat);
  175. }
  176. void push_object()
  177. {
  178. using namespace igl;
  179. glPushMatrix();
  180. glScaled(2./bbd,2./bbd,2./bbd);
  181. glTranslated(-Vmid(0),-Vmid(1),-Vmid(2));
  182. }
  183. void pop_object()
  184. {
  185. glPopMatrix();
  186. }
  187. void pop_scene()
  188. {
  189. glMatrixMode(GL_PROJECTION);
  190. glPopMatrix();
  191. glMatrixMode(GL_MODELVIEW);
  192. glPopMatrix();
  193. }
  194. // Set up double-sided lights
  195. void lights()
  196. {
  197. using namespace std;
  198. using namespace Eigen;
  199. glEnable(GL_LIGHTING);
  200. //glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
  201. glEnable(GL_LIGHT0);
  202. float WHITE[4] = {1,1,1,1.};
  203. float GREY[4] = {0.4,0.4,0.4,1.};
  204. float BLACK[4] = {0.,0.,0.,1.};
  205. float NEAR_BLACK[4] = {0.1,0.1,0.1,1.};
  206. Vector4f pos = light_pos;
  207. glLightfv(GL_LIGHT0,GL_AMBIENT,BLACK);
  208. glLightfv(GL_LIGHT0,GL_DIFFUSE,WHITE);
  209. glLightfv(GL_LIGHT0,GL_SPECULAR,BLACK);
  210. glLightfv(GL_LIGHT0,GL_POSITION,pos.data());
  211. //glEnable(GL_LIGHT1);
  212. //pos(0) *= -1;
  213. //pos(1) *= -1;
  214. //pos(2) *= -1;
  215. //glLightfv(GL_LIGHT1,GL_AMBIENT,BLACK);
  216. //glLightfv(GL_LIGHT1,GL_DIFFUSE,NEAR_BLACK);
  217. //glLightfv(GL_LIGHT1,GL_SPECULAR,BLACK);
  218. //glLightfv(GL_LIGHT1,GL_POSITION,pos.data());
  219. }
  220. void display()
  221. {
  222. using namespace igl;
  223. using namespace std;
  224. using namespace Eigen;
  225. glClearColor(1,1,1,0);
  226. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  227. if(is_animating)
  228. {
  229. double t = (get_seconds() - animation_start_time)/ANIMATION_DURATION;
  230. if(t > 1)
  231. {
  232. t = 1;
  233. is_animating = false;
  234. }
  235. Quaterniond q;
  236. q.coeffs() =
  237. animation_to_quat.coeffs()*t + animation_from_quat.coeffs()*(1.-t);
  238. q.normalize();
  239. copy(q.coeffs().data(),q.coeffs().data()+4,s.camera.rotation);
  240. }
  241. glEnable(GL_DEPTH_TEST);
  242. glEnable(GL_NORMALIZE);
  243. lights();
  244. push_scene();
  245. push_object();
  246. // Set material properties
  247. glEnable(GL_COLOR_MATERIAL);
  248. glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
  249. if(wireframe_visible)
  250. {
  251. glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  252. if(fill_visible)
  253. {
  254. glColor3f(0,0,0);
  255. draw_mesh(V,F,s.N);
  256. }else
  257. {
  258. draw_mesh(V,F,s.N,s.C);
  259. }
  260. }
  261. glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  262. if(fill_visible)
  263. {
  264. glEnable(GL_POLYGON_OFFSET_FILL); // Avoid Stitching!
  265. glPolygonOffset(1.0, 0);
  266. draw_mesh(V,F,s.N,s.C);
  267. }
  268. pop_object();
  269. // Draw a nice floor
  270. glPushMatrix();
  271. const double floor_offset =
  272. -2./bbd*(V.col(1).maxCoeff()-Vmid(1));
  273. glTranslated(0,floor_offset,0);
  274. const float GREY[4] = {0.5,0.5,0.6,1.0};
  275. const float DARK_GREY[4] = {0.2,0.2,0.3,1.0};
  276. draw_floor(GREY,DARK_GREY);
  277. glPopMatrix();
  278. pop_scene();
  279. report_gl_error();
  280. TwDraw();
  281. glutSwapBuffers();
  282. glutPostRedisplay();
  283. }
  284. void mouse_wheel(int wheel, int direction, int mouse_x, int mouse_y)
  285. {
  286. using namespace std;
  287. if(wheel == 0)
  288. {
  289. static double mouse_scroll_y = 0;
  290. const double delta_y = 0.125*direction;
  291. mouse_scroll_y += delta_y;
  292. // absolute scale difference when changing zooms (+1)
  293. const double z_diff = 0.01;
  294. GLint viewport[4];
  295. glGetIntegerv(GL_VIEWPORT,viewport);
  296. if(TwMouseMotion(mouse_x, viewport[3] - mouse_y))
  297. {
  298. TwMouseWheel(mouse_scroll_y);
  299. }else
  300. {
  301. s.camera.zoom *= (1.0+double(direction)*z_diff);
  302. const double min_zoom = 0.01;
  303. const double max_zoom = 10.0;
  304. s.camera.zoom = min(max_zoom,max(min_zoom,s.camera.zoom));
  305. }
  306. }else
  307. {
  308. if(!is_rotating)
  309. {
  310. // Change viewing angle (reshape will take care of adjust zoom)
  311. const double a_diff = 1.0;
  312. s.camera.angle += double(direction)*a_diff;
  313. const double min_angle = 15.0;
  314. s.camera.angle =
  315. min(90.0,max(min_angle,s.camera.angle));
  316. }
  317. }
  318. }
  319. void mouse(int glutButton, int glutState, int mouse_x, int mouse_y)
  320. {
  321. using namespace std;
  322. using namespace Eigen;
  323. using namespace igl;
  324. bool tw_using = TwEventMouseButtonGLUT(glutButton,glutState,mouse_x,mouse_y);
  325. switch(glutButton)
  326. {
  327. case GLUT_RIGHT_BUTTON:
  328. case GLUT_LEFT_BUTTON:
  329. {
  330. switch(glutState)
  331. {
  332. case 1:
  333. // up
  334. glutSetCursor(GLUT_CURSOR_INHERIT);
  335. is_rotating = false;
  336. break;
  337. case 0:
  338. if(!tw_using)
  339. {
  340. push_undo();
  341. glutSetCursor(GLUT_CURSOR_CYCLE);
  342. // collect information for trackball
  343. is_rotating = true;
  344. down_camera = s.camera;
  345. down_x = mouse_x;
  346. down_y = mouse_y;
  347. }
  348. break;
  349. }
  350. break;
  351. // Scroll down
  352. case GLUT_WHEEL_DOWN:
  353. {
  354. mouse_wheel(0,-1,mouse_x,mouse_y);
  355. break;
  356. }
  357. // Scroll up
  358. case GLUT_WHEEL_UP:
  359. {
  360. mouse_wheel(0,1,mouse_x,mouse_y);
  361. break;
  362. }
  363. // Scroll left
  364. case GLUT_WHEEL_LEFT:
  365. {
  366. mouse_wheel(1,-1,mouse_x,mouse_y);
  367. break;
  368. }
  369. // Scroll right
  370. case GLUT_WHEEL_RIGHT:
  371. {
  372. mouse_wheel(1,1,mouse_x,mouse_y);
  373. break;
  374. }
  375. }
  376. }
  377. }
  378. void mouse_drag(int mouse_x, int mouse_y)
  379. {
  380. using namespace igl;
  381. using namespace std;
  382. using namespace Eigen;
  383. bool tw_using = TwMouseMotion(mouse_x,mouse_y);
  384. if(is_rotating)
  385. {
  386. glutSetCursor(GLUT_CURSOR_CYCLE);
  387. switch(rotation_type)
  388. {
  389. case ROTATION_TYPE_IGL_TRACKBALL:
  390. {
  391. // Rotate according to trackball
  392. igl::trackball<double>(
  393. width,
  394. height,
  395. 2.0,
  396. down_camera.rotation,
  397. down_x,
  398. down_y,
  399. mouse_x,
  400. mouse_y,
  401. s.camera.rotation);
  402. break;
  403. }
  404. case ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP:
  405. {
  406. Quaterniond down_q;
  407. copy(down_camera.rotation,down_camera.rotation+4,down_q.coeffs().data());
  408. Vector3d axis(0,1,0);
  409. const double speed = 2.0;
  410. Quaterniond q;
  411. q = down_q *
  412. Quaterniond(
  413. AngleAxisd(
  414. M_PI*((double)(mouse_x-down_x))/(double)width*speed/2.0,
  415. axis.normalized()));
  416. q.normalize();
  417. {
  418. Vector3d axis(1,0,0);
  419. const double speed = 2.0;
  420. if(axis.norm() != 0)
  421. {
  422. q =
  423. Quaterniond(
  424. AngleAxisd(
  425. M_PI*(mouse_y-down_y)/(double)width*speed/2.0,
  426. axis.normalized())) * q;
  427. q.normalize();
  428. }
  429. }
  430. copy(q.coeffs().data(),q.coeffs().data()+4,s.camera.rotation);
  431. break;
  432. }
  433. default:
  434. break;
  435. }
  436. }
  437. }
  438. void init_relative()
  439. {
  440. using namespace Eigen;
  441. using namespace igl;
  442. per_face_normals(V,F,s.N);
  443. normalize_row_lengths(s.N,s.N);
  444. Vmax = V.colwise().maxCoeff();
  445. Vmin = V.colwise().minCoeff();
  446. Vmid = 0.5*(Vmax + Vmin);
  447. bbd = (Vmax-Vmin).norm();
  448. }
  449. void randomly_color(
  450. const Eigen::VectorXi & CC,
  451. Eigen::MatrixXd & C)
  452. {
  453. using namespace Eigen;
  454. using namespace igl;
  455. using namespace std;
  456. VectorXi I;
  457. srand ( unsigned ( time(0) ) );
  458. double num_cc = (double)CC.maxCoeff()+1.0;
  459. randperm(num_cc,I);
  460. C.resize(CC.rows(),3);
  461. for(int f = 0;f<CC.rows();f++)
  462. {
  463. jet(
  464. (double)I(CC(f))/num_cc,
  465. C(f,0),
  466. C(f,1),
  467. C(f,2));
  468. }
  469. }
  470. void randomize_colors(void * /*clientData*/)
  471. {
  472. push_undo();
  473. randomly_color(CC,s.C);
  474. }
  475. void init_patches()
  476. {
  477. using namespace Eigen;
  478. using namespace igl;
  479. using namespace std;
  480. {
  481. VectorXi VCC;
  482. components(F,VCC);
  483. cout<<"There are "<<VCC.maxCoeff()+1<<" connected components of vertices."<<endl;
  484. }
  485. bfs_orient(F,F,CC);
  486. VectorXi I;
  487. orient_outward(V,F,CC,F,I);
  488. double num_cc = (double)CC.maxCoeff()+1.0;
  489. cout<<"There are "<<num_cc<<" 'manifold/orientable' patches of faces."<<endl;
  490. randomly_color(CC,s.C);
  491. }
  492. void undo()
  493. {
  494. using namespace std;
  495. if(!undo_stack.empty())
  496. {
  497. redo_stack.push(s);
  498. s = undo_stack.top();
  499. undo_stack.pop();
  500. }
  501. }
  502. void redo()
  503. {
  504. using namespace std;
  505. if(!redo_stack.empty())
  506. {
  507. undo_stack.push(s);
  508. s = redo_stack.top();
  509. redo_stack.pop();
  510. }
  511. }
  512. void key(unsigned char key, int mouse_x, int mouse_y)
  513. {
  514. using namespace std;
  515. int mod = glutGetModifiers();
  516. switch(key)
  517. {
  518. // ESC
  519. case char(27):
  520. rebar.save(REBAR_NAME);
  521. // ^C
  522. case char(3):
  523. exit(0);
  524. case 'I':
  525. case 'i':
  526. {
  527. push_undo();
  528. s.N *= -1.0;
  529. break;
  530. }
  531. case 'z':
  532. case 'Z':
  533. if(mod & GLUT_ACTIVE_COMMAND)
  534. {
  535. if(mod & GLUT_ACTIVE_SHIFT)
  536. {
  537. redo();
  538. }else
  539. {
  540. undo();
  541. }
  542. break;
  543. }else
  544. {
  545. push_undo();
  546. igl::snap_to_canonical_view_quat<double>(
  547. s.camera.rotation,
  548. 1.0,
  549. s.camera.rotation);
  550. break;
  551. }
  552. default:
  553. if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
  554. {
  555. cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
  556. }
  557. }
  558. }
  559. int main(int argc, char * argv[])
  560. {
  561. using namespace std;
  562. using namespace Eigen;
  563. using namespace igl;
  564. string filename = "../shared/truck.obj";
  565. if(argc < 2)
  566. {
  567. cerr<<"Usage:"<<endl<<" ./example input.obj"<<endl;
  568. cout<<endl<<"Opening default mesh..."<<endl;
  569. }else
  570. {
  571. // Read and prepare mesh
  572. filename = argv[1];
  573. }
  574. // print key commands
  575. cout<<"[Click] and [drag] Rotate model using trackball."<<endl;
  576. cout<<"[Z,z] Snap rotation to canonical view."<<endl;
  577. cout<<"[⌘ Z] Undo."<<endl;
  578. cout<<"[⇧ ⌘ Z] Redo."<<endl;
  579. cout<<"[^C,ESC] Exit."<<endl;
  580. // dirname, basename, extension and filename
  581. string d,b,ext,f;
  582. pathinfo(filename,d,b,ext,f);
  583. // Convert extension to lower case
  584. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  585. vector<vector<double > > vV,vN,vTC;
  586. vector<vector<int > > vF,vFTC,vFN;
  587. if(ext == "obj")
  588. {
  589. // Convert extension to lower case
  590. if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN))
  591. {
  592. return 1;
  593. }
  594. }else if(ext == "off")
  595. {
  596. // Convert extension to lower case
  597. if(!igl::readOFF(filename,vV,vF,vN))
  598. {
  599. return 1;
  600. }
  601. }else if(ext == "wrl")
  602. {
  603. // Convert extension to lower case
  604. if(!igl::readWRL(filename,vV,vF))
  605. {
  606. return 1;
  607. }
  608. //}else
  609. //{
  610. // // Convert extension to lower case
  611. // MatrixXi T;
  612. // if(!igl::readMESH(filename,V,T,F))
  613. // {
  614. // return 1;
  615. // }
  616. // //if(F.size() > T.size() || F.size() == 0)
  617. // {
  618. // boundary_faces(T,F);
  619. // }
  620. }
  621. if(vV.size() > 0)
  622. {
  623. if(!list_to_matrix(vV,V))
  624. {
  625. return 1;
  626. }
  627. triangulate(vF,F);
  628. }
  629. init_patches();
  630. init_relative();
  631. // Init glut
  632. glutInit(&argc,argv);
  633. if( !TwInit(TW_OPENGL, NULL) )
  634. {
  635. // A fatal error occured
  636. fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
  637. return 1;
  638. }
  639. // Create a tweak bar
  640. rebar.TwNewBar("TweakBar");
  641. rebar.TwAddVarCB("camera_rotation", TW_TYPE_QUAT4D, set_camera_rotation,get_camera_rotation, NULL, "open readonly=true");
  642. TwEnumVal RotationTypesEV[NUM_ROTATION_TYPES] =
  643. {
  644. {ROTATION_TYPE_IGL_TRACKBALL,"igl trackball"},
  645. {ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP,"two axis fixed up"}
  646. };
  647. TwType RotationTypeTW =
  648. ReTwDefineEnum(
  649. "RotationType",
  650. RotationTypesEV,
  651. NUM_ROTATION_TYPES);
  652. rebar.TwAddVarCB( "rotation_type", RotationTypeTW,
  653. set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=[");
  654. rebar.TwAddVarRW("wireframe_visible",TW_TYPE_BOOLCPP,&wireframe_visible,"key=l");
  655. rebar.TwAddVarRW("fill_visible",TW_TYPE_BOOLCPP,&fill_visible,"key=f");
  656. rebar.TwAddButton("randomize colors",randomize_colors,NULL,"key=c");
  657. rebar.load(REBAR_NAME);
  658. animation_from_quat = Quaterniond(1,0,0,0);
  659. copy(s.camera.rotation,s.camera.rotation+4,animation_to_quat.coeffs().data());
  660. animation_start_time = get_seconds();
  661. // Init antweakbar
  662. glutInitDisplayString( "rgba depth double samples>=8 ");
  663. glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0);
  664. glutCreateWindow("patches");
  665. glutDisplayFunc(display);
  666. glutReshapeFunc(reshape);
  667. glutKeyboardFunc(key);
  668. glutMouseFunc(mouse);
  669. glutMotionFunc(mouse_drag);
  670. glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
  671. glutMainLoop();
  672. return 0;
  673. }