| 1 | – | /* Copyright (c) 1998 Silicon Graphics, Inc. */ | 
| 2 | – |  | 
| 1 |  | #ifndef lint | 
| 2 | < | static char SCCSid[] = "$SunId$ SGI"; | 
| 2 | > | static const char       RCSid[] = "$Id$"; | 
| 3 |  | #endif | 
| 6 | – |  | 
| 4 |  | /* | 
| 5 |  | * OpenGL driver for holodeck display. | 
| 6 |  | * Based on GLX driver using T-mesh. | 
| 19 |  |  | 
| 20 |  | #include "standard.h" | 
| 21 |  |  | 
| 25 | – | #include <sys/types.h> | 
| 22 |  | #include <GL/glx.h> | 
| 23 |  | #include <GL/glu.h> | 
| 24 |  | #ifdef STEREO | 
| 25 |  | #include <X11/extensions/SGIStereo.h> | 
| 26 |  | #endif | 
| 27 | + | #include <time.h> | 
| 28 |  |  | 
| 29 |  | #include "rhd_odraw.h" | 
| 30 |  | #ifdef DOBJ | 
| 36 |  | #ifndef RAYQLEN | 
| 37 |  | #define RAYQLEN         0               /* max. rays to queue before flush */ | 
| 38 |  | #endif | 
| 39 | + | #ifndef MINWIDTH | 
| 40 | + | #define MINWIDTH        480             /* minimum graphics window width */ | 
| 41 | + | #define MINHEIGHT       400             /* minimum graphics window height */ | 
| 42 | + | #endif | 
| 43 | + | #ifndef VIEWDIST | 
| 44 | + | #define VIEWDIST        356             /* assumed viewing distance (mm) */ | 
| 45 | + | #endif | 
| 46 | + | #ifndef BORWIDTH | 
| 47 | + | #define BORWIDTH        5               /* border width */ | 
| 48 | + | #endif | 
| 49 |  |  | 
| 50 |  | #ifndef FEQ | 
| 51 |  | #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) | 
| 67 |  | #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */ | 
| 68 |  | #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) | 
| 69 |  |  | 
| 63 | – | #define MINWIDTH        480             /* minimum graphics window width */ | 
| 64 | – | #define MINHEIGHT       400             /* minimum graphics window height */ | 
| 65 | – |  | 
| 66 | – | #define VIEWDIST        356             /* assumed viewing distance (mm) */ | 
| 67 | – |  | 
| 68 | – | #define BORWIDTH        5               /* border width */ | 
| 69 | – |  | 
| 70 |  | #define setstereobuf(bid)       (glXWaitGL(), \ | 
| 71 |  | XSGISetStereoBuffer(ourdisplay, gwind, bid), \ | 
| 72 |  | glXWaitX()) | 
| 331 |  | dev_input();    /* get resize event */ | 
| 332 |  | } | 
| 333 |  | copystruct(&odev.v, nv);        /* setview() already called */ | 
| 334 | – | #ifdef STEREO | 
| 335 | – | copystruct(&vwright, nv); | 
| 336 | – | d = eyesepdist / sqrt(nv->hn2); | 
| 337 | – | VSUM(vwright.vp, nv->vp, nv->hvec, d); | 
| 338 | – | /* setview(&vwright);   -- Unnecessary */ | 
| 339 | – | #endif | 
| 334 |  | viewflags |= VWCHANGE; | 
| 335 |  | } | 
| 336 | + | #ifdef STEREO | 
| 337 | + | copystruct(&vwright, nv); | 
| 338 | + | d = eyesepdist / sqrt(nv->hn2); | 
| 339 | + | VSUM(vwright.vp, nv->vp, nv->hvec, d); | 
| 340 | + | /* setview(&vwright);   -- Unnecessary */ | 
| 341 | + | #endif | 
| 342 |  | wipeclean(); | 
| 343 |  | return(1); | 
| 344 |  | } | 
| 347 |  | dev_section(gfn, pfn)           /* add octree for geometry rendering */ | 
| 348 |  | char    *gfn, *pfn; | 
| 349 |  | { | 
| 350 | – | extern char     *index(); | 
| 350 |  | char    *cp; | 
| 351 |  |  | 
| 352 |  | if (gfn == NULL) { | 
| 554 |  | glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */ | 
| 555 |  | odDepthMap(0, depthbuffer);             /* transfer depth data */ | 
| 556 |  | if (pbuf != NULL) | 
| 557 | < | free((char *)pbuf);             /* free our portal buffer */ | 
| 557 | > | free((void *)pbuf);             /* free our portal buffer */ | 
| 558 |  | } | 
| 559 |  |  | 
| 560 |  |  | 
| 565 |  | return; | 
| 566 |  | #ifdef STEREO | 
| 567 |  | odDepthMap(1, NULL); | 
| 568 | < | free((char *)depthright); | 
| 568 | > | free((void *)depthright); | 
| 569 |  | depthright = NULL; | 
| 570 |  | #endif | 
| 571 |  | odDepthMap(0, NULL); | 
| 572 | < | free((char *)depthbuffer); | 
| 572 | > | free((void *)depthbuffer); | 
| 573 |  | depthbuffer = NULL; | 
| 574 |  | } | 
| 575 |  |  | 
| 789 |  |  | 
| 790 |  |  | 
| 791 |  | static | 
| 792 | + | waitabit()                              /* pause a moment */ | 
| 793 | + | { | 
| 794 | + | struct timespec ts; | 
| 795 | + | ts.tv_sec = 0; | 
| 796 | + | ts.tv_nsec = 50000000; | 
| 797 | + | nanosleep(&ts, NULL); | 
| 798 | + | } | 
| 799 | + |  | 
| 800 | + |  | 
| 801 | + | static | 
| 802 |  | getmove(ebut)                           /* get view change */ | 
| 803 |  | XButtonPressedEvent     *ebut; | 
| 804 |  | { | 
| 815 |  | setglpersp();                   /* start us off in perspective */ | 
| 816 |  | while (!XCheckMaskEvent(ourdisplay, | 
| 817 |  | ButtonReleaseMask, levptr(XEvent))) { | 
| 818 | + | /* pause so as not to move too fast */ | 
| 819 | + | waitabit(); | 
| 820 |  | /* get cursor position */ | 
| 821 |  | if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, | 
| 822 |  | &rootx, &rooty, &wx, &wy, &statemask)) | 
| 868 |  | dev_zmax = 100.; | 
| 869 |  | } else { | 
| 870 |  | dev_zmin = 0.5*depthlim[0]; | 
| 871 | < | dev_zmax = 2.0*depthlim[1]; | 
| 871 | > | dev_zmax = 1.25*depthlim[1]; | 
| 872 |  | if (dev_zmin > dev_zmax/5.) | 
| 873 |  | dev_zmin = dev_zmax/5.; | 
| 874 |  | } | 
| 876 |  | dev_zmin = odev.v.vfore; | 
| 877 |  | if (odev.v.vaft > FTINY) | 
| 878 |  | dev_zmax = odev.v.vaft; | 
| 879 | < | if (dev_zmin < dev_zmax/100.) | 
| 880 | < | dev_zmin = dev_zmax/100.; | 
| 879 | > | if (dev_zmin*500. < dev_zmax) | 
| 880 | > | dev_zmin = dev_zmax/500.; | 
| 881 |  | setzrat(); | 
| 882 |  | xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz); | 
| 883 |  | xmin = -xmax; | 
| 953 |  | viewflags &= ~VWCHANGE;         /* change noted */ | 
| 954 |  | } else if (viewflags & VWSTEADY) | 
| 955 |  | odRedrawAll(); | 
| 956 | < | setglpersp(&odev.v);            /* reset view & clipping planes */ | 
| 956 | > | setglpersp();                   /* reset view & clipping planes */ | 
| 957 |  | } | 
| 958 |  |  | 
| 959 |  |  |