example.cpp 16 KB

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