74 |
|
|
75 |
|
struct driver odev; /* global device driver structure */ |
76 |
|
|
77 |
+ |
#ifdef STEREO |
78 |
|
static VIEW vwright; /* right eye view */ |
79 |
+ |
#endif |
80 |
|
|
81 |
|
static int rayqleft = 0; /* rays left to queue before flush */ |
82 |
|
|
126 |
|
XSizeHints oursizhints; |
127 |
|
/* check for unsupported stereo */ |
128 |
|
#ifdef NOSTEREO |
129 |
< |
error(USER, "stereo display driver unavailable"); |
129 |
> |
error(INTERNAL, "stereo display driver unavailable"); |
130 |
|
#endif |
131 |
|
/* open display server */ |
132 |
|
ourdisplay = XOpenDisplay(NULL); |
218 |
|
pheight *= 2.; |
219 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
220 |
|
#endif |
221 |
+ |
checkglerr("setting rendering parameters"); |
222 |
|
copystruct(&odev.v, &stdview); |
223 |
|
odev.v.type = VT_PER; |
224 |
|
/* map the window */ |
275 |
|
nv->vert = odev.v.vert; |
276 |
|
return(0); |
277 |
|
} |
278 |
< |
if (nv != &odev.v && /* resize window? */ |
279 |
< |
(!FEQ(nv->horiz,odev.v.horiz) || |
280 |
< |
!FEQ(nv->vert,odev.v.vert))) { |
281 |
< |
int dw = DisplayWidth(ourdisplay,ourscreen); |
282 |
< |
int dh = DisplayHeight(ourdisplay,ourscreen); |
278 |
> |
if (nv != &odev.v) { |
279 |
> |
/* resize window? */ |
280 |
> |
if (!FEQ(nv->horiz,odev.v.horiz) || |
281 |
> |
!FEQ(nv->vert,odev.v.vert)) { |
282 |
> |
int dw = DisplayWidth(ourdisplay,ourscreen); |
283 |
> |
int dh = DisplayHeight(ourdisplay,ourscreen); |
284 |
|
|
285 |
< |
dw -= 25; /* for window frame */ |
286 |
< |
dh -= 50; |
285 |
> |
dw -= 25; /* for window frame */ |
286 |
> |
dh -= 50; |
287 |
|
#ifdef STEREO |
288 |
< |
dh /= 2; |
288 |
> |
dh /= 2; |
289 |
|
#endif |
290 |
< |
odev.hres = 2.*VIEWDIST/pwidth * |
291 |
< |
tan(PI/180./2.*nv->horiz); |
292 |
< |
odev.vres = 2.*VIEWDIST/pheight * |
293 |
< |
tan(PI/180./2.*nv->vert); |
294 |
< |
if (odev.hres > dw) { |
295 |
< |
odev.vres = dw * odev.vres / odev.hres; |
296 |
< |
odev.hres = dw; |
290 |
> |
odev.hres = 2.*VIEWDIST/pwidth * |
291 |
> |
tan(PI/180./2.*nv->horiz); |
292 |
> |
odev.vres = 2.*VIEWDIST/pheight * |
293 |
> |
tan(PI/180./2.*nv->vert); |
294 |
> |
if (odev.hres > dw) { |
295 |
> |
odev.vres = dw * odev.vres / odev.hres; |
296 |
> |
odev.hres = dw; |
297 |
> |
} |
298 |
> |
if (odev.vres > dh) { |
299 |
> |
odev.hres = dh * odev.hres / odev.vres; |
300 |
> |
odev.vres = dh; |
301 |
> |
} |
302 |
> |
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
303 |
> |
dev_input(); /* get resize event */ |
304 |
|
} |
305 |
< |
if (odev.vres > dh) { |
295 |
< |
odev.hres = dh * odev.hres / odev.vres; |
296 |
< |
odev.vres = dh; |
297 |
< |
} |
298 |
< |
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
299 |
< |
dev_input(); /* get resize event */ |
300 |
< |
} |
301 |
< |
copystruct(&odev.v, nv); /* setview() already called */ |
302 |
< |
setglpersp(&odev.v); |
305 |
> |
copystruct(&odev.v, nv); /* setview() already called */ |
306 |
|
#ifdef STEREO |
307 |
< |
copystruct(&vwright, nv); |
308 |
< |
d = eyesepdist / sqrt(nv->hn2); |
309 |
< |
VSUM(vwright.vp, nv->vp, nv->hvec, d); |
310 |
< |
/* setview(&vwright); -- Unnecessary */ |
307 |
> |
copystruct(&vwright, nv); |
308 |
> |
d = eyesepdist / sqrt(nv->hn2); |
309 |
> |
VSUM(vwright.vp, nv->vp, nv->hvec, d); |
310 |
> |
/* setview(&vwright); -- Unnecessary */ |
311 |
|
#endif |
312 |
< |
checkglerr("setting view"); |
312 |
> |
} |
313 |
|
wipeclean(); |
314 |
|
return(1); |
315 |
|
} |
370 |
|
return; |
371 |
|
} |
372 |
|
#endif |
373 |
< |
smNewSamp(c, d, p); /* add to display representation */ |
371 |
< |
if (p != NULL) { |
373 |
> |
if (p != NULL) { /* add depth to our range */ |
374 |
|
depth = (p[0] - odev.v.vp[0])*d[0] + |
375 |
|
(p[1] - odev.v.vp[1])*d[1] + |
376 |
|
(p[2] - odev.v.vp[2])*d[2]; |
381 |
|
maxdpth = depth; |
382 |
|
} |
383 |
|
} |
384 |
+ |
smNewSamp(c, d, p); /* add to display representation */ |
385 |
|
if (!--rayqleft) |
386 |
|
dev_flush(); /* flush output */ |
387 |
|
} |
390 |
|
int |
391 |
|
dev_flush() /* flush output */ |
392 |
|
{ |
393 |
+ |
if (mapped) { |
394 |
|
#ifdef STEREO |
395 |
< |
pushright(); /* update right eye */ |
396 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
393 |
< |
smUpdate(&vwright, 100); |
395 |
> |
pushright(); /* update right eye */ |
396 |
> |
smUpdate(&vwright, 100); |
397 |
|
#ifdef DOBJ |
398 |
< |
dobj_render(); /* usually in foreground */ |
398 |
> |
dobj_render(); /* usually in foreground */ |
399 |
|
#endif |
400 |
< |
popright(); /* update left eye */ |
398 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
400 |
> |
popright(); /* update left eye */ |
401 |
|
#endif |
402 |
< |
smUpdate(&odev.v, 100); |
402 |
> |
smUpdate(&odev.v, 100); |
403 |
> |
checkglerr("rendering mesh"); |
404 |
|
#ifdef DOBJ |
405 |
< |
dobj_render(); |
405 |
> |
dobj_render(); |
406 |
|
#endif |
407 |
< |
glFlush(); /* flush OGL */ |
408 |
< |
checkglerr("flushing display"); |
407 |
> |
glFlush(); /* flush OGL */ |
408 |
> |
} |
409 |
|
rayqleft = RAYQLEN; |
410 |
|
/* flush X11 and return # pending */ |
411 |
|
return(odev.inpready = XPending(ourdisplay)); |
436 |
|
glPushMatrix(); |
437 |
|
d = -eyesepdist / sqrt(odev.v.hn2); |
438 |
|
glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1], d*odev.v.hvec[2]); |
439 |
+ |
checkglerr("setting right view"); |
440 |
|
} |
441 |
|
|
442 |
|
|
505 |
|
|
506 |
|
|
507 |
|
static |
508 |
< |
draw_grids() /* draw holodeck section grids */ |
508 |
> |
draw_grids(fore) /* draw holodeck section grids */ |
509 |
> |
int fore; |
510 |
|
{ |
511 |
< |
static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00}; |
512 |
< |
|
513 |
< |
if (!mapped) |
514 |
< |
return; |
510 |
< |
glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]); |
511 |
> |
if (fore) |
512 |
> |
glColor4ub(0, 255, 255, 0); |
513 |
> |
else |
514 |
> |
glColor4ub(0, 0, 0, 0); |
515 |
|
glBegin(GL_LINES); /* draw each grid line */ |
516 |
|
gridlines(draw3dline); |
517 |
|
glEnd(); |
518 |
+ |
checkglerr("drawing grid lines"); |
519 |
|
} |
520 |
|
|
521 |
|
|
529 |
|
register int li; |
530 |
|
/* start with old view */ |
531 |
|
copystruct(&nv, &odev.v); |
532 |
< |
/* change view direction */ |
532 |
> |
/* orient our motion */ |
533 |
|
if (viewray(v1, odir, &odev.v, |
534 |
|
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
535 |
|
return(0); /* outside view */ |
536 |
< |
if (mov | orb) { |
536 |
> |
if (mov | orb) { /* moving relative to geometry */ |
537 |
|
#ifdef DOBJ |
538 |
< |
d = dobj_trace(v1, odir); /* check objects */ |
539 |
< |
/* is holodeck in front? */ |
540 |
< |
if ((li = smFindSamp(v1, odir)) >= 0 && |
536 |
< |
(rsL.wp[li][0] - nv.vp[0])*odir[0] + |
537 |
< |
(rsL.wp[li][1] - nv.vp[1])*odir[1] + |
538 |
< |
(rsL.wp[li][2] - nv.vp[2])*odir[2] < d) |
538 |
> |
d = dobj_trace(NULL, v1, odir); /* check objects */ |
539 |
> |
/* check holodeck */ |
540 |
> |
if ((li = smFindSamp(v1, odir)) >= 0) { |
541 |
|
VCOPY(wip, rsL.wp[li]); |
542 |
< |
else if (d < .99*FHUGE) /* object is closer */ |
543 |
< |
VSUM(wip, nv.vp, odir, d); |
544 |
< |
else /* nothing visible */ |
545 |
< |
return(0); |
542 |
> |
if (d < .99*FHUGE && d*d <= dist2(v1, wip)) |
543 |
> |
li = -1; /* object is closer */ |
544 |
> |
} else if (d >= .99*FHUGE) |
545 |
> |
return(0); /* nothing visible */ |
546 |
> |
if (li < 0) |
547 |
> |
VSUM(wip, v1, odir, d); /* else get object point */ |
548 |
|
#else |
549 |
|
if ((li = smFindSamp(v1, odir)) < 0) |
550 |
|
return(0); /* not on window */ |
551 |
|
VCOPY(wip, rsL.wp[li]); |
552 |
|
#endif |
553 |
< |
VSUM(odir, wip, nv.vp, -1.); |
554 |
< |
} else |
553 |
> |
VSUM(odir, wip, odev.v.vp, -1.); |
554 |
> |
} else /* panning with constant viewpoint */ |
555 |
|
VCOPY(nv.vdir, odir); |
556 |
|
if (orb && mov) { /* orbit left/right */ |
557 |
|
spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov); |
570 |
|
} |
571 |
|
if (!mov ^ !orb && headlocked) { /* restore head height */ |
572 |
|
VSUM(v1, odev.v.vp, nv.vp, -1.); |
573 |
< |
d = DOT(v1, odev.v.vup); |
573 |
> |
d = DOT(v1, nv.vup); |
574 |
|
VSUM(nv.vp, nv.vp, odev.v.vup, d); |
575 |
|
} |
576 |
|
if (setview(&nv) != NULL) |
594 |
|
int rootx, rooty, wx, wy; |
595 |
|
unsigned int statemask; |
596 |
|
|
597 |
< |
XNoOp(ourdisplay); |
597 |
> |
XNoOp(ourdisplay); /* makes sure we're not idle */ |
598 |
|
|
599 |
|
lasttime = time(0); nframes = 0; |
600 |
|
while (!XCheckMaskEvent(ourdisplay, |
601 |
|
ButtonReleaseMask, levptr(XEvent))) { |
602 |
< |
|
602 |
> |
/* get cursor position */ |
603 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
604 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
605 |
|
break; /* on another screen */ |
606 |
|
|
607 |
+ |
draw_grids(0); /* clear old grid lines */ |
608 |
+ |
#ifdef STEREO |
609 |
+ |
pushright(); draw_grids(0); popright(); |
610 |
+ |
#endif |
611 |
+ |
/* compute view motion */ |
612 |
|
if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) { |
613 |
|
sleep(1); |
614 |
|
lasttime++; |
615 |
< |
continue; |
615 |
> |
continue; /* cursor in bad place */ |
616 |
|
} |
617 |
+ |
draw_grids(1); /* redraw grid */ |
618 |
|
#ifdef STEREO |
619 |
|
pushright(); |
620 |
< |
glClear(GL_COLOR_BUFFER_BIT); |
611 |
< |
draw_grids(); |
620 |
> |
draw_grids(1); |
621 |
|
smUpdate(&vwright, qlevel); |
622 |
|
#ifdef DOBJ |
623 |
|
dobj_render(); |
624 |
|
#endif |
625 |
|
popright(); |
626 |
|
#endif |
627 |
< |
glClear(GL_COLOR_BUFFER_BIT); |
619 |
< |
draw_grids(); |
627 |
> |
/* redraw mesh */ |
628 |
|
smUpdate(&odev.v, qlevel); |
629 |
|
#ifdef DOBJ |
630 |
< |
dobj_render(); |
630 |
> |
dobj_render(); /* redraw object */ |
631 |
|
#endif |
632 |
|
glFlush(); |
633 |
< |
checkglerr("moving view"); |
626 |
< |
nframes++; |
633 |
> |
nframes++; /* figure out good quality level */ |
634 |
|
thistime = time(0); |
635 |
|
if (thistime - lasttime >= 3 || |
636 |
|
nframes > (int)(3*3*TARGETFPS)) { |
695 |
|
odev.v.vp[1] + odev.v.vdir[1], |
696 |
|
odev.v.vp[2] + odev.v.vdir[2], |
697 |
|
odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]); |
698 |
+ |
checkglerr("setting perspective view"); |
699 |
|
} |
700 |
|
|
701 |
|
|
702 |
|
static |
703 |
|
wipeclean() /* prepare for redraw */ |
704 |
|
{ |
705 |
+ |
/* clear depth buffer */ |
706 |
|
#ifdef STEREO |
707 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
708 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
709 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
710 |
|
#endif |
711 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
712 |
< |
smClean(); |
712 |
> |
smClean(); /* reset drawing routines */ |
713 |
> |
setglpersp(&odev.v); /* reset view & clipping planes */ |
714 |
|
} |
715 |
|
|
716 |
|
|
750 |
|
case CTRL('L'): /* refresh from server */ |
751 |
|
if (inpresflags & DFL(DC_REDRAW)) |
752 |
|
return; |
753 |
+ |
setglpersp(&odev.v); /* reset clipping planes */ |
754 |
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
755 |
< |
glDisable(GL_DEPTH_TEST); |
756 |
< |
draw_grids(); |
755 |
> |
glDisable(GL_DEPTH_TEST); /* so grids will clear */ |
756 |
> |
draw_grids(1); |
757 |
|
#ifdef STEREO |
758 |
|
pushright(); |
759 |
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
760 |
< |
draw_grids(); |
760 |
> |
draw_grids(1); |
761 |
|
popright(); |
762 |
|
#endif |
763 |
|
glEnable(GL_DEPTH_TEST); |