example.cpp 17 KB

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