example.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. #include <igl/draw_skeleton_3d.h>
  2. #include <igl/draw_skeleton_vector_graphics.h>
  3. #include <igl/two_axis_valuator_fixed_up.h>
  4. #include <igl/readOBJ.h>
  5. #include <igl/readTGF.h>
  6. #include <igl/writeOBJ.h>
  7. #include <igl/writeOFF.h>
  8. #include <igl/readWRL.h>
  9. #include <igl/report_gl_error.h>
  10. #include <igl/polygon_mesh_to_triangle_mesh.h>
  11. #include <igl/readOFF.h>
  12. #include <igl/readMESH.h>
  13. #include <igl/draw_mesh.h>
  14. #include <igl/draw_floor.h>
  15. #include <igl/pathinfo.h>
  16. #include <igl/list_to_matrix.h>
  17. #include <igl/quat_to_mat.h>
  18. #include <igl/per_face_normals.h>
  19. #include <igl/material_colors.h>
  20. #include <igl/trackball.h>
  21. #include <igl/snap_to_canonical_view_quat.h>
  22. #include <igl/snap_to_fixed_up.h>
  23. #include <igl/REDRUM.h>
  24. #include <igl/Camera.h>
  25. #include <igl/ReAntTweakBar.h>
  26. #include <igl/get_seconds.h>
  27. #include <igl/forward_kinematics.h>
  28. #include <igl/tetgen/mesh_with_skeleton.h>
  29. #include <igl/boundary_conditions.h>
  30. #include <igl/normalize_row_sums.h>
  31. #include <igl/lbs_matrix.h>
  32. #include <igl/bbw/bbw.h>
  33. #include <Eigen/Core>
  34. #include <Eigen/Geometry>
  35. #ifdef __APPLE__
  36. #include <GLUT/glut.h>
  37. #include <Carbon/Carbon.h>
  38. #else
  39. #include <GL/glut.h>
  40. #endif
  41. #include <string>
  42. #include <vector>
  43. #include <stack>
  44. #include <iostream>
  45. enum SkelStyleType
  46. {
  47. SKEL_STYLE_TYPE_3D = 0,
  48. SKEL_STYLE_TYPE_VECTOR_GRAPHICS = 1,
  49. NUM_SKEL_STYLE_TYPE = 2
  50. }skel_style;
  51. Eigen::MatrixXd V,N,C,W,M;
  52. Eigen::VectorXd Vmid,Vmin,Vmax;
  53. double bbd = 1.0;
  54. Eigen::MatrixXi F,BE;
  55. Eigen::VectorXi P;
  56. struct State
  57. {
  58. igl::Camera camera;
  59. } s;
  60. bool wireframe = false;
  61. bool skeleton_on_top = false;
  62. // See README for descriptions
  63. enum RotationType
  64. {
  65. ROTATION_TYPE_IGL_TRACKBALL = 0,
  66. ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
  67. NUM_ROTATION_TYPES = 2,
  68. } rotation_type;
  69. std::stack<State> undo_stack;
  70. std::stack<State> redo_stack;
  71. bool is_rotating = false;
  72. int down_x,down_y;
  73. igl::Camera down_camera;
  74. bool is_animating = false;
  75. double animation_start_time = 0;
  76. double ANIMATION_DURATION = 0.5;
  77. Eigen::Quaterniond animation_from_quat;
  78. Eigen::Quaterniond animation_to_quat;
  79. int width,height;
  80. Eigen::Vector4f light_pos(-0.1,-0.1,0.9,0);
  81. #define REBAR_NAME "temp.rbr"
  82. igl::ReTwBar rebar;
  83. void push_undo()
  84. {
  85. undo_stack.push(s);
  86. // Clear
  87. redo_stack = std::stack<State>();
  88. }
  89. // No-op setter, does nothing
  90. void TW_CALL no_op(const void * /*value*/, void * /*clientData*/)
  91. {
  92. }
  93. void TW_CALL set_rotation_type(const void * value, void * clientData)
  94. {
  95. using namespace Eigen;
  96. using namespace std;
  97. using namespace igl;
  98. const RotationType old_rotation_type = rotation_type;
  99. rotation_type = *(const RotationType *)(value);
  100. if(rotation_type == ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP &&
  101. old_rotation_type != ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP)
  102. {
  103. push_undo();
  104. animation_from_quat = s.camera.m_rotation_conj;
  105. snap_to_fixed_up(animation_from_quat,animation_to_quat);
  106. // start animation
  107. animation_start_time = get_seconds();
  108. is_animating = true;
  109. }
  110. }
  111. void TW_CALL get_rotation_type(void * value, void *clientData)
  112. {
  113. RotationType * rt = (RotationType *)(value);
  114. *rt = rotation_type;
  115. }
  116. void reshape(int width, int height)
  117. {
  118. ::width = width;
  119. ::height = height;
  120. glViewport(0,0,width,height);
  121. // Send the new window size to AntTweakBar
  122. TwWindowSize(width, height);
  123. s.camera.m_aspect = (double)width/(double)height;
  124. }
  125. void push_scene()
  126. {
  127. using namespace igl;
  128. using namespace std;
  129. glMatrixMode(GL_PROJECTION);
  130. glPushMatrix();
  131. glLoadIdentity();
  132. auto & camera = s.camera;
  133. gluPerspective(camera.m_angle,camera.m_aspect,camera.m_near,camera.m_far);
  134. glMatrixMode(GL_MODELVIEW);
  135. glPushMatrix();
  136. glLoadIdentity();
  137. gluLookAt(
  138. camera.eye()(0), camera.eye()(1), camera.eye()(2),
  139. camera.at()(0), camera.at()(1), camera.at()(2),
  140. camera.up()(0), camera.up()(1), camera.up()(2));
  141. }
  142. void push_object()
  143. {
  144. using namespace igl;
  145. glPushMatrix();
  146. glScaled(2./bbd,2./bbd,2./bbd);
  147. glTranslated(-Vmid(0),-Vmid(1),-Vmid(2));
  148. }
  149. void pop_object()
  150. {
  151. glPopMatrix();
  152. }
  153. void pop_scene()
  154. {
  155. glMatrixMode(GL_PROJECTION);
  156. glPopMatrix();
  157. glMatrixMode(GL_MODELVIEW);
  158. glPopMatrix();
  159. }
  160. // Set up double-sided lights
  161. void lights()
  162. {
  163. using namespace std;
  164. using namespace Eigen;
  165. glEnable(GL_LIGHTING);
  166. glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
  167. glEnable(GL_LIGHT0);
  168. glEnable(GL_LIGHT1);
  169. float WHITE[4] = {0.8,0.8,0.8,1.};
  170. float GREY[4] = {0.4,0.4,0.4,1.};
  171. float BLACK[4] = {0.,0.,0.,1.};
  172. Vector4f pos = light_pos;
  173. glLightfv(GL_LIGHT0,GL_AMBIENT,GREY);
  174. glLightfv(GL_LIGHT0,GL_DIFFUSE,WHITE);
  175. glLightfv(GL_LIGHT0,GL_SPECULAR,BLACK);
  176. glLightfv(GL_LIGHT0,GL_POSITION,pos.data());
  177. pos(0) *= -1;
  178. pos(1) *= -1;
  179. pos(2) *= -1;
  180. glLightfv(GL_LIGHT1,GL_AMBIENT,GREY);
  181. glLightfv(GL_LIGHT1,GL_DIFFUSE,WHITE);
  182. glLightfv(GL_LIGHT1,GL_SPECULAR,BLACK);
  183. glLightfv(GL_LIGHT1,GL_POSITION,pos.data());
  184. }
  185. void display()
  186. {
  187. using namespace igl;
  188. using namespace std;
  189. using namespace Eigen;
  190. const float back[4] = {30.0/255.0,30.0/255.0,50.0/255.0,0};
  191. glClearColor(back[0],back[1],back[2],0);
  192. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  193. if(is_animating)
  194. {
  195. double t = (get_seconds() - animation_start_time)/ANIMATION_DURATION;
  196. if(t > 1)
  197. {
  198. t = 1;
  199. is_animating = false;
  200. }
  201. Quaterniond q = animation_from_quat.slerp(t,animation_to_quat).normalized();
  202. auto & camera = s.camera;
  203. camera.orbit(q.conjugate());
  204. }
  205. glEnable(GL_DEPTH_TEST);
  206. glEnable(GL_NORMALIZE);
  207. lights();
  208. push_scene();
  209. // Draw a nice floor
  210. glEnable(GL_DEPTH_TEST);
  211. glPushMatrix();
  212. const double floor_offset =
  213. -2./bbd*(V.col(1).maxCoeff()-Vmid(1));
  214. glTranslated(0,floor_offset,0);
  215. const float GREY[4] = {0.5,0.5,0.6,1.0};
  216. const float DARK_GREY[4] = {0.2,0.2,0.3,1.0};
  217. glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  218. draw_floor(GREY,DARK_GREY);
  219. glPopMatrix();
  220. push_object();
  221. // Set material properties
  222. glDisable(GL_COLOR_MATERIAL);
  223. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, SILVER_AMBIENT);
  224. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, SILVER_DIFFUSE );
  225. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SILVER_SPECULAR);
  226. glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128);
  227. typedef std::vector<
  228. Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> >
  229. RotationList;
  230. RotationList dQ(BE.rows(),Quaterniond::Identity()),vQ;
  231. vector<Vector3d> vT;
  232. Matrix3d A = Matrix3d::Identity();
  233. for(int e = 0;e<BE.rows();e++)
  234. {
  235. dQ[e] = AngleAxisd((sin(get_seconds()+e))*0.06*PI,A.col(e%3));
  236. }
  237. forward_kinematics(C,BE,P,dQ,vQ,vT);
  238. const int dim = C.cols();
  239. MatrixXd T(BE.rows()*(dim+1),dim);
  240. for(int e = 0;e<BE.rows();e++)
  241. {
  242. Affine3d a = Affine3d::Identity();
  243. a.translate(vT[e]);
  244. a.rotate(vQ[e]);
  245. T.block(e*(dim+1),0,dim+1,dim) =
  246. a.matrix().transpose().block(0,0,dim+1,dim);
  247. }
  248. if(wireframe)
  249. {
  250. glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  251. }
  252. glLineWidth(1.0);
  253. MatrixXd U = M*T;
  254. per_face_normals(U,F,N);
  255. draw_mesh(U,F,N);
  256. glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  257. if(skeleton_on_top)
  258. {
  259. glDisable(GL_DEPTH_TEST);
  260. }
  261. switch(skel_style)
  262. {
  263. default:
  264. case SKEL_STYLE_TYPE_3D:
  265. draw_skeleton_3d(C,BE,T);
  266. break;
  267. case SKEL_STYLE_TYPE_VECTOR_GRAPHICS:
  268. draw_skeleton_vector_graphics(C,BE,T);
  269. break;
  270. }
  271. pop_object();
  272. pop_scene();
  273. report_gl_error();
  274. TwDraw();
  275. glutSwapBuffers();
  276. glutPostRedisplay();
  277. }
  278. void mouse_wheel(int wheel, int direction, int mouse_x, int mouse_y)
  279. {
  280. using namespace std;
  281. using namespace igl;
  282. using namespace Eigen;
  283. GLint viewport[4];
  284. glGetIntegerv(GL_VIEWPORT,viewport);
  285. if(wheel == 0 && TwMouseMotion(mouse_x, viewport[3] - mouse_y))
  286. {
  287. static double mouse_scroll_y = 0;
  288. const double delta_y = 0.125*direction;
  289. mouse_scroll_y += delta_y;
  290. TwMouseWheel(mouse_scroll_y);
  291. return;
  292. }
  293. push_undo();
  294. auto & camera = s.camera;
  295. if(wheel==0)
  296. {
  297. // factor of zoom change
  298. double s = (1.-0.01*direction);
  299. //// FOV zoom: just widen angle. This is hardly ever appropriate.
  300. //camera.m_angle *= s;
  301. //camera.m_angle = min(max(camera.m_angle,1),89);
  302. camera.push_away(s);
  303. }else
  304. {
  305. // Dolly zoom:
  306. camera.dolly_zoom((double)direction*1.0);
  307. }
  308. }
  309. void mouse(int glutButton, int glutState, int mouse_x, int mouse_y)
  310. {
  311. using namespace std;
  312. using namespace Eigen;
  313. using namespace igl;
  314. bool tw_using = TwEventMouseButtonGLUT(glutButton,glutState,mouse_x,mouse_y);
  315. switch(glutButton)
  316. {
  317. case GLUT_RIGHT_BUTTON:
  318. case GLUT_LEFT_BUTTON:
  319. {
  320. switch(glutState)
  321. {
  322. case 1:
  323. // up
  324. glutSetCursor(GLUT_CURSOR_INHERIT);
  325. is_rotating = false;
  326. break;
  327. case 0:
  328. if(!tw_using)
  329. {
  330. push_undo();
  331. glutSetCursor(GLUT_CURSOR_CYCLE);
  332. // collect information for trackball
  333. is_rotating = true;
  334. down_camera = s.camera;
  335. down_x = mouse_x;
  336. down_y = mouse_y;
  337. }
  338. break;
  339. }
  340. break;
  341. }
  342. // Scroll down
  343. case 3:
  344. {
  345. mouse_wheel(0,-1,mouse_x,mouse_y);
  346. break;
  347. }
  348. // Scroll up
  349. case 4:
  350. {
  351. mouse_wheel(0,1,mouse_x,mouse_y);
  352. break;
  353. }
  354. // Scroll left
  355. case 5:
  356. {
  357. mouse_wheel(1,-1,mouse_x,mouse_y);
  358. break;
  359. }
  360. // Scroll right
  361. case 6:
  362. {
  363. mouse_wheel(1,1,mouse_x,mouse_y);
  364. break;
  365. }
  366. }
  367. }
  368. void mouse_drag(int mouse_x, int mouse_y)
  369. {
  370. using namespace igl;
  371. using namespace std;
  372. using namespace Eigen;
  373. if(is_rotating)
  374. {
  375. glutSetCursor(GLUT_CURSOR_CYCLE);
  376. Quaterniond q;
  377. auto & camera = s.camera;
  378. switch(rotation_type)
  379. {
  380. case ROTATION_TYPE_IGL_TRACKBALL:
  381. {
  382. // Rotate according to trackball
  383. igl::trackball<double>(
  384. width,
  385. height,
  386. 2.0,
  387. down_camera.m_rotation_conj.coeffs().data(),
  388. down_x,
  389. down_y,
  390. mouse_x,
  391. mouse_y,
  392. q.coeffs().data());
  393. break;
  394. }
  395. case ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP:
  396. {
  397. // Rotate according to two axis valuator with fixed up vector
  398. two_axis_valuator_fixed_up(
  399. width, height,
  400. 2.0,
  401. down_camera.m_rotation_conj,
  402. down_x, down_y, mouse_x, mouse_y,
  403. q);
  404. break;
  405. }
  406. default:
  407. break;
  408. }
  409. camera.orbit(q.conjugate());
  410. }
  411. }
  412. void init_relative()
  413. {
  414. using namespace Eigen;
  415. using namespace igl;
  416. per_face_normals(V,F,N);
  417. Vmax = V.colwise().maxCoeff();
  418. Vmin = V.colwise().minCoeff();
  419. Vmid = 0.5*(Vmax + Vmin);
  420. bbd = (Vmax-Vmin).norm();
  421. }
  422. void undo()
  423. {
  424. using namespace std;
  425. if(!undo_stack.empty())
  426. {
  427. redo_stack.push(s);
  428. s = undo_stack.top();
  429. undo_stack.pop();
  430. }
  431. }
  432. void redo()
  433. {
  434. using namespace std;
  435. if(!redo_stack.empty())
  436. {
  437. undo_stack.push(s);
  438. s = redo_stack.top();
  439. redo_stack.pop();
  440. }
  441. }
  442. void key(unsigned char key, int mouse_x, int mouse_y)
  443. {
  444. using namespace std;
  445. using namespace igl;
  446. using namespace Eigen;
  447. int mod = glutGetModifiers();
  448. const bool command_down = GLUT_ACTIVE_COMMAND & mod;
  449. const bool shift_down = GLUT_ACTIVE_SHIFT & mod;
  450. switch(key)
  451. {
  452. // ESC
  453. case char(27):
  454. rebar.save(REBAR_NAME);
  455. // ^C
  456. case char(3):
  457. exit(0);
  458. case 'z':
  459. case 'Z':
  460. if(command_down)
  461. {
  462. if(shift_down)
  463. {
  464. redo();
  465. }else
  466. {
  467. undo();
  468. }
  469. break;
  470. }else
  471. {
  472. push_undo();
  473. Quaterniond q;
  474. snap_to_canonical_view_quat(s.camera.m_rotation_conj,1.0,q);
  475. s.camera.orbit(q.conjugate());
  476. }
  477. default:
  478. if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
  479. {
  480. cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
  481. }
  482. }
  483. }
  484. bool init_weights(
  485. const Eigen::MatrixXd & V,
  486. const Eigen::MatrixXi & F,
  487. const Eigen::MatrixXd & C,
  488. const Eigen::MatrixXi & BE,
  489. Eigen::MatrixXd & W)
  490. {
  491. using namespace igl;
  492. using namespace Eigen;
  493. // Mesh with samples on skeleton
  494. // New vertices of tet mesh, V prefaces VV
  495. MatrixXd VV;
  496. MatrixXi TT,FF,CE;
  497. VectorXi P;
  498. if(!mesh_with_skeleton(V,F,C,P,BE,CE,10,VV,TT,FF))
  499. {
  500. return false;
  501. }
  502. // List of boundary indices (aka fixed value indices into VV)
  503. VectorXi b;
  504. // List of boundary conditions of each weight function
  505. MatrixXd bc;
  506. if(!boundary_conditions(VV,TT,C,P,BE,CE,b,bc))
  507. {
  508. return false;
  509. }
  510. // compute BBW
  511. // Default bbw data and flags
  512. BBWData bbw_data;
  513. bbw_data.active_set_params.max_iter = 4;
  514. // Weights matrix
  515. if(!bbw(VV,TT,b,bc,bbw_data,W))
  516. {
  517. return false;
  518. }
  519. // Normalize weights to sum to one
  520. normalize_row_sums(W,W);
  521. W.conservativeResize(V.rows(),W.cols());
  522. return true;
  523. }
  524. int main(int argc, char * argv[])
  525. {
  526. using namespace std;
  527. using namespace Eigen;
  528. using namespace igl;
  529. string filename = "../shared/cheburashka.off";
  530. string skel_filename = "../shared/cheburashka.tgf";
  531. if(argc < 3)
  532. {
  533. cerr<<"Usage:"<<endl<<" ./example input.obj"<<endl;
  534. cout<<endl<<"Opening default mesh..."<<endl;
  535. }else
  536. {
  537. // Read and prepare mesh
  538. filename = argv[1];
  539. skel_filename = argv[2];
  540. }
  541. // print key commands
  542. cout<<"[Click] and [drag] Rotate model using trackball."<<endl;
  543. cout<<"[Z,z] Snap rotation to canonical view."<<endl;
  544. cout<<"[⌘ Z] Undo."<<endl;
  545. cout<<"[⇧ ⌘ Z] Redo."<<endl;
  546. cout<<"[^C,ESC] Exit."<<endl;
  547. // dirname, basename, extension and filename
  548. string d,b,ext,f;
  549. pathinfo(filename,d,b,ext,f);
  550. // Convert extension to lower case
  551. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  552. vector<vector<double > > vV,vN,vTC;
  553. vector<vector<int > > vF,vFTC,vFN;
  554. if(ext == "obj")
  555. {
  556. // Convert extension to lower case
  557. if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN))
  558. {
  559. return 1;
  560. }
  561. }else if(ext == "off")
  562. {
  563. // Convert extension to lower case
  564. if(!igl::readOFF(filename,vV,vF,vN))
  565. {
  566. return 1;
  567. }
  568. }else if(ext == "wrl")
  569. {
  570. // Convert extension to lower case
  571. if(!igl::readWRL(filename,vV,vF))
  572. {
  573. return 1;
  574. }
  575. //}else
  576. //{
  577. // // Convert extension to lower case
  578. // MatrixXi T;
  579. // if(!igl::readMESH(filename,V,T,F))
  580. // {
  581. // return 1;
  582. // }
  583. // //if(F.size() > T.size() || F.size() == 0)
  584. // {
  585. // boundary_facets(T,F);
  586. // }
  587. }
  588. if(vV.size() > 0)
  589. {
  590. if(!list_to_matrix(vV,V))
  591. {
  592. return 1;
  593. }
  594. polygon_mesh_to_triangle_mesh(vF,F);
  595. }
  596. readTGF(skel_filename,C,BE);
  597. // Recover parent indices because (C,BE) is crappy format for a tree.
  598. P.resize(BE.rows(),1);
  599. for(int e = 0;e<BE.rows();e++)
  600. {
  601. P(e) = -1;
  602. for(int f = 0;f<BE.rows();f++)
  603. {
  604. if(BE(e,0) == BE(f,1))
  605. {
  606. P(e) = f;
  607. }
  608. }
  609. }
  610. init_weights(V,F,C,BE,W);
  611. lbs_matrix(V,W,M);
  612. init_relative();
  613. // Init glut
  614. glutInit(&argc,argv);
  615. if( !TwInit(TW_OPENGL, NULL) )
  616. {
  617. // A fatal error occured
  618. fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
  619. return 1;
  620. }
  621. // Create a tweak bar
  622. rebar.TwNewBar("TweakBar");
  623. rebar.TwAddVarRW("camera_rotation", TW_TYPE_QUAT4D,
  624. s.camera.m_rotation_conj.coeffs().data(), "open readonly=true");
  625. TwType RotationTypeTW = ReTwDefineEnumFromString("RotationType",
  626. "igl_trackball,two-a...-fixed-up");
  627. rebar.TwAddVarCB( "rotation_type", RotationTypeTW,
  628. set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=[");
  629. rebar.TwAddVarRW("skeleton_on_top", TW_TYPE_BOOLCPP,&skeleton_on_top,"key=O");
  630. rebar.TwAddVarRW("wireframe", TW_TYPE_BOOLCPP,&wireframe,"key=l");
  631. TwType SkelStyleTypeTW = ReTwDefineEnumFromString("SkelStyleType",
  632. "3d,vector-graphics");
  633. rebar.TwAddVarRW("style",SkelStyleTypeTW,&skel_style,"key=s");
  634. rebar.load(REBAR_NAME);
  635. // Init antweakbar
  636. glutInitDisplayString( "rgba depth double samples>=8 ");
  637. glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0);
  638. glutCreateWindow("upright");
  639. glutDisplayFunc(display);
  640. glutReshapeFunc(reshape);
  641. glutKeyboardFunc(key);
  642. glutMouseFunc(mouse);
  643. glutMotionFunc(mouse_drag);
  644. glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
  645. glutMainLoop();
  646. return 0;
  647. }