example.cpp 16 KB

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