example.cpp 17 KB

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