124 |
|
XSizeHints oursizhints; |
125 |
|
/* check for unsupported stereo */ |
126 |
|
#ifdef NOSTEREO |
127 |
< |
error(USER, "stereo display driver unavailable"); |
127 |
> |
error(INTERNAL, "stereo display driver unavailable"); |
128 |
|
#endif |
129 |
|
/* open display server */ |
130 |
|
ourdisplay = XOpenDisplay(NULL); |
272 |
|
nv->vert = odev.v.vert; |
273 |
|
return(0); |
274 |
|
} |
275 |
< |
if (nv != &odev.v && /* resize window? */ |
276 |
< |
(!FEQ(nv->horiz,odev.v.horiz) || |
277 |
< |
!FEQ(nv->vert,odev.v.vert))) { |
278 |
< |
int dw = DisplayWidth(ourdisplay,ourscreen); |
279 |
< |
int dh = DisplayHeight(ourdisplay,ourscreen); |
275 |
> |
if (nv != &odev.v) { |
276 |
> |
/* resize window? */ |
277 |
> |
if (!FEQ(nv->horiz,odev.v.horiz) || |
278 |
> |
!FEQ(nv->vert,odev.v.vert)) { |
279 |
> |
int dw = DisplayWidth(ourdisplay,ourscreen); |
280 |
> |
int dh = DisplayHeight(ourdisplay,ourscreen); |
281 |
|
|
282 |
< |
dw -= 25; /* for window frame */ |
283 |
< |
dh -= 50; |
282 |
> |
dw -= 25; /* for window frame */ |
283 |
> |
dh -= 50; |
284 |
|
#ifdef STEREO |
285 |
< |
dh /= 2; |
285 |
> |
dh /= 2; |
286 |
|
#endif |
287 |
< |
odev.hres = 2.*VIEWDIST/pwidth * |
288 |
< |
tan(PI/180./2.*nv->horiz); |
289 |
< |
odev.vres = 2.*VIEWDIST/pheight * |
290 |
< |
tan(PI/180./2.*nv->vert); |
291 |
< |
if (odev.hres > dw) { |
292 |
< |
odev.vres = dw * odev.vres / odev.hres; |
293 |
< |
odev.hres = dw; |
287 |
> |
odev.hres = 2.*VIEWDIST/pwidth * |
288 |
> |
tan(PI/180./2.*nv->horiz); |
289 |
> |
odev.vres = 2.*VIEWDIST/pheight * |
290 |
> |
tan(PI/180./2.*nv->vert); |
291 |
> |
if (odev.hres > dw) { |
292 |
> |
odev.vres = dw * odev.vres / odev.hres; |
293 |
> |
odev.hres = dw; |
294 |
> |
} |
295 |
> |
if (odev.vres > dh) { |
296 |
> |
odev.hres = dh * odev.hres / odev.vres; |
297 |
> |
odev.vres = dh; |
298 |
> |
} |
299 |
> |
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
300 |
> |
dev_input(); /* get resize event */ |
301 |
|
} |
302 |
< |
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); |
302 |
> |
copystruct(&odev.v, nv); /* setview() already called */ |
303 |
|
#ifdef STEREO |
304 |
< |
copystruct(&vwright, nv); |
305 |
< |
d = eyesepdist / sqrt(nv->hn2); |
306 |
< |
VSUM(vwright.vp, nv->vp, nv->hvec, d); |
307 |
< |
/* setview(&vwright); -- Unnecessary */ |
304 |
> |
copystruct(&vwright, nv); |
305 |
> |
d = eyesepdist / sqrt(nv->hn2); |
306 |
> |
VSUM(vwright.vp, nv->vp, nv->hvec, d); |
307 |
> |
/* setview(&vwright); -- Unnecessary */ |
308 |
|
#endif |
309 |
< |
checkglerr("setting view"); |
309 |
> |
} |
310 |
|
wipeclean(); |
311 |
|
return(1); |
312 |
|
} |
367 |
|
return; |
368 |
|
} |
369 |
|
#endif |
370 |
< |
smNewSamp(c, d, p); /* add to display representation */ |
371 |
< |
if (p != NULL) { |
370 |
> |
if (p != NULL) { /* add depth to our range */ |
371 |
|
depth = (p[0] - odev.v.vp[0])*d[0] + |
372 |
|
(p[1] - odev.v.vp[1])*d[1] + |
373 |
|
(p[2] - odev.v.vp[2])*d[2]; |
378 |
|
maxdpth = depth; |
379 |
|
} |
380 |
|
} |
381 |
+ |
smNewSamp(c, d, p); /* add to display representation */ |
382 |
|
if (!--rayqleft) |
383 |
|
dev_flush(); /* flush output */ |
384 |
|
} |
387 |
|
int |
388 |
|
dev_flush() /* flush output */ |
389 |
|
{ |
390 |
+ |
if (mapped) { |
391 |
|
#ifdef STEREO |
392 |
< |
pushright(); /* update right eye */ |
393 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
394 |
< |
smUpdate(&vwright, 100); |
392 |
> |
pushright(); /* update right eye */ |
393 |
> |
glClear(GL_DEPTH_BUFFER_BIT); |
394 |
> |
smUpdate(&vwright, 100); |
395 |
|
#ifdef DOBJ |
396 |
< |
dobj_render(); /* usually in foreground */ |
396 |
> |
dobj_render(); /* usually in foreground */ |
397 |
|
#endif |
398 |
< |
popright(); /* update left eye */ |
399 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
398 |
> |
popright(); /* update left eye */ |
399 |
> |
glClear(GL_DEPTH_BUFFER_BIT); |
400 |
|
#endif |
401 |
< |
smUpdate(&odev.v, 100); |
401 |
> |
smUpdate(&odev.v, 100); |
402 |
> |
checkglerr("rendering mesh"); |
403 |
|
#ifdef DOBJ |
404 |
< |
dobj_render(); |
404 |
> |
dobj_render(); |
405 |
|
#endif |
406 |
< |
glFlush(); /* flush OGL */ |
407 |
< |
checkglerr("flushing display"); |
406 |
> |
glFlush(); /* flush OGL */ |
407 |
> |
} |
408 |
|
rayqleft = RAYQLEN; |
409 |
|
/* flush X11 and return # pending */ |
410 |
|
return(odev.inpready = XPending(ourdisplay)); |
503 |
|
|
504 |
|
|
505 |
|
static |
506 |
< |
draw_grids() /* draw holodeck section grids */ |
506 |
> |
draw_grids(fore) /* draw holodeck section grids */ |
507 |
> |
int fore; |
508 |
|
{ |
506 |
– |
static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00}; |
507 |
– |
|
509 |
|
if (!mapped) |
510 |
|
return; |
511 |
< |
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(); |
528 |
|
register int li; |
529 |
|
/* start with old view */ |
530 |
|
copystruct(&nv, &odev.v); |
531 |
< |
/* change view direction */ |
531 |
> |
/* orient our motion */ |
532 |
|
if (viewray(v1, odir, &odev.v, |
533 |
|
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
534 |
|
return(0); /* outside view */ |
535 |
< |
if (mov | orb) { |
535 |
> |
if (mov | orb) { /* moving relative to geometry */ |
536 |
|
#ifdef DOBJ |
537 |
|
d = dobj_trace(NULL, v1, odir); /* check objects */ |
538 |
< |
/* is holodeck in front? */ |
539 |
< |
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 |
> |
/* check holodeck */ |
539 |
> |
if ((li = smFindSamp(v1, odir)) >= 0) { |
540 |
|
VCOPY(wip, rsL.wp[li]); |
541 |
< |
else if (d < .99*FHUGE) /* object is closer */ |
542 |
< |
VSUM(wip, nv.vp, odir, d); |
543 |
< |
else /* nothing visible */ |
544 |
< |
return(0); |
541 |
> |
if (d < .99*FHUGE && d*d <= dist2(v1, wip)) |
542 |
> |
li = -1; /* object is closer */ |
543 |
> |
} else if (d >= .99*FHUGE) |
544 |
> |
return(0); /* nothing visible */ |
545 |
> |
if (li < 0) |
546 |
> |
VSUM(wip, v1, odir, d); /* else get object point */ |
547 |
|
#else |
548 |
|
if ((li = smFindSamp(v1, odir)) < 0) |
549 |
|
return(0); /* not on window */ |
550 |
|
VCOPY(wip, rsL.wp[li]); |
551 |
|
#endif |
552 |
< |
VSUM(odir, wip, nv.vp, -1.); |
553 |
< |
} else |
552 |
> |
VSUM(odir, wip, odev.v.vp, -1.); |
553 |
> |
} else /* panning with constant viewpoint */ |
554 |
|
VCOPY(nv.vdir, odir); |
555 |
|
if (orb && mov) { /* orbit left/right */ |
556 |
|
spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov); |
569 |
|
} |
570 |
|
if (!mov ^ !orb && headlocked) { /* restore head height */ |
571 |
|
VSUM(v1, odev.v.vp, nv.vp, -1.); |
572 |
< |
d = DOT(v1, odev.v.vup); |
572 |
> |
d = DOT(v1, nv.vup); |
573 |
|
VSUM(nv.vp, nv.vp, odev.v.vup, d); |
574 |
|
} |
575 |
|
if (setview(&nv) != NULL) |
603 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
604 |
|
break; /* on another screen */ |
605 |
|
|
606 |
+ |
draw_grids(0); /* clear old grid lines */ |
607 |
|
if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) { |
608 |
|
sleep(1); |
609 |
|
lasttime++; |
611 |
|
} |
612 |
|
#ifdef STEREO |
613 |
|
pushright(); |
614 |
< |
glClear(GL_COLOR_BUFFER_BIT); |
611 |
< |
draw_grids(); |
614 |
> |
draw_grids(1); |
615 |
|
smUpdate(&vwright, qlevel); |
616 |
|
#ifdef DOBJ |
617 |
|
dobj_render(); |
618 |
|
#endif |
619 |
|
popright(); |
620 |
|
#endif |
621 |
< |
glClear(GL_COLOR_BUFFER_BIT); |
619 |
< |
draw_grids(); |
621 |
> |
draw_grids(1); |
622 |
|
smUpdate(&odev.v, qlevel); |
623 |
|
#ifdef DOBJ |
624 |
|
dobj_render(); |
696 |
|
static |
697 |
|
wipeclean() /* prepare for redraw */ |
698 |
|
{ |
699 |
+ |
/* clear depth buffer */ |
700 |
|
#ifdef STEREO |
701 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
702 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
703 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
704 |
|
#endif |
705 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
706 |
< |
smClean(); |
706 |
> |
smClean(); /* reset drawing routines */ |
707 |
> |
setglpersp(&odev.v); /* reset view & clipping planes */ |
708 |
|
} |
709 |
|
|
710 |
|
|
746 |
|
return; |
747 |
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
748 |
|
glDisable(GL_DEPTH_TEST); |
749 |
< |
draw_grids(); |
749 |
> |
draw_grids(1); |
750 |
|
#ifdef STEREO |
751 |
|
pushright(); |
752 |
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
753 |
< |
draw_grids(); |
753 |
> |
draw_grids(1); |
754 |
|
popright(); |
755 |
|
#endif |
756 |
|
glEnable(GL_DEPTH_TEST); |
757 |
|
glFlush(); |
758 |
|
smInit(rsL.max_samp); /* get rid of old values */ |
759 |
|
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
760 |
+ |
setglpersp(&odev.v); /* reset clipping planes */ |
761 |
|
rayqleft = 0; /* hold off update */ |
762 |
|
return; |
763 |
|
case 'K': /* kill rtrace process(es) */ |