Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1104 lines
24 KiB

  1. #ifdef GLX_MOTIF
  2. #include <X11/keysym.h>
  3. #include <X11/Intrinsic.h>
  4. #include <Xm/Xm.h>
  5. #include <Xm/ToggleB.h>
  6. #include <GL/glx.h>
  7. #include <GLwMDrawA.h>
  8. #include <sys/time.h>
  9. #endif
  10. extern "C" {
  11. #include <windows.h>
  12. #include <GL/glu.h>
  13. #include <GL/gl.h>
  14. #include <GL/glaux.h>
  15. }
  16. #include <math.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include "scene.hxx"
  20. #include "cbacks.hxx"
  21. #include "menu.h"
  22. #ifdef GLX_MOTIF
  23. extern Widget glw;
  24. extern XtAppContext app_context;
  25. GLXContext glx_context;
  26. #endif
  27. extern light lights[];
  28. extern int quick_moves;
  29. extern int auto_motion;
  30. static float dtheta[nlights];
  31. static float last_motion_update;
  32. //struct timeval starttime;
  33. SYSTEMTIME starttime;
  34. static int button_down;
  35. static int winx, winy;
  36. GLint mouse_x, mouse_y;
  37. static int name_selected;
  38. #ifdef GLX_MOTIF
  39. static XtWorkProcId workproc = NULL;
  40. #endif
  41. const float time_fudge = .0001;
  42. inline
  43. float current_time()
  44. {
  45. //struct timeval time;
  46. SYSTEMTIME time;
  47. //gettimeofday(&time, NULL);
  48. GetSystemTime(&time);
  49. //return ((double)(time.tv_sec - starttime.tv_sec) +
  50. // (double)(time.tv_usec - starttime.tv_usec) / 1000000.0);
  51. return ((float)(time.wSecond - starttime.wSecond) +
  52. (float)(time.wMilliseconds - starttime.wMilliseconds) / (float)1000.0);
  53. }
  54. inline float rand(float min, float max)
  55. {
  56. double r;
  57. r = (double)rand() / (double)RAND_MAX;
  58. return (float)(min + r * (max - min));
  59. }
  60. /******************************Public*Routine******************************\
  61. *
  62. * void draw(void)
  63. *
  64. * History:
  65. * 29-Nov-1993 Replaced with wgl and aux calls
  66. *
  67. \**************************************************************************/
  68. void draw(void)
  69. {
  70. #ifdef GLX_MOTIF
  71. GLwDrawingAreaMakeCurrent(glw, glx_context);
  72. //#else
  73. //wglMakeCurrent(auxGetHDC(), auxGetHGLRC());
  74. #endif
  75. scene_draw();
  76. #ifdef GLX_MOTIF
  77. GLwDrawingAreaSwapBuffers(glw);
  78. #else
  79. // Win32's SwapBuffers takes HDC
  80. // SwapBuffers(auxGetHDC);
  81. auxSwapBuffers();
  82. #endif
  83. }
  84. /******************************Public*Routine******************************\
  85. *
  86. * vQuickMove(void)
  87. *
  88. * //void intToggleCB(Widget w, XtPointer client_data, XtPointer call_data)
  89. *
  90. * Effects: set or reset the global flag quick_moves
  91. *
  92. * History:
  93. * 30-Nov-1993
  94. *
  95. \**************************************************************************/
  96. void vQuickMove(void)
  97. {
  98. HMENU hmenu;
  99. hmenu = GetMenu(auxGetHWND());
  100. #ifdef GLX_MOTIF
  101. int *data;
  102. XmToggleButtonCallbackStruct *ptr;
  103. ptr = (XmToggleButtonCallbackStruct *)call_data;
  104. data = (int *)client_data;
  105. *data = ptr->set;
  106. #endif
  107. quick_moves = quick_moves ? 0 : 1;
  108. if (quick_moves)
  109. CheckMenuItem(hmenu, IDM_QUICK, MF_BYCOMMAND | MF_CHECKED);
  110. else
  111. CheckMenuItem(hmenu, IDM_QUICK, MF_BYCOMMAND | MF_UNCHECKED);
  112. // This redraw may or may not be needed - do it to be safe
  113. draw();
  114. }
  115. /******************************Public*Routine******************************\
  116. *
  117. * vResetLights(void)
  118. *
  119. * // void resetLightsCB(Widget w)
  120. *
  121. * Effects:
  122. *
  123. * History:
  124. * 30-Nov-1993
  125. *
  126. \**************************************************************************/
  127. void vResetLights(void)
  128. {
  129. scene_reset_lights();
  130. draw();
  131. }
  132. /******************************Public*Routine******************************\
  133. *
  134. * vAutoMotion(void)
  135. *
  136. * // void autoMotionCB(Widget w, XtPointer client_data, XtPointer call_data)
  137. *
  138. * Effects: !!! turns on/off the timer?
  139. * (Re)set the global auto_moves
  140. *
  141. * Warnings:
  142. *
  143. * History:
  144. * 30-Nov-1993
  145. *
  146. \**************************************************************************/
  147. void vAutoMotion(void)
  148. {
  149. int i;
  150. HMENU hmenu;
  151. hmenu = GetMenu(auxGetHWND());
  152. #ifdef GLX_MOTIF
  153. XmToggleButtonCallbackStruct *ptr;
  154. ptr = (XmToggleButtonCallbackStruct *)call_data;
  155. auto_motion = ptr->set;
  156. #endif
  157. auto_motion = auto_motion ? 0 : 1;
  158. SendMessage(auxGetHWND(), WM_USER, 0L, 0L);
  159. if (auto_motion) {
  160. CheckMenuItem(hmenu, IDM_AUTO, MF_BYCOMMAND | MF_CHECKED);
  161. for (i = 0; i < nlights; i++)
  162. dtheta[i] = rand(-1, 1);
  163. last_motion_update = current_time();
  164. } else {
  165. CheckMenuItem(hmenu, IDM_AUTO, MF_BYCOMMAND | MF_UNCHECKED);
  166. }
  167. #ifdef GLX_MOTIF
  168. if (auto_motion) {
  169. workproc = XtAppAddWorkProc(app_context, drawWP, NULL);
  170. for (i = 0; i < nlights; i++) dtheta[i] = rand(-1, 1);
  171. last_motion_update = current_time();
  172. } else {
  173. XtRemoveWorkProc(workproc);
  174. }
  175. #endif
  176. }
  177. /******************************Public*Routine******************************\
  178. *
  179. * vInit(void)
  180. *
  181. * // void initCB(Widget w)
  182. *
  183. * Effects:
  184. *
  185. * History:
  186. * 30-Nov-1993
  187. *
  188. \**************************************************************************/
  189. void vInit(void)
  190. {
  191. RECT rect;
  192. HMENU hmenu;
  193. HWND hWnd;
  194. int i;
  195. #ifdef GLX_MOTIF
  196. Arg args[1];
  197. XVisualInfo *vi;
  198. XtSetArg(args[0], GLwNvisualInfo, &vi);
  199. XtGetValues(w, args, 1);
  200. // !!! creating indirect context, make current
  201. //
  202. glx_context = glXCreateContext(XtDisplay(w), vi, 0, GL_FALSE);
  203. GLwDrawingAreaMakeCurrent(w, glx_context);
  204. #endif
  205. #ifdef TESTTEST
  206. PIXELFORMATDESCRIPTOR pfd;
  207. HDC hDC;
  208. HGLRC hRC;
  209. INT iPixelFormat;
  210. hDC = auxGetHDC();
  211. iPixelFormat = GetPixelFormat(hDC);
  212. DescribePixelFormat(hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  213. if ((pfd.dwFlags & PFD_SUPPORT_GDI) == 0) {
  214. OutputDebugString("PFD_SUPPORT_GDI not supported!\n");
  215. pfd.dwFlags |= PFD_SUPPORT_GDI;
  216. }
  217. if (!SetPixelFormat(hDC, iPixelFormat, &pfd))
  218. OutputDebugString("PFD_SUPPORT_GDI still not supported!\n");
  219. //
  220. // Maynot need this
  221. //
  222. hRC = wglCreateContext(hDC);
  223. if (!wglMakeCurrent(hDC, hRC))
  224. OutputDebugString("MakeCurrentFailed!\n");
  225. #endif
  226. scene_init();
  227. //gettimeofday(&starttime, NULL);
  228. //srand(starttime.tv_usec);
  229. GetSystemTime(&starttime);
  230. srand(starttime.wMilliseconds);
  231. hWnd = auxGetHWND();
  232. GetClientRect(hWnd, &rect);
  233. glViewport(0, 0, rect.right, rect.bottom);
  234. glClear(GL_COLOR_BUFFER_BIT);
  235. //
  236. // this is for initizating the menu items
  237. //
  238. hmenu = GetMenu(hWnd);
  239. for (i=0; i < nlights; i++) {
  240. if (lights[i].on)
  241. CheckMenuItem(hmenu, IDM_RED+i, MF_BYCOMMAND | MF_CHECKED);
  242. else
  243. CheckMenuItem(hmenu, IDM_RED+i, MF_BYCOMMAND | MF_UNCHECKED);
  244. }
  245. if (draw_square)
  246. CheckMenuItem(hmenu, IDM_SQUARE, MF_BYCOMMAND | MF_CHECKED);
  247. if (draw_shadows)
  248. CheckMenuItem(hmenu, IDM_SHADOW, MF_BYCOMMAND | MF_CHECKED);
  249. if (draw_refraction)
  250. CheckMenuItem(hmenu, IDM_REFRACTION, MF_BYCOMMAND | MF_CHECKED);
  251. if (draw_lights)
  252. CheckMenuItem(hmenu, IDM_LIGHTS, MF_BYCOMMAND | MF_CHECKED);
  253. if (draw_sphere)
  254. CheckMenuItem(hmenu, IDM_SPHERE, MF_BYCOMMAND | MF_CHECKED);
  255. if (draw_texture)
  256. CheckMenuItem(hmenu, IDM_TEXTURE, MF_BYCOMMAND | MF_CHECKED);
  257. CheckMenuItem(hmenu, IDM_AIR+def_refraction_index, MF_BYCOMMAND | MF_CHECKED);
  258. CheckMenuItem(hmenu, IDM_10+def_divisions_index, MF_BYCOMMAND | MF_CHECKED);
  259. }
  260. /******************************Public*Routine******************************\
  261. *
  262. * vExpose
  263. *
  264. * // !!! void exposeCB(Widget w)
  265. *
  266. * History:
  267. * 30-Nov-1993
  268. *
  269. \**************************************************************************/
  270. void vExpose(int x, int y)
  271. {
  272. draw();
  273. }
  274. /******************************Public*Routine******************************\
  275. *
  276. * vResize
  277. *
  278. * // void resizeCB(Widget w, XtPointer client_data, XtPointer call)
  279. *
  280. * Effects: changes globals winx, winy and aspect
  281. *
  282. * History:
  283. * 30-Nov-1993
  284. *
  285. \**************************************************************************/
  286. void vResize(GLsizei width, GLsizei height)
  287. {
  288. #ifdef GLX_MOTIF
  289. GLwDrawingAreaCallbackStruct *call_data;
  290. call_data = (GLwDrawingAreaCallbackStruct *)call;
  291. GLwDrawingAreaMakeCurrent(w, glx_context);
  292. winx = call_data->width;
  293. winy = call_data->height;
  294. #endif
  295. winx = width;
  296. winy = height;
  297. glViewport(0, 0, winx, winy);
  298. aspect = (GLfloat)winx / (GLfloat)winy;
  299. }
  300. #ifdef GLX_MOTIF
  301. //
  302. // !!! mouse down/up function??
  303. //
  304. void inputCB(Widget w, XtPointer client_data, XtPointer call_data)
  305. {
  306. int picked;
  307. GLwDrawingAreaCallbackStruct *call;
  308. char buffer[5];
  309. int bufsize = 5;
  310. KeySym key;
  311. XComposeStatus compose;
  312. static int mousex, mousey;
  313. /* Just to confuse everybody, I've made these go from 0-1. */
  314. float dmousex, dmousey;
  315. float r1, r2;
  316. call = (GLwDrawingAreaCallbackStruct *)call_data;
  317. GLwDrawingAreaMakeCurrent(w, glx_context);
  318. switch(call->event->type) {
  319. case ButtonPress:
  320. button_down = call->event->xbutton.button;
  321. mousex = call->event->xbutton.x;
  322. mousey = call->event->xbutton.y;
  323. picked = scene_pick(mousex, mousey);
  324. if (picked >= name_lights) name_selected = picked;
  325. break;
  326. case ButtonRelease:
  327. if (quick_moves)
  328. scene_move_update(name_selected, button_down == Button2,
  329. button_down == Button3, button_down = Button1);
  330. button_down = 0;
  331. break;
  332. case MotionNotify:
  333. if (button_down == Button1) {
  334. /* This is the "default" mouse button - moves things in theta
  335. * since this is easy and computationally cheap */
  336. dmousex = (double)(call->event->xmotion.x - mousex) / (double)winx;
  337. scene_move(name_selected, 0, 0, dmousex, quick_moves ? 0 : 1);
  338. } else if (button_down == Button2) {
  339. /* Change the radius - figue out the component of the mouse motion
  340. * that's going toward the center of the screen */
  341. mousex = (winx / 2) - mousex;
  342. mousey = (winy / 2) - mousey;
  343. r1 = sqrt((float)(mousex*mousex) / (float)(winx*winx) +
  344. (float)(mousey*mousey) / (float)(winy*winy));
  345. mousex = call->event->xmotion.x;
  346. mousey = call->event->xmotion.y;
  347. mousex = (winx / 2) - mousex;
  348. mousey = (winy / 2) - mousey;
  349. r2 = sqrt((float)(mousex*mousex) / (float)(winx*winx) +
  350. (float)(mousey*mousey) / (float)(winy*winy));
  351. scene_move(name_selected, r2 - r1, 0, 0, quick_moves ? 0 : 1);
  352. } else if (button_down == Button3) {
  353. /* Change phi - this is expensive */
  354. dmousex = (double)(call->event->xmotion.x - mousex) / (double)winx;
  355. scene_move(name_selected, 0, dmousex, 0, quick_moves ? 0 : 1);
  356. }
  357. mousex = call->event->xmotion.x;
  358. mousey = call->event->xmotion.y;
  359. break;
  360. case KeyPress:
  361. XLookupString(&(call->event->xkey), buffer, bufsize, &key, &compose);
  362. if (key == XK_Escape) exit(0);
  363. break;
  364. default:
  365. break;
  366. }
  367. draw();
  368. }
  369. #endif
  370. /******************************Public*Routine******************************\
  371. *
  372. * vDrawAll(void)
  373. *
  374. * //void drawAllCB(Widget w)
  375. *
  376. * Effects:
  377. *
  378. * History:
  379. * 30-Nov-1993
  380. *
  381. \**************************************************************************/
  382. void vDrawAll(void)
  383. {
  384. HMENU hmenu;
  385. int i;
  386. static int fAll=0;
  387. hmenu = GetMenu(auxGetHWND());
  388. fAll = fAll ? 0 : 1;
  389. if (fAll) {
  390. for (i=0; i < 6; i++)
  391. CheckMenuItem(hmenu, IDM_SQUARE+i, MF_BYCOMMAND | MF_CHECKED);
  392. CheckMenuItem(hmenu, IDM_ALL, MF_BYCOMMAND | MF_CHECKED);
  393. draw_square = 1;
  394. draw_shadows = 1;
  395. draw_refraction = 1;
  396. draw_sphere = 1;
  397. draw_lights = 1;
  398. } else {
  399. CheckMenuItem(hmenu, IDM_ALL, MF_BYCOMMAND | MF_UNCHECKED);
  400. }
  401. draw();
  402. }
  403. /******************************Public*Routine******************************\
  404. *
  405. * //void drawSomethingCB(Widget w, XtPointer client_data, XtPointer call_data)
  406. *
  407. * Effects: functions for auxKeyFunc can't have parameters so we have
  408. * these similar functions here.
  409. *
  410. * History:
  411. * 30-Nov-1993
  412. *
  413. \**************************************************************************/
  414. void vDrawSquare(void)
  415. {
  416. #ifdef GLX_MOTIF
  417. XmToggleButtonCallbackStruct *ptr;
  418. int *data;
  419. int i;
  420. ptr = (XmToggleButtonCallbackStruct *)call_data;
  421. data = (int *)client_data;
  422. *data = ptr->set;
  423. #endif
  424. HMENU hmenu;
  425. hmenu = GetMenu(auxGetHWND());
  426. draw_square = draw_square ? 0 : 1;
  427. if (draw_square)
  428. CheckMenuItem(hmenu, IDM_SQUARE, MF_BYCOMMAND | MF_CHECKED);
  429. else
  430. CheckMenuItem(hmenu, IDM_SQUARE, MF_BYCOMMAND | MF_UNCHECKED);
  431. draw();
  432. }
  433. void vDrawShadow(void)
  434. {
  435. HMENU hmenu;
  436. hmenu = GetMenu(auxGetHWND());
  437. draw_shadows = draw_shadows ? 0 : 1;
  438. if (draw_shadows)
  439. CheckMenuItem(hmenu, IDM_SHADOW, MF_BYCOMMAND | MF_CHECKED);
  440. else
  441. CheckMenuItem(hmenu, IDM_SHADOW, MF_BYCOMMAND | MF_UNCHECKED);
  442. draw();
  443. }
  444. void vDrawRefraction(void)
  445. {
  446. HMENU hmenu;
  447. hmenu = GetMenu(auxGetHWND());
  448. draw_refraction = draw_refraction ? 0 : 1;
  449. if (draw_refraction)
  450. CheckMenuItem(hmenu, IDM_REFRACTION, MF_BYCOMMAND | MF_CHECKED);
  451. else
  452. CheckMenuItem(hmenu, IDM_REFRACTION, MF_BYCOMMAND | MF_UNCHECKED);
  453. draw();
  454. }
  455. void vDrawSphere(void)
  456. {
  457. HMENU hmenu;
  458. hmenu = GetMenu(auxGetHWND());
  459. draw_sphere = draw_sphere ? 0 : 1;
  460. if (draw_sphere)
  461. CheckMenuItem(hmenu, IDM_SPHERE, MF_BYCOMMAND | MF_CHECKED);
  462. else
  463. CheckMenuItem(hmenu, IDM_SPHERE, MF_BYCOMMAND | MF_UNCHECKED);
  464. draw();
  465. }
  466. void vDrawLight(void)
  467. {
  468. HMENU hmenu;
  469. hmenu = GetMenu(auxGetHWND());
  470. draw_lights = draw_lights ? 0 : 1;
  471. if (draw_lights)
  472. CheckMenuItem(hmenu, IDM_LIGHTS, MF_BYCOMMAND | MF_CHECKED);
  473. else
  474. CheckMenuItem(hmenu, IDM_LIGHTS, MF_BYCOMMAND | MF_UNCHECKED);
  475. draw();
  476. }
  477. void vDrawTexture(void)
  478. {
  479. HMENU hmenu;
  480. hmenu = GetMenu(auxGetHWND());
  481. draw_texture = draw_texture ? 0 : 1;
  482. if (draw_texture)
  483. CheckMenuItem(hmenu, IDM_TEXTURE, MF_BYCOMMAND | MF_CHECKED);
  484. else
  485. CheckMenuItem(hmenu, IDM_TEXTURE, MF_BYCOMMAND | MF_UNCHECKED);
  486. draw();
  487. }
  488. void vDrawStuff(int *what)
  489. {
  490. *what = *what ? 0 : 1;
  491. draw();
  492. }
  493. /******************************Public*Routine******************************\
  494. *
  495. * //void refractionCB(Widget w, XtPointer client_data, XtPointer call_data)
  496. *
  497. * Effects: functions for auxKeyFunc can't have parameters so we have
  498. * these similar functions here.
  499. * History:
  500. * 30-Nov-1993
  501. *
  502. \**************************************************************************/
  503. void vRefractionAIR(void)
  504. {
  505. #ifdef GLX_MOTIF
  506. XmToggleButtonCallbackStruct *ptr;
  507. GLfloat refraction;
  508. ptr = (XmToggleButtonCallbackStruct *)call_data;
  509. if (!ptr->set) return;
  510. refraction = *((GLfloat *)client_data);
  511. #endif
  512. GLfloat refraction;
  513. HMENU hmenu;
  514. int i;
  515. hmenu = GetMenu(auxGetHWND());
  516. for (i = 0; i < nindices; i++)
  517. CheckMenuItem(hmenu, IDM_AIR+i, MF_BYCOMMAND | MF_UNCHECKED);
  518. CheckMenuItem(hmenu, IDM_AIR+0, MF_BYCOMMAND | MF_CHECKED);
  519. refraction = indices[0].index;
  520. refraction_change(refraction);
  521. draw();
  522. }
  523. void vRefractionICE(void)
  524. {
  525. GLfloat refraction;
  526. HMENU hmenu;
  527. int i;
  528. hmenu = GetMenu(auxGetHWND());
  529. for (i = 0; i < nindices; i++)
  530. CheckMenuItem(hmenu, IDM_AIR+i, MF_BYCOMMAND | MF_UNCHECKED);
  531. CheckMenuItem(hmenu, IDM_AIR+1, MF_BYCOMMAND | MF_CHECKED);
  532. refraction = indices[1].index;
  533. refraction_change(refraction);
  534. draw();
  535. }
  536. void vRefractionWATER(void)
  537. {
  538. GLfloat refraction;
  539. HMENU hmenu;
  540. int i;
  541. hmenu = GetMenu(auxGetHWND());
  542. for (i = 0; i < nindices; i++)
  543. CheckMenuItem(hmenu, IDM_AIR+i, MF_BYCOMMAND | MF_UNCHECKED);
  544. CheckMenuItem(hmenu, IDM_AIR+2, MF_BYCOMMAND | MF_CHECKED);
  545. refraction = indices[2].index;
  546. refraction_change(refraction);
  547. draw();
  548. }
  549. void vRefractionZincGLASS(void)
  550. {
  551. GLfloat refraction;
  552. HMENU hmenu;
  553. int i;
  554. hmenu = GetMenu(auxGetHWND());
  555. for (i = 0; i < nindices; i++)
  556. CheckMenuItem(hmenu, IDM_AIR+i, MF_BYCOMMAND | MF_UNCHECKED);
  557. CheckMenuItem(hmenu, IDM_AIR+3, MF_BYCOMMAND | MF_CHECKED);
  558. refraction = indices[3].index;
  559. refraction_change(refraction);
  560. draw();
  561. }
  562. void vRefractionLightGLASS(void)
  563. {
  564. GLfloat refraction;
  565. HMENU hmenu;
  566. int i;
  567. hmenu = GetMenu(auxGetHWND());
  568. for (i = 0; i < nindices; i++)
  569. CheckMenuItem(hmenu, IDM_AIR+i, MF_BYCOMMAND | MF_UNCHECKED);
  570. CheckMenuItem(hmenu, IDM_AIR+4, MF_BYCOMMAND | MF_CHECKED);
  571. refraction = indices[4].index;
  572. refraction_change(refraction);
  573. draw();
  574. }
  575. void vRefractionHeavyGLASS(void)
  576. {
  577. GLfloat refraction;
  578. HMENU hmenu;
  579. int i;
  580. hmenu = GetMenu(auxGetHWND());
  581. for (i = 0; i < nindices; i++)
  582. CheckMenuItem(hmenu, IDM_AIR+i, MF_BYCOMMAND | MF_UNCHECKED);
  583. CheckMenuItem(hmenu, IDM_AIR+5, MF_BYCOMMAND | MF_CHECKED);
  584. refraction = indices[5].index;
  585. refraction_change(refraction);
  586. draw();
  587. }
  588. void vRefraction(int type)
  589. {
  590. GLfloat refraction;
  591. HMENU hmenu;
  592. int i;
  593. hmenu = GetMenu(auxGetHWND());
  594. for (i = 0; i < nindices; i++)
  595. CheckMenuItem(hmenu, IDM_AIR+i, MF_BYCOMMAND | MF_UNCHECKED);
  596. CheckMenuItem(hmenu, IDM_AIR+type, MF_BYCOMMAND | MF_CHECKED);
  597. refraction = indices[type].index;
  598. refraction_change(refraction);
  599. draw();
  600. }
  601. /******************************Public*Routine******************************\
  602. *
  603. * vSubdivision
  604. *
  605. * //void subdivisionCB(Widget w, XtPointer client_data, XtPointer call_data)
  606. *
  607. * Effects: functions for auxKeyFunc can't have parameters so we have
  608. * these similar functions here.
  609. * History:
  610. * 30-Nov-1993
  611. *
  612. \**************************************************************************/
  613. void vSubdivision10(void)
  614. {
  615. #ifdef GLX_MOTIF
  616. XmToggleButtonCallbackStruct *ptr;
  617. int subdivisions;
  618. ptr = (XmToggleButtonCallbackStruct *)call_data;
  619. if (!ptr->set) return;
  620. subdivisions = *((int *)client_data);
  621. #endif
  622. HMENU hmenu;
  623. int i;
  624. hmenu = GetMenu(auxGetHWND());
  625. for (i = 0; i < npossible_divisions; i++)
  626. CheckMenuItem(hmenu, IDM_10+i, MF_BYCOMMAND | MF_UNCHECKED);
  627. CheckMenuItem(hmenu, IDM_10, MF_BYCOMMAND | MF_CHECKED);
  628. divisions_change(possible_divisions[0]);
  629. draw();
  630. }
  631. void vSubdivision20(void)
  632. {
  633. HMENU hmenu;
  634. int i;
  635. hmenu = GetMenu(auxGetHWND());
  636. for (i = 0; i < npossible_divisions; i++)
  637. CheckMenuItem(hmenu, IDM_10+i, MF_BYCOMMAND | MF_UNCHECKED);
  638. CheckMenuItem(hmenu, IDM_20, MF_BYCOMMAND | MF_CHECKED);
  639. divisions_change(possible_divisions[1]);
  640. draw();
  641. }
  642. void vSubdivision30(void)
  643. {
  644. HMENU hmenu;
  645. int i;
  646. hmenu = GetMenu(auxGetHWND());
  647. for (i = 0; i < npossible_divisions; i++)
  648. CheckMenuItem(hmenu, IDM_10+i, MF_BYCOMMAND | MF_UNCHECKED);
  649. CheckMenuItem(hmenu, IDM_30, MF_BYCOMMAND | MF_CHECKED);
  650. divisions_change(possible_divisions[2]);
  651. draw();
  652. }
  653. void vSubdivision40(void)
  654. {
  655. HMENU hmenu;
  656. int i;
  657. hmenu = GetMenu(auxGetHWND());
  658. for (i = 0; i < npossible_divisions; i++)
  659. CheckMenuItem(hmenu, IDM_10+i, MF_BYCOMMAND | MF_UNCHECKED);
  660. CheckMenuItem(hmenu, IDM_40, MF_BYCOMMAND | MF_CHECKED);
  661. divisions_change(possible_divisions[3]);
  662. draw();
  663. }
  664. void vSubdivision(int which)
  665. {
  666. HMENU hmenu;
  667. int i;
  668. hmenu = GetMenu(auxGetHWND());
  669. for (i = 0; i < npossible_divisions; i++)
  670. CheckMenuItem(hmenu, IDM_10+i, MF_BYCOMMAND | MF_UNCHECKED);
  671. CheckMenuItem(hmenu, IDM_10+which, MF_BYCOMMAND | MF_CHECKED);
  672. divisions_change(possible_divisions[which]);
  673. draw();
  674. }
  675. /******************************Public*Routine******************************\
  676. *
  677. * v[RGB]Light_on
  678. *
  679. * //void light_onCB(Widget w, XtPointer client_data, XtPointer call_data)
  680. *
  681. * Effects: functions for auxKeyFunc can't have parameters so we have
  682. * these similar functions here.
  683. * History:
  684. * 30-Nov-1993
  685. *
  686. \**************************************************************************/
  687. #define RED_LIGHT 0
  688. #define GREEN_LIGHT 1
  689. #define BLUE_LIGHT 2
  690. void vRLight_on(void)
  691. {
  692. #ifdef GLX_MOTIF
  693. XmToggleButtonCallbackStruct *ptr;
  694. ptr = (XmToggleButtonCallbackStruct *)call_data;
  695. lights_onoff((light *)client_data - lights, ptr->set);
  696. #endif
  697. int fOn;
  698. HMENU hmenu;
  699. hmenu = GetMenu(auxGetHWND());
  700. fOn = lights[RED_LIGHT].on ? 0 : 1;
  701. if (fOn)
  702. CheckMenuItem(hmenu, IDM_RED, MF_BYCOMMAND | MF_CHECKED);
  703. else
  704. CheckMenuItem(hmenu, IDM_RED, MF_BYCOMMAND | MF_UNCHECKED);
  705. lights_onoff(RED_LIGHT, fOn);
  706. draw();
  707. }
  708. void vGLight_on(void)
  709. {
  710. int fOn;
  711. HMENU hmenu;
  712. hmenu = GetMenu(auxGetHWND());
  713. fOn = lights[GREEN_LIGHT].on ? 0 : 1;
  714. if (fOn)
  715. CheckMenuItem(hmenu, IDM_GREEN, MF_BYCOMMAND | MF_CHECKED);
  716. else
  717. CheckMenuItem(hmenu, IDM_GREEN, MF_BYCOMMAND | MF_UNCHECKED);
  718. lights_onoff(GREEN_LIGHT, fOn);
  719. draw();
  720. }
  721. void vBLight_on(void)
  722. {
  723. int fOn;
  724. HMENU hmenu;
  725. hmenu = GetMenu(auxGetHWND());
  726. fOn = lights[BLUE_LIGHT].on ? 0 : 1;
  727. if (fOn)
  728. CheckMenuItem(hmenu, IDM_BLUE, MF_BYCOMMAND | MF_CHECKED);
  729. else
  730. CheckMenuItem(hmenu, IDM_BLUE, MF_BYCOMMAND | MF_UNCHECKED);
  731. lights_onoff(BLUE_LIGHT, fOn);
  732. draw();
  733. }
  734. void vLight_on(int which)
  735. {
  736. int fOn;
  737. HMENU hmenu;
  738. hmenu = GetMenu(auxGetHWND());
  739. fOn = lights[which].on ? 0 : 1;
  740. if (fOn)
  741. CheckMenuItem(hmenu, IDM_RED+which, MF_BYCOMMAND | MF_CHECKED);
  742. else
  743. CheckMenuItem(hmenu, IDM_RED+which, MF_BYCOMMAND | MF_UNCHECKED);
  744. lights_onoff(which, fOn);
  745. draw();
  746. }
  747. /******************************Public*Routine******************************\
  748. *
  749. * vExit
  750. *
  751. * //void exitCB(Widget w, XtPointer client_data, XtPointer call_data)
  752. *
  753. * Effects: !!! this is redundant unless we do stuff other than auxQuit
  754. *
  755. * History:
  756. * 30-Nov-1993
  757. *
  758. \**************************************************************************/
  759. void vExit(void)
  760. {
  761. #ifdef GLX_MOTIF
  762. exit(0);
  763. #endif
  764. auxQuit();
  765. }
  766. /******************************Public*Routine******************************\
  767. *
  768. * bAutoMotion(void)
  769. *
  770. * // Boolean drawWP(XtPointer data)
  771. *
  772. * Effects: !!! for WM_TIMER ?
  773. *
  774. * History:
  775. * 30-Nov-1993
  776. *
  777. \**************************************************************************/
  778. GLboolean bAutoMotion(void)
  779. {
  780. float t, dt;
  781. int i;
  782. t = current_time();
  783. dt = t - last_motion_update;
  784. dt = (dt < 0) ? -dt : dt;
  785. if (dt < time_fudge) {
  786. char text[128];
  787. wsprintf(text, "dt = %lx\n", dt);
  788. OutputDebugString(text);
  789. return FALSE;
  790. }
  791. for (i = 0; i < nlights; i++) {
  792. scene_move(name_lights + i, 0, 0, dtheta[i] * dt, 1);
  793. }
  794. last_motion_update = t;
  795. draw();
  796. return FALSE;
  797. }
  798. void vMouseDown(AUX_EVENTREC *event)
  799. {
  800. int picked;
  801. mouse_x = event->data[AUX_MOUSEX];
  802. mouse_y = event->data[AUX_MOUSEY];
  803. picked = scene_pick(mouse_x, mouse_y);
  804. if (picked >= name_lights)
  805. name_selected = picked;
  806. return;
  807. }
  808. void vLeftMouseUp(AUX_EVENTREC *event)
  809. {
  810. if (quick_moves)
  811. scene_move_update(name_selected, 0, // dr
  812. 0, // dphi
  813. 1); // dtheta
  814. return;
  815. }
  816. void vMiddleMouseUp(AUX_EVENTREC *event)
  817. {
  818. if (quick_moves)
  819. scene_move_update(name_selected, 1, // dr
  820. 0, // dphi
  821. 0); // dtheta
  822. return;
  823. }
  824. void vRightMouseUp(AUX_EVENTREC *event)
  825. {
  826. if (quick_moves)
  827. scene_move_update(name_selected, 0, // dr
  828. 1, // dphi
  829. 0); // dtheta
  830. return;
  831. }
  832. void CALLBACK vMouseMove(AUX_EVENTREC *event)
  833. {
  834. float dmousex;
  835. float r1, r2;
  836. GLint button = event->data[AUX_MOUSESTATUS];
  837. GLint x = event->data[AUX_MOUSEX];
  838. GLint y = event->data[AUX_MOUSEY];
  839. switch( button ) {
  840. case AUX_LEFTBUTTON:
  841. /* This is the "default" mouse button - moves things in theta
  842. * since this is easy and computationally cheap */
  843. dmousex = (float)((double)(x - mouse_x) / (double)winx);
  844. scene_move(name_selected, 0, 0, dmousex, quick_moves ? 0 : 1);
  845. break;
  846. case AUX_MIDDLEBUTTON:
  847. /* Change the radius - figue out the component of the mouse motion
  848. * that's going toward the center of the screen */
  849. mouse_x = (winx / 2) - mouse_x;
  850. mouse_y = (winy / 2) - mouse_y;
  851. r1 = (float)sqrt((double)(mouse_x*mouse_x) / (double)(winx*winx) +
  852. (double)(mouse_y*mouse_y) / (double)(winy*winy));
  853. mouse_x = x;
  854. mouse_y = y;
  855. mouse_x = (winx / 2) - mouse_x;
  856. mouse_y = (winy / 2) - mouse_y;
  857. r2 = (float)sqrt((double)(mouse_x*mouse_x) / (double)(winx*winx) +
  858. (double)(mouse_y*mouse_y) / (double)(winy*winy));
  859. scene_move(name_selected, r2 - r1, 0, 0, quick_moves ? 0 : 1);
  860. break;
  861. case AUX_RIGHTBUTTON :
  862. /* Change phi - this is expensive */
  863. dmousex = (float)((double)(x - mouse_x) / (double)winx);
  864. scene_move(name_selected, 0, dmousex, 0, quick_moves ? 0 : 1);
  865. break;
  866. }
  867. mouse_x = x;
  868. mouse_y = y;
  869. }
  870. //
  871. // hack these since cfront generates these...
  872. //
  873. PVOID __nw(unsigned int ui)
  874. {
  875. return LocalAlloc(LMEM_FIXED, ui);
  876. }
  877. VOID __dl(PVOID pv)
  878. {
  879. LocalFree(pv);
  880. return;
  881. }
  882. PVOID __vec_new(void *p, int x, int y, void *q)
  883. {
  884. return LocalAlloc(LMEM_FIXED, x*y);
  885. }