1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
6 |
|
|
7 |
|
/* |
8 |
|
* OpenGL GLX driver for holodeck display. |
9 |
< |
* Based on x11 driver. |
9 |
> |
* Based on old GLX driver using cones. |
10 |
> |
* |
11 |
> |
* Define symbol STEREO for stereo viewing. |
12 |
> |
* Define symbol DOBJ for display object viewing. |
13 |
|
*/ |
14 |
|
|
15 |
+ |
#ifdef NOSTEREO |
16 |
+ |
#ifdef STEREO |
17 |
+ |
#undef STEREO |
18 |
+ |
#else |
19 |
+ |
#undef NOSTEREO |
20 |
+ |
#endif |
21 |
+ |
#endif |
22 |
+ |
|
23 |
|
#include "standard.h" |
24 |
< |
#include "tonemap.h" |
14 |
< |
#include "rhdriver.h" |
24 |
> |
#include "rhd_sample.h" |
25 |
|
|
26 |
< |
#include <GL/glx.h> |
27 |
< |
|
28 |
< |
#include "x11icon.h" |
29 |
< |
|
30 |
< |
#ifndef FEQ |
21 |
< |
#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) |
26 |
> |
#include <sys/types.h> |
27 |
> |
#include <GL/glx.h> |
28 |
> |
#include <GL/glu.h> |
29 |
> |
#ifdef STEREO |
30 |
> |
#include <X11/extensions/SGIStereo.h> |
31 |
|
#endif |
32 |
< |
|
33 |
< |
#ifndef int4 |
25 |
< |
#define int4 int |
32 |
> |
#ifdef DOBJ |
33 |
> |
#include "rhdobj.h" |
34 |
|
#endif |
35 |
|
|
36 |
< |
#ifndef FREEPCT |
37 |
< |
#define FREEPCT 10 /* percentage of values to free */ |
36 |
> |
#include "x11icon.h" |
37 |
> |
|
38 |
> |
#ifndef RAYQLEN |
39 |
> |
#define RAYQLEN 250 /* max. rays to queue before flush */ |
40 |
|
#endif |
41 |
|
|
42 |
< |
#ifndef NCONEV |
43 |
< |
#define NCONEV 7 /* number of cone base vertices */ |
42 |
> |
#ifndef FEQ |
43 |
> |
#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) |
44 |
|
#endif |
35 |
– |
#ifndef CONEH |
36 |
– |
#define CONEH 5. /* cone height (fraction of depth) */ |
37 |
– |
#endif |
38 |
– |
#ifndef CONEW |
39 |
– |
#define CONEW 0.07 /* cone width (fraction of screen) */ |
40 |
– |
#endif |
41 |
– |
#ifndef DIRPEN |
42 |
– |
#define DIRPEN 0.001 /* direction penalty factor */ |
43 |
– |
#endif |
45 |
|
|
46 |
|
#define GAMMA 1.4 /* default gamma correction */ |
47 |
|
|
50 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
51 |
|
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
52 |
|
|
53 |
+ |
#ifndef TARGETFPS |
54 |
+ |
#define TARGETFPS 4.0 /* target frames/sec during motion */ |
55 |
+ |
#endif |
56 |
+ |
|
57 |
|
#define MINWIDTH 480 /* minimum graphics window width */ |
58 |
|
#define MINHEIGHT 400 /* minimum graphics window height */ |
59 |
|
|
61 |
|
|
62 |
|
#define BORWIDTH 5 /* border width */ |
63 |
|
|
64 |
+ |
#define setstereobuf(bid) (glXWaitGL(), \ |
65 |
+ |
XSGISetStereoBuffer(ourdisplay, gwind, bid), \ |
66 |
+ |
glXWaitX()) |
67 |
+ |
|
68 |
|
#define ourscreen DefaultScreen(ourdisplay) |
69 |
|
#define ourroot RootWindow(ourdisplay,ourscreen) |
70 |
|
#define ourmask (StructureNotifyMask|ExposureMask|KeyPressMask|\ |
74 |
|
|
75 |
|
struct driver odev; /* global device driver structure */ |
76 |
|
|
77 |
+ |
static VIEW vwright; /* right eye view */ |
78 |
+ |
|
79 |
+ |
static int rayqleft = 0; /* rays left to queue before flush */ |
80 |
+ |
|
81 |
|
static XEvent currentevent; /* current event */ |
82 |
|
|
83 |
|
static int mapped = 0; /* window is mapped? */ |
88 |
|
static Window gwind = 0; /* our graphics window */ |
89 |
|
static GLXContext gctx; /* our GLX context */ |
90 |
|
|
78 |
– |
static double mindepth = FHUGE; /* minimum depth value so far */ |
79 |
– |
static double maxdepth = 0.; /* maximum depth value so far */ |
80 |
– |
|
91 |
|
static double pwidth, pheight; /* pixel dimensions (mm) */ |
92 |
|
|
93 |
< |
static FVECT conev[NCONEV]; /* drawing cone */ |
84 |
< |
static double coneh; /* cone height */ |
93 |
> |
static double mindpth, maxdpth; /* min. and max. depth */ |
94 |
|
|
95 |
+ |
double dev_zmin, dev_zmax; /* fore and aft clipping plane dist. */ |
96 |
+ |
|
97 |
|
static int inpresflags; /* input result flags */ |
98 |
|
|
99 |
|
static int headlocked = 0; /* lock vertical motion */ |
100 |
|
|
101 |
< |
static struct { |
102 |
< |
float (*wp)[3]; /* world intersection point array */ |
92 |
< |
int4 *wd; /* world direction array */ |
93 |
< |
TMbright *brt; /* encoded brightness array */ |
94 |
< |
BYTE (*chr)[3]; /* encoded chrominance array */ |
95 |
< |
BYTE (*rgb)[3]; /* tone-mapped color array */ |
96 |
< |
BYTE *alpha; /* alpha values */ |
97 |
< |
int nl; /* count of values */ |
98 |
< |
int bl, tl; /* bottom and top (next) value index */ |
99 |
< |
int tml; /* next value needing tone-mapping */ |
100 |
< |
int drl; /* next value in need of drawing */ |
101 |
< |
char *base; /* base of allocated memory */ |
102 |
< |
} rV; /* our collection of values */ |
101 |
> |
static int resizewindow(), getevent(), getkey(), moveview(), wipeclean(), |
102 |
> |
setglpersp(), getmove(), fixwindow(), mytmflags(); |
103 |
|
|
104 |
< |
static int *valmap = NULL; /* sorted map of screen values */ |
105 |
< |
static int vmaplen = 0; /* value map length */ |
104 |
> |
#ifdef STEREO |
105 |
> |
static int pushright(), popright(); |
106 |
> |
#endif |
107 |
|
|
108 |
< |
#define redraw() (rV.drl = rV.bl) |
108 |
> |
extern time_t time(); |
109 |
|
|
109 |
– |
static int resizewindow(), getevent(), getkey(), moveview(), |
110 |
– |
setGLview(), getmove(), fixwindow(), mytmflags(), |
111 |
– |
drawvalue(), valcmp(), clralphas(), setalphas(), mergalphas(), |
112 |
– |
IndexValue(), Compost(), FindValue(), TMapValues(), |
113 |
– |
AllocValues(), FreeValues(); |
110 |
|
|
111 |
< |
extern int4 encodedir(); |
116 |
< |
extern double fdir2diff(), dir2diff(); |
117 |
< |
|
118 |
< |
|
119 |
< |
dev_open(id) /* initialize X11 driver */ |
111 |
> |
dev_open(id) /* initialize GLX driver */ |
112 |
|
char *id; |
113 |
|
{ |
114 |
|
extern char *getenv(); |
115 |
+ |
static RGBPRIMS myprims = STDPRIMS; |
116 |
|
static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8, |
117 |
|
GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, |
118 |
< |
GLX_ALPHA_SIZE,8, GLX_DEPTH_SIZE,15, |
119 |
< |
None}; |
127 |
< |
char *gv; |
118 |
> |
GLX_DEPTH_SIZE,15, None}; |
119 |
> |
char *ev; |
120 |
|
double gamval = GAMMA; |
121 |
+ |
RGBPRIMP dpri = stdprims; |
122 |
|
XSetWindowAttributes ourwinattr; |
123 |
|
XWMHints ourxwmhints; |
124 |
|
XSizeHints oursizhints; |
125 |
+ |
/* check for unsupported stereo */ |
126 |
+ |
#ifdef NOSTEREO |
127 |
+ |
error(USER, "stereo display driver unavailable"); |
128 |
+ |
#endif |
129 |
|
/* open display server */ |
130 |
|
ourdisplay = XOpenDisplay(NULL); |
131 |
|
if (ourdisplay == NULL) |
132 |
|
error(USER, "cannot open X-windows; DISPLAY variable set?\n"); |
133 |
+ |
#ifdef STEREO |
134 |
+ |
switch (XSGIQueryStereoMode(ourdisplay, ourroot)) { |
135 |
+ |
case STEREO_TOP: |
136 |
+ |
case STEREO_BOTTOM: |
137 |
+ |
break; |
138 |
+ |
case STEREO_OFF: |
139 |
+ |
error(USER, |
140 |
+ |
"wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first"); |
141 |
+ |
case X_STEREO_UNSUPPORTED: |
142 |
+ |
error(USER, "stereo mode not supported on this screen"); |
143 |
+ |
default: |
144 |
+ |
error(INTERNAL, "unknown stereo mode"); |
145 |
+ |
} |
146 |
+ |
#endif |
147 |
|
/* find a usable visual */ |
148 |
|
ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest); |
149 |
|
if (ourvinf == NULL) |
151 |
|
/* get a context */ |
152 |
|
gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE); |
153 |
|
/* set gamma and tone mapping */ |
154 |
< |
if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
155 |
< |
|| (gv = getenv("DISPLAY_GAMMA")) != NULL) |
156 |
< |
gamval = atof(gv); |
157 |
< |
if (tmInit(mytmflags(), stdprims, gamval) == NULL) |
154 |
> |
if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL |
155 |
> |
|| (ev = getenv("DISPLAY_GAMMA")) != NULL) |
156 |
> |
gamval = atof(ev); |
157 |
> |
if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL && |
158 |
> |
sscanf(ev, "%f %f %f %f %f %f %f %f", |
159 |
> |
&myprims[RED][CIEX],&myprims[RED][CIEY], |
160 |
> |
&myprims[GRN][CIEX],&myprims[GRN][CIEY], |
161 |
> |
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
162 |
> |
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
163 |
> |
dpri = myprims; |
164 |
> |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
165 |
|
error(SYSTEM, "not enough memory in dev_open"); |
166 |
|
/* open window */ |
167 |
|
ourwinattr.background_pixel = ourblack; |
172 |
|
ourvinf->visual, AllocNone); |
173 |
|
gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, |
174 |
|
DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, |
175 |
+ |
#ifdef STEREO |
176 |
+ |
(DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH)/2, |
177 |
+ |
#else |
178 |
|
DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, |
179 |
+ |
#endif |
180 |
|
BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual, |
181 |
|
CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr); |
182 |
|
if (gwind == 0) |
189 |
|
gwind, x11icon_bits, x11icon_width, x11icon_height); |
190 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
191 |
|
oursizhints.min_width = MINWIDTH; |
192 |
+ |
#ifdef STEREO |
193 |
+ |
oursizhints.min_height = MINHEIGHT/2; |
194 |
+ |
oursizhints.max_width = DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH; |
195 |
+ |
oursizhints.max_height = (DisplayHeight(ourdisplay,ourscreen) - |
196 |
+ |
2*BORWIDTH)/2; |
197 |
+ |
oursizhints.flags = PMinSize|PMaxSize; |
198 |
+ |
#else |
199 |
|
oursizhints.min_height = MINHEIGHT; |
200 |
|
oursizhints.flags = PMinSize; |
201 |
+ |
#endif |
202 |
|
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
203 |
|
/* set GLX context */ |
204 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
205 |
|
glEnable(GL_DEPTH_TEST); |
206 |
|
glDepthFunc(GL_LEQUAL); |
207 |
< |
glShadeModel(GL_FLAT); |
207 |
> |
glShadeModel(GL_SMOOTH); |
208 |
|
glDisable(GL_DITHER); |
209 |
+ |
glDisable(GL_CULL_FACE); |
210 |
|
/* figure out sensible view */ |
211 |
|
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
212 |
|
DisplayWidth(ourdisplay, ourscreen); |
213 |
|
pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / |
214 |
|
DisplayHeight(ourdisplay, ourscreen); |
215 |
+ |
#ifdef STEREO |
216 |
+ |
pheight *= 2.; |
217 |
+ |
setstereobuf(STEREO_BUFFER_LEFT); |
218 |
+ |
#endif |
219 |
|
copystruct(&odev.v, &stdview); |
220 |
|
odev.v.type = VT_PER; |
221 |
|
/* map the window */ |
222 |
|
XMapWindow(ourdisplay, gwind); |
223 |
|
dev_input(); /* sets size and view angles */ |
224 |
< |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
225 |
< |
/* allocate our value list */ |
226 |
< |
if (!AllocValues(DisplayWidth(ourdisplay,ourscreen) * |
192 |
< |
DisplayHeight(ourdisplay,ourscreen) / 4)) |
224 |
> |
/* allocate our samples */ |
225 |
> |
if (!smInit(DisplayWidth(ourdisplay,ourscreen) * |
226 |
> |
DisplayHeight(ourdisplay,ourscreen) / 10)) |
227 |
|
error(SYSTEM, "insufficient memory for value storage"); |
228 |
+ |
mindpth = FHUGE; maxdpth = FTINY; |
229 |
|
odev.name = id; |
230 |
|
odev.ifd = ConnectionNumber(ourdisplay); |
231 |
|
} |
233 |
|
|
234 |
|
dev_close() /* close our display and free resources */ |
235 |
|
{ |
236 |
+ |
smInit(0); |
237 |
+ |
#ifdef DOBJ |
238 |
+ |
dobj_cleanup(); |
239 |
+ |
#endif |
240 |
|
glXMakeCurrent(ourdisplay, None, NULL); |
241 |
|
glXDestroyContext(ourdisplay, gctx); |
242 |
|
XDestroyWindow(ourdisplay, gwind); |
244 |
|
XCloseDisplay(ourdisplay); |
245 |
|
ourdisplay = NULL; |
246 |
|
tmDone(NULL); |
208 |
– |
FreeValues(); |
247 |
|
odev.v.type = 0; |
248 |
|
odev.hres = odev.vres = 0; |
249 |
|
odev.ifd = -1; |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
+ |
dev_clear() /* clear our representation */ |
254 |
+ |
{ |
255 |
+ |
smInit(rsL.max_samp); |
256 |
+ |
wipeclean(); |
257 |
+ |
rayqleft = 0; /* hold off update */ |
258 |
+ |
} |
259 |
+ |
|
260 |
+ |
|
261 |
|
int |
262 |
|
dev_view(nv) /* assign new driver view */ |
263 |
|
register VIEW *nv; |
264 |
|
{ |
265 |
+ |
double d; |
266 |
+ |
|
267 |
|
if (nv->type != VT_PER || /* check view legality */ |
268 |
< |
nv->horiz > 120. || nv->vert > 120.) { |
268 |
> |
nv->horiz > 160. || nv->vert > 160.) { |
269 |
|
error(COMMAND, "illegal view type/angle"); |
270 |
< |
nv->type = VT_PER; |
270 |
> |
nv->type = odev.v.type; |
271 |
|
nv->horiz = odev.v.horiz; |
272 |
|
nv->vert = odev.v.vert; |
273 |
|
return(0); |
274 |
|
} |
275 |
< |
if (nv != &odev.v) { |
276 |
< |
if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */ |
277 |
< |
!FEQ(nv->vert,odev.v.vert)) { |
278 |
< |
int dw = DisplayWidth(ourdisplay,ourscreen); |
279 |
< |
int dh = DisplayHeight(ourdisplay,ourscreen); |
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); |
280 |
|
|
281 |
< |
dw -= 25; /* for window frame */ |
282 |
< |
dh -= 50; |
283 |
< |
odev.hres = 2.*VIEWDIST/pwidth * |
284 |
< |
tan(PI/180./2.*nv->horiz); |
285 |
< |
odev.vres = 2.*VIEWDIST/pheight * |
286 |
< |
tan(PI/180./2.*nv->vert); |
287 |
< |
if (odev.hres > dw) { |
288 |
< |
odev.vres = dw * odev.vres / odev.hres; |
289 |
< |
odev.hres = dw; |
290 |
< |
} |
291 |
< |
if (odev.vres > dh) { |
292 |
< |
odev.hres = dh * odev.hres / odev.vres; |
245 |
< |
odev.vres = dh; |
246 |
< |
} |
247 |
< |
XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); |
248 |
< |
dev_input(); /* get resize event */ |
281 |
> |
dw -= 25; /* for window frame */ |
282 |
> |
dh -= 50; |
283 |
> |
#ifdef STEREO |
284 |
> |
dh /= 2; |
285 |
> |
#endif |
286 |
> |
odev.hres = 2.*VIEWDIST/pwidth * |
287 |
> |
tan(PI/180./2.*nv->horiz); |
288 |
> |
odev.vres = 2.*VIEWDIST/pheight * |
289 |
> |
tan(PI/180./2.*nv->vert); |
290 |
> |
if (odev.hres > dw) { |
291 |
> |
odev.vres = dw * odev.vres / odev.hres; |
292 |
> |
odev.hres = dw; |
293 |
|
} |
294 |
< |
copystruct(&odev.v, nv); |
295 |
< |
setGLview(); |
296 |
< |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
297 |
< |
redraw(); |
294 |
> |
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); |
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 */ |
308 |
+ |
#endif |
309 |
+ |
checkglerr("setting view"); |
310 |
+ |
wipeclean(); |
311 |
|
return(1); |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
< |
int |
316 |
< |
dev_input() /* get X11 input */ |
315 |
> |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
316 |
> |
char *cmd, *args; |
317 |
|
{ |
318 |
< |
inpresflags = 0; |
319 |
< |
|
320 |
< |
do |
321 |
< |
getevent(); |
322 |
< |
|
323 |
< |
while (XQLength(ourdisplay) > 0); |
268 |
< |
|
269 |
< |
return(inpresflags); |
318 |
> |
#ifdef DOBJ |
319 |
> |
if (dobj_command(cmd, args) >= 0) |
320 |
> |
return; |
321 |
> |
#endif |
322 |
> |
sprintf(errmsg, "%s: unknown command", cmd); |
323 |
> |
error(COMMAND, errmsg); |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
< |
dev_value(c, p, v) /* add a pixel value to our list */ |
328 |
< |
COLR c; |
329 |
< |
FVECT p, v; |
327 |
> |
VIEW * |
328 |
> |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
329 |
> |
int n; |
330 |
> |
int hvres[2]; |
331 |
|
{ |
332 |
< |
register int li; |
333 |
< |
|
334 |
< |
li = rV.tl++; |
335 |
< |
if (rV.tl >= rV.nl) /* get next leaf in ring */ |
336 |
< |
rV.tl = 0; |
337 |
< |
if (rV.tl == rV.bl) /* need to shake some free */ |
338 |
< |
Compost(FREEPCT); |
339 |
< |
VCOPY(rV.wp[li], p); |
285 |
< |
rV.wd[li] = encodedir(v); |
286 |
< |
tmCvColrs(&rV.brt[li], rV.chr[li], c, 1); |
332 |
> |
hvres[0] = odev.hres; hvres[1] = odev.vres; |
333 |
> |
if (n == 0) |
334 |
> |
return(&odev.v); |
335 |
> |
#ifdef STEREO |
336 |
> |
if (n == 1) |
337 |
> |
return(&vwright); |
338 |
> |
#endif |
339 |
> |
return(NULL); |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
int |
344 |
< |
dev_flush() /* flush output */ |
344 |
> |
dev_input() /* get X11 input */ |
345 |
|
{ |
346 |
< |
if (mapped) { |
294 |
< |
TMapValues(0); |
295 |
< |
while (rV.drl != rV.tl) { |
296 |
< |
drawvalue(rV.drl); |
297 |
< |
if (++rV.drl >= rV.nl) |
298 |
< |
rV.drl = 0; |
299 |
< |
} |
300 |
< |
glFlush(); |
301 |
< |
} |
302 |
< |
return(XPending(ourdisplay)); |
303 |
< |
} |
346 |
> |
inpresflags = 0; |
347 |
|
|
348 |
+ |
do |
349 |
+ |
getevent(); |
350 |
|
|
351 |
< |
static int |
352 |
< |
mytmflags() /* figure out tone mapping flags */ |
353 |
< |
{ |
354 |
< |
extern char *progname; |
355 |
< |
register char *cp, *tail; |
311 |
< |
/* find basic name */ |
312 |
< |
for (cp = tail = progname; *cp; cp++) |
313 |
< |
if (*cp == '/') |
314 |
< |
tail = cp+1; |
315 |
< |
for (cp = tail; *cp && *cp != '.'; cp++) |
316 |
< |
; |
317 |
< |
if (cp-tail == 3 && !strncmp(tail, "glx", 3)) |
318 |
< |
return(TM_F_CAMERA); |
319 |
< |
if (cp-tail == 4 && !strncmp(tail, "glxh", 4)) |
320 |
< |
return(TM_F_HUMAN); |
321 |
< |
error(USER, "illegal driver name"); |
351 |
> |
while (XPending(ourdisplay) > 0); |
352 |
> |
|
353 |
> |
odev.inpready = 0; |
354 |
> |
|
355 |
> |
return(inpresflags); |
356 |
|
} |
357 |
|
|
358 |
|
|
359 |
< |
static |
360 |
< |
setGLview() /* set our GL view */ |
359 |
> |
dev_value(c, d, p) /* add a pixel value to our mesh */ |
360 |
> |
COLR c; |
361 |
> |
FVECT d, p; |
362 |
|
{ |
363 |
< |
double xmin, xmax, ymin, ymax, zmin, zmax; |
364 |
< |
double d, cx, sx, crad; |
365 |
< |
FVECT vx, vy; |
366 |
< |
register int i, j; |
332 |
< |
/* compute view frustum */ |
333 |
< |
if (normalize(odev.v.vdir) == 0.0) |
363 |
> |
double depth; |
364 |
> |
#ifdef DOBJ |
365 |
> |
if (dobj_lightsamp != NULL) { /* in light source sampling */ |
366 |
> |
(*dobj_lightsamp)(c, d, p); |
367 |
|
return; |
335 |
– |
if (mindepth < maxdepth) { |
336 |
– |
zmin = 0.25*mindepth; |
337 |
– |
zmax = 4.0*(1.+CONEH)*maxdepth; |
338 |
– |
} else { |
339 |
– |
zmin = 0.01; |
340 |
– |
zmax = 1000.; |
368 |
|
} |
369 |
< |
if (odev.v.vfore > FTINY) |
370 |
< |
zmin = odev.v.vfore; |
371 |
< |
if (odev.v.vaft > FTINY) |
372 |
< |
zmax = odev.v.vaft; |
373 |
< |
xmax = zmin * tan(PI/180./2. * odev.v.horiz); |
374 |
< |
xmin = -xmax; |
375 |
< |
d = odev.v.hoff * (xmax - xmin); |
376 |
< |
xmin += d; xmax += d; |
377 |
< |
ymax = zmin * tan(PI/180./2. * odev.v.vert); |
378 |
< |
ymin = -ymax; |
379 |
< |
d = odev.v.voff * (ymax - ymin); |
380 |
< |
ymin += d; ymax += d; |
354 |
< |
/* set view matrix */ |
355 |
< |
glMatrixMode(GL_PROJECTION); |
356 |
< |
glLoadIdentity(); |
357 |
< |
glFrustum(xmin, xmax, ymin, ymax, zmin, zmax); |
358 |
< |
gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2], |
359 |
< |
odev.v.vp[0] + odev.v.vdir[0], |
360 |
< |
odev.v.vp[1] + odev.v.vdir[1], |
361 |
< |
odev.v.vp[2] + odev.v.vdir[2], |
362 |
< |
odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]); |
363 |
< |
/* set viewport */ |
364 |
< |
glViewport(0, 0, odev.hres, odev.vres); |
365 |
< |
/* initialize cone for Vornoi polys */ |
366 |
< |
coneh = CONEH*(zmax - zmin); |
367 |
< |
crad = 0.5 * CONEW * 0.5*(xmax-xmin + ymax-ymin) * (zmin+coneh)/zmin; |
368 |
< |
vy[0] = vy[1] = vy[2] = 0.; |
369 |
< |
for (i = 0; i < 3; i++) |
370 |
< |
if (odev.v.vdir[i] < 0.6 && odev.v.vdir[i] > -0.6) |
371 |
< |
break; |
372 |
< |
vy[i] = 1.; |
373 |
< |
fcross(vx, vy, odev.v.vdir); |
374 |
< |
normalize(vx); |
375 |
< |
fcross(vy, odev.v.vdir, vx); |
376 |
< |
for (j = 0, d = 0.; j < NCONEV; j++, d += 2.*PI/NCONEV) { |
377 |
< |
cx = crad*cos(d); sx = crad*sin(d); |
378 |
< |
for (i = 0; i < 3; i++) |
379 |
< |
conev[j][i] = coneh*odev.v.vdir[i] + |
380 |
< |
cx*vx[i] + sx*vy[i]; |
369 |
> |
#endif |
370 |
> |
smNewSamp(c, d, p); /* add to display representation */ |
371 |
> |
if (p != NULL) { |
372 |
> |
depth = (p[0] - odev.v.vp[0])*d[0] + |
373 |
> |
(p[1] - odev.v.vp[1])*d[1] + |
374 |
> |
(p[2] - odev.v.vp[2])*d[2]; |
375 |
> |
if (depth > FTINY) { |
376 |
> |
if (depth < mindpth) |
377 |
> |
mindpth = depth; |
378 |
> |
if (depth > maxdpth) |
379 |
> |
maxdpth = depth; |
380 |
> |
} |
381 |
|
} |
382 |
+ |
if (!--rayqleft) |
383 |
+ |
dev_flush(); /* flush output */ |
384 |
|
} |
385 |
|
|
386 |
|
|
387 |
< |
static |
388 |
< |
drawvalue(li) /* draw a pixel value as a cone */ |
387 |
< |
register int li; |
387 |
> |
int |
388 |
> |
dev_flush() /* flush output */ |
389 |
|
{ |
390 |
< |
static FVECT disp; |
391 |
< |
FVECT apex; |
392 |
< |
double d, dorg, dnew, h, v; |
393 |
< |
register int i; |
394 |
< |
/* compute cone coordinates */ |
395 |
< |
disp[0] = rV.wp[li][0] - odev.v.vp[0]; |
396 |
< |
disp[1] = rV.wp[li][1] - odev.v.vp[1]; |
397 |
< |
disp[2] = rV.wp[li][2] - odev.v.vp[2]; |
398 |
< |
dorg = DOT(disp,odev.v.vdir); |
399 |
< |
if (dorg <= odev.v.vfore) |
400 |
< |
return; /* clipped too near */ |
401 |
< |
if (odev.v.vaft > FTINY && dorg > odev.v.vaft) |
402 |
< |
return; /* clipped too far */ |
403 |
< |
if (dorg > 1e5) { /* background pixel */ |
404 |
< |
dnew = maxdepth; |
405 |
< |
d = dnew/dorg; |
406 |
< |
} else { /* foreground pixel, compute penalty */ |
407 |
< |
normalize(disp); |
408 |
< |
d = dnew = dorg + coneh*fdir2diff(rV.wd[li],disp)*DIRPEN; |
408 |
< |
} |
409 |
< |
/* compute adjusted apex position */ |
410 |
< |
disp[0] *= d; disp[1] *= d; disp[2] *= d; |
411 |
< |
apex[0] = odev.v.vp[0] + disp[0]; |
412 |
< |
apex[1] = odev.v.vp[1] + disp[1]; |
413 |
< |
apex[2] = odev.v.vp[2] + disp[2]; |
414 |
< |
/* compute view position and base offset */ |
415 |
< |
h = DOT(disp,odev.v.hvec)/(dnew*odev.v.hn2); |
416 |
< |
v = DOT(disp,odev.v.vvec)/(dnew*odev.v.vn2); |
417 |
< |
if (fabs(h - odev.v.hoff) > 0.5 || fabs(v - odev.v.voff) > 0.5) |
418 |
< |
return; /* clipped off screen */ |
419 |
< |
if (dorg < mindepth) |
420 |
< |
mindepth = dorg; |
421 |
< |
if (dorg > maxdepth) |
422 |
< |
maxdepth = dorg; |
423 |
< |
for (i = 0; i < 3; i++) |
424 |
< |
disp[i] = apex[i] + coneh*(h*odev.v.hvec[i] + v*odev.v.vvec[i]); |
425 |
< |
/* draw cone (pyramid approx.) */ |
426 |
< |
glColor4ub(rV.rgb[li][0], rV.rgb[li][1], rV.rgb[li][2], rV.alpha[li]); |
427 |
< |
glBegin(GL_TRIANGLE_FAN); |
428 |
< |
glVertex3f(apex[0], apex[1], apex[2]); |
429 |
< |
for (i = 0; i < NCONEV; i++) |
430 |
< |
glVertex3d(conev[i][0] + disp[0], conev[i][1] + disp[1], |
431 |
< |
conev[i][2] + disp[2]); |
432 |
< |
/* connect last face to first */ |
433 |
< |
glVertex3d(conev[0][0] + disp[0], conev[0][1] + disp[1], |
434 |
< |
conev[0][2] + disp[2]); |
435 |
< |
glEnd(); /* done */ |
390 |
> |
#ifdef STEREO |
391 |
> |
pushright(); /* update right eye */ |
392 |
> |
glClear(GL_DEPTH_BUFFER_BIT); |
393 |
> |
smUpdate(&vwright, 100); |
394 |
> |
#ifdef DOBJ |
395 |
> |
dobj_render(); /* usually in foreground */ |
396 |
> |
#endif |
397 |
> |
popright(); /* update left eye */ |
398 |
> |
glClear(GL_DEPTH_BUFFER_BIT); |
399 |
> |
#endif |
400 |
> |
smUpdate(&odev.v, 100); |
401 |
> |
#ifdef DOBJ |
402 |
> |
dobj_render(); |
403 |
> |
#endif |
404 |
> |
glFlush(); /* flush OGL */ |
405 |
> |
checkglerr("flushing display"); |
406 |
> |
rayqleft = RAYQLEN; |
407 |
> |
/* flush X11 and return # pending */ |
408 |
> |
return(odev.inpready = XPending(ourdisplay)); |
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
< |
#define LEAFSIZ (3*sizeof(float)+sizeof(int4)+\ |
413 |
< |
sizeof(TMbright)+7*sizeof(BYTE)) |
441 |
< |
|
442 |
< |
static |
443 |
< |
AllocValues(n) /* allocate space for n values */ |
444 |
< |
register int n; |
412 |
> |
checkglerr(where) /* check for GL or GLU error */ |
413 |
> |
char *where; |
414 |
|
{ |
415 |
< |
unsigned nbytes; |
447 |
< |
register unsigned i; |
415 |
> |
register GLenum errcode; |
416 |
|
|
417 |
< |
if (n <= 0) |
418 |
< |
return(0); |
419 |
< |
if (rV.nl >= n) |
420 |
< |
return(rV.nl); |
453 |
< |
else if (rV.nl > 0) |
454 |
< |
free(rV.base); |
455 |
< |
/* round space up to nearest power of 2 */ |
456 |
< |
nbytes = n*LEAFSIZ + 8; |
457 |
< |
for (i = 1024; nbytes > i; i <<= 1) |
458 |
< |
; |
459 |
< |
n = (i - 8) / LEAFSIZ; /* should we make sure n is even? */ |
460 |
< |
rV.base = (char *)malloc(n*LEAFSIZ); |
461 |
< |
if (rV.base == NULL) |
462 |
< |
return(0); |
463 |
< |
/* assign larger alignment types earlier */ |
464 |
< |
rV.wp = (float (*)[3])rV.base; |
465 |
< |
rV.wd = (int4 *)(rV.wp + n); |
466 |
< |
rV.brt = (TMbright *)(rV.wd + n); |
467 |
< |
rV.chr = (BYTE (*)[3])(rV.brt + n); |
468 |
< |
rV.rgb = (BYTE (*)[3])(rV.chr + n); |
469 |
< |
rV.alpha = (BYTE *)(rV.rgb + n); |
470 |
< |
rV.nl = n; |
471 |
< |
rV.drl = rV.tml = rV.bl = rV.tl = 0; |
472 |
< |
return(n); |
473 |
< |
} |
474 |
< |
|
475 |
< |
#undef LEAFSIZ |
476 |
< |
|
477 |
< |
|
478 |
< |
static |
479 |
< |
FreeValues() /* free our allocated values */ |
480 |
< |
{ |
481 |
< |
if (rV.nl <= 0) |
482 |
< |
return; |
483 |
< |
free(rV.base); |
484 |
< |
rV.base = NULL; |
485 |
< |
rV.nl = 0; |
486 |
< |
} |
487 |
< |
|
488 |
< |
|
489 |
< |
static |
490 |
< |
clralphas() /* prepare for new alpha values */ |
491 |
< |
{ |
492 |
< |
if (!vmaplen) |
493 |
< |
return; |
494 |
< |
free((char *)valmap); |
495 |
< |
valmap = NULL; |
496 |
< |
vmaplen = 0; |
497 |
< |
} |
498 |
< |
|
499 |
< |
|
500 |
< |
static int |
501 |
< |
valcmp(v1p, v2p) /* compare two pixel values */ |
502 |
< |
int *v1p, *v2p; |
503 |
< |
{ |
504 |
< |
register int v1 = *v1p, v2 = *v2p; |
505 |
< |
register int c; |
506 |
< |
|
507 |
< |
if ((c = rV.rgb[v1][0] - rV.rgb[v2][0])) return(c); |
508 |
< |
if ((c = rV.rgb[v1][1] - rV.rgb[v2][1])) return(c); |
509 |
< |
if ((c = rV.rgb[v1][2] - rV.rgb[v2][2])) return(c); |
510 |
< |
return(rV.alpha[v1] - rV.alpha[v2]); |
511 |
< |
} |
512 |
< |
|
513 |
< |
|
514 |
< |
static |
515 |
< |
mergalphas(adest, al1, n1, al2, n2) /* merge two sorted alpha lists */ |
516 |
< |
register int *adest, *al1, *al2; |
517 |
< |
int n1, n2; |
518 |
< |
{ |
519 |
< |
register int cmp; |
520 |
< |
|
521 |
< |
while (n1 | n2) { |
522 |
< |
if (!n1) cmp = 1; |
523 |
< |
else if (!n2) cmp = -1; |
524 |
< |
else cmp = valcmp(al1, al2); |
525 |
< |
if (cmp > 0) { |
526 |
< |
*adest++ = *al2++; |
527 |
< |
n2--; |
528 |
< |
} else { |
529 |
< |
*adest++ = *al1++; |
530 |
< |
n1--; |
531 |
< |
} |
417 |
> |
while ((errcode = glGetError()) != GL_NO_ERROR) { |
418 |
> |
sprintf(errmsg, "OpenGL error %s: %s", |
419 |
> |
where, gluErrorString(errcode)); |
420 |
> |
error(WARNING, errmsg); |
421 |
|
} |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
+ |
#ifdef STEREO |
426 |
|
static |
427 |
< |
setalphas(vbeg, nvals) /* add values to our map and set alphas */ |
538 |
< |
int vbeg, nvals; |
427 |
> |
pushright() /* push on right view */ |
428 |
|
{ |
429 |
< |
register int *newmap; |
541 |
< |
short ccmp[3], lastalpha; |
542 |
< |
int newmaplen; |
429 |
> |
double d; |
430 |
|
|
431 |
< |
if (nvals <= 0) |
432 |
< |
return; |
433 |
< |
newmaplen = vmaplen + nvals; /* allocate new map */ |
434 |
< |
newmap = (int *)malloc(newmaplen*sizeof(int)); |
435 |
< |
if (newmap == NULL) |
549 |
< |
error(SYSTEM, "out of memory in setalphas"); |
550 |
< |
while (nvals--) { /* add new values to end */ |
551 |
< |
rV.alpha[vbeg] = 255; |
552 |
< |
newmap[vmaplen+nvals] = vbeg++; |
553 |
< |
} |
554 |
< |
if (nvals >= 3*vmaplen) { /* resort the combined array */ |
555 |
< |
while (vmaplen--) |
556 |
< |
newmap[vmaplen] = valmap[vmaplen]; |
557 |
< |
qsort((char *)newmap, newmaplen, sizeof(int), valcmp); |
558 |
< |
} else { /* perform merge sort */ |
559 |
< |
qsort((char *)(newmap+vmaplen), newmaplen-vmaplen, |
560 |
< |
sizeof(int), valcmp); |
561 |
< |
mergalphas(newmap, valmap, vmaplen, |
562 |
< |
newmap+vmaplen, newmaplen-vmaplen); |
563 |
< |
} |
564 |
< |
if (valmap != NULL) /* free old map and assign new one */ |
565 |
< |
free((char *)valmap); |
566 |
< |
valmap = newmap; |
567 |
< |
vmaplen = newmaplen; |
568 |
< |
lastalpha = 0; /* set new alpha values */ |
569 |
< |
ccmp[0] = ccmp[1] = ccmp[2] = 256; |
570 |
< |
while (newmaplen--) |
571 |
< |
if (rV.rgb[*newmap][0] == ccmp[0] && |
572 |
< |
rV.rgb[*newmap][1] == ccmp[1] && |
573 |
< |
rV.rgb[*newmap][2] == ccmp[2]) { |
574 |
< |
if (lastalpha >= 255) |
575 |
< |
newmap++; |
576 |
< |
else if (rV.alpha[*newmap] < 255) |
577 |
< |
lastalpha = rV.alpha[*newmap++]; |
578 |
< |
else |
579 |
< |
rV.alpha[*newmap++] = ++lastalpha; |
580 |
< |
} else { |
581 |
< |
ccmp[0] = rV.rgb[*newmap][0]; |
582 |
< |
ccmp[1] = rV.rgb[*newmap][1]; |
583 |
< |
ccmp[2] = rV.rgb[*newmap][2]; |
584 |
< |
if (rV.alpha[*newmap] < 255) |
585 |
< |
lastalpha = rV.alpha[*newmap++]; |
586 |
< |
else |
587 |
< |
rV.alpha[*newmap++] = lastalpha = 1; |
588 |
< |
} |
431 |
> |
setstereobuf(STEREO_BUFFER_RIGHT); |
432 |
> |
glMatrixMode(GL_MODELVIEW); |
433 |
> |
glPushMatrix(); |
434 |
> |
d = -eyesepdist / sqrt(odev.v.hn2); |
435 |
> |
glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1], d*odev.v.hvec[2]); |
436 |
|
} |
437 |
|
|
438 |
|
|
439 |
|
static |
440 |
< |
TMapValues(redo) /* map our values to RGB */ |
594 |
< |
int redo; |
440 |
> |
popright() /* pop off right view */ |
441 |
|
{ |
442 |
< |
int aorg, alen, borg, blen; |
443 |
< |
/* recompute mapping? */ |
444 |
< |
if (redo) |
599 |
< |
rV.tml = rV.bl; |
600 |
< |
/* already done? */ |
601 |
< |
if (rV.tml == rV.tl) |
602 |
< |
return(1); |
603 |
< |
/* compute segments */ |
604 |
< |
aorg = rV.tml; |
605 |
< |
if (rV.tl >= aorg) { |
606 |
< |
alen = rV.tl - aorg; |
607 |
< |
blen = 0; |
608 |
< |
} else { |
609 |
< |
alen = rV.nl - aorg; |
610 |
< |
borg = 0; |
611 |
< |
blen = rV.tl; |
612 |
< |
} |
613 |
< |
/* (re)compute tone mapping? */ |
614 |
< |
if (rV.tml == rV.bl) { |
615 |
< |
tmClearHisto(); |
616 |
< |
tmAddHisto(rV.brt+aorg, alen, 1); |
617 |
< |
if (blen > 0) |
618 |
< |
tmAddHisto(rV.brt+borg, blen, 1); |
619 |
< |
if (tmComputeMapping(0., 0., 0.) != TM_E_OK) |
620 |
< |
return(0); |
621 |
< |
clralphas(); /* restart value list */ |
622 |
< |
rV.drl = rV.bl; /* need to redraw */ |
623 |
< |
} |
624 |
< |
if (tmMapPixels(rV.rgb+aorg, rV.brt+aorg, |
625 |
< |
rV.chr+aorg, alen) != TM_E_OK) |
626 |
< |
return(0); |
627 |
< |
if (blen > 0) |
628 |
< |
tmMapPixels(rV.rgb+borg, rV.brt+borg, |
629 |
< |
rV.chr+borg, blen); |
630 |
< |
setalphas(aorg, alen); /* compute add'l alpha values */ |
631 |
< |
if (blen > 0) |
632 |
< |
setalphas(borg, blen); |
633 |
< |
rV.tml = rV.tl; /* we're all up to date */ |
634 |
< |
return(1); |
442 |
> |
glMatrixMode(GL_MODELVIEW); |
443 |
> |
glPopMatrix(); |
444 |
> |
setstereobuf(STEREO_BUFFER_LEFT); |
445 |
|
} |
446 |
+ |
#endif |
447 |
|
|
448 |
|
|
449 |
|
static int |
450 |
< |
Compost(pct) /* free up some values */ |
640 |
< |
int pct; |
450 |
> |
mytmflags() /* figure out tone mapping flags */ |
451 |
|
{ |
452 |
< |
int nused, nclear, nmapped, ndrawn; |
453 |
< |
/* figure out how many values to clear */ |
454 |
< |
nclear = rV.nl * pct / 100; |
455 |
< |
nused = rV.tl - rV.bl; |
456 |
< |
if (nused <= 0) nused += rV.nl; |
457 |
< |
nclear -= rV.nl - nused; |
458 |
< |
if (nclear <= 0) |
459 |
< |
return(0); |
460 |
< |
if (nclear >= nused) { /* clear them all? */ |
461 |
< |
rV.drl = rV.tml = rV.bl = rV.tl = 0; |
462 |
< |
return(nused); |
463 |
< |
} |
654 |
< |
/* else clear values from bottom */ |
655 |
< |
ndrawn = rV.drl - rV.bl; |
656 |
< |
if (ndrawn < 0) ndrawn += rV.nl; |
657 |
< |
nmapped = rV.tml - rV.bl; |
658 |
< |
if (nmapped < 0) nmapped += rV.nl; |
659 |
< |
rV.bl += nclear; |
660 |
< |
if (rV.bl >= rV.nl) rV.bl -= rV.nl; |
661 |
< |
if (ndrawn < nclear) rV.drl = rV.bl; |
662 |
< |
if (nmapped < nclear) rV.tml = rV.bl; |
663 |
< |
return(nclear); |
452 |
> |
extern char *progname; |
453 |
> |
register char *cp, *tail; |
454 |
> |
/* find basic name */ |
455 |
> |
for (cp = tail = progname; *cp; cp++) |
456 |
> |
if (*cp == '/') |
457 |
> |
tail = cp+1; |
458 |
> |
for (cp = tail; *cp && *cp != '.'; cp++) |
459 |
> |
; |
460 |
> |
if (cp > tail && cp[-1] == 'h') |
461 |
> |
return(TM_F_HUMAN|TM_F_NOSTDERR); |
462 |
> |
else |
463 |
> |
return(TM_F_CAMERA|TM_F_NOSTDERR); |
464 |
|
} |
465 |
|
|
466 |
|
|
508 |
|
if (!mapped) |
509 |
|
return; |
510 |
|
glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]); |
511 |
< |
/* draw each grid line */ |
712 |
< |
glBegin(GL_LINES); |
511 |
> |
glBegin(GL_LINES); /* draw each grid line */ |
512 |
|
gridlines(draw3dline); |
513 |
|
glEnd(); |
514 |
|
} |
515 |
|
|
516 |
|
|
718 |
– |
static int |
719 |
– |
IndexValue(rgba) /* locate a pixel by it's framebuffer value */ |
720 |
– |
register BYTE rgba[4]; |
721 |
– |
{ |
722 |
– |
register int *vp; |
723 |
– |
/* check legality */ |
724 |
– |
if (rgba[3] == 0 || rgba[3] == 255) |
725 |
– |
return(-1); |
726 |
– |
/* borrow a value slot */ |
727 |
– |
rV.rgb[rV.tl][0] = rgba[0]; |
728 |
– |
rV.rgb[rV.tl][1] = rgba[1]; |
729 |
– |
rV.rgb[rV.tl][2] = rgba[2]; |
730 |
– |
rV.alpha[rV.tl] = rgba[3]; |
731 |
– |
/* find it */ |
732 |
– |
vp = (int *)bsearch((char *)&rV.tl, (char *)valmap, vmaplen, |
733 |
– |
sizeof(int), valcmp); |
734 |
– |
if (vp == NULL) |
735 |
– |
return(-1); |
736 |
– |
return(*vp); |
737 |
– |
} |
738 |
– |
|
739 |
– |
|
740 |
– |
static int |
741 |
– |
FindValue(dx, dy) /* find a value on the display */ |
742 |
– |
int dx, dy; |
743 |
– |
{ |
744 |
– |
BYTE rgba[4]; |
745 |
– |
|
746 |
– |
if (dx < 0 || dy < 0 || dx >= odev.hres || dy >= odev.vres) |
747 |
– |
return(-1); |
748 |
– |
glReadPixels(dx, dy, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, rgba); |
749 |
– |
return(IndexValue(rgba)); |
750 |
– |
} |
751 |
– |
|
752 |
– |
|
517 |
|
static |
518 |
|
moveview(dx, dy, mov, orb) /* move our view */ |
519 |
|
int dx, dy, mov, orb; |
520 |
|
{ |
521 |
|
VIEW nv; |
522 |
< |
FVECT odir, v1; |
522 |
> |
FVECT odir, v1, wip; |
523 |
|
double d; |
524 |
|
register int li; |
525 |
|
/* start with old view */ |
526 |
|
copystruct(&nv, &odev.v); |
527 |
|
/* change view direction */ |
528 |
+ |
if (viewray(v1, odir, &odev.v, |
529 |
+ |
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
530 |
+ |
return(0); /* outside view */ |
531 |
|
if (mov | orb) { |
532 |
< |
if ((li = FindValue(dx, dy)) < 0) |
532 |
> |
#ifdef DOBJ |
533 |
> |
d = dobj_trace(v1, odir); /* check objects */ |
534 |
> |
/* is holodeck in front? */ |
535 |
> |
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) |
539 |
> |
VCOPY(wip, rsL.wp[li]); |
540 |
> |
else if (d < .99*FHUGE) /* object is closer */ |
541 |
> |
VSUM(wip, nv.vp, odir, d); |
542 |
> |
else /* nothing visible */ |
543 |
> |
return(0); |
544 |
> |
#else |
545 |
> |
if ((li = smFindSamp(v1, odir)) < 0) |
546 |
|
return(0); /* not on window */ |
547 |
< |
VSUM(odir, rV.wp[li], nv.vp, -1.); |
548 |
< |
} else { |
549 |
< |
if (viewray(nv.vp, nv.vdir, &odev.v, |
550 |
< |
(dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) |
551 |
< |
return(0); /* outside view */ |
772 |
< |
} |
547 |
> |
VCOPY(wip, rsL.wp[li]); |
548 |
> |
#endif |
549 |
> |
VSUM(odir, wip, nv.vp, -1.); |
550 |
> |
} else |
551 |
> |
VCOPY(nv.vdir, odir); |
552 |
|
if (orb && mov) { /* orbit left/right */ |
553 |
|
spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov); |
554 |
< |
VSUM(nv.vp, rV.wp[li], odir, -1.); |
554 |
> |
VSUM(nv.vp, wip, odir, -1.); |
555 |
|
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
556 |
|
} else if (orb) { /* orbit up/down */ |
557 |
|
fcross(v1, odir, nv.vup); |
558 |
|
if (normalize(v1) == 0.) |
559 |
|
return(0); |
560 |
|
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
561 |
< |
VSUM(nv.vp, rV.wp[li], odir, -1.); |
561 |
> |
VSUM(nv.vp, wip, odir, -1.); |
562 |
|
spinvector(nv.vdir, nv.vdir, v1, d); |
563 |
|
} else if (mov) { /* move forward/backward */ |
564 |
|
d = MOVPCT/100. * mov; |
583 |
|
{ |
584 |
|
int movdir = MOVDIR(ebut->button); |
585 |
|
int movorb = MOVORB(ebut->state); |
586 |
+ |
int qlevel = 99; |
587 |
+ |
time_t lasttime, thistime; |
588 |
+ |
int nframes; |
589 |
|
Window rootw, childw; |
590 |
|
int rootx, rooty, wx, wy; |
591 |
|
unsigned int statemask; |
592 |
|
|
593 |
|
XNoOp(ourdisplay); |
594 |
|
|
595 |
+ |
lasttime = time(0); nframes = 0; |
596 |
|
while (!XCheckMaskEvent(ourdisplay, |
597 |
|
ButtonReleaseMask, levptr(XEvent))) { |
598 |
|
|
602 |
|
|
603 |
|
if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) { |
604 |
|
sleep(1); |
605 |
+ |
lasttime++; |
606 |
|
continue; |
607 |
|
} |
608 |
+ |
#ifdef STEREO |
609 |
+ |
pushright(); |
610 |
+ |
glClear(GL_COLOR_BUFFER_BIT); |
611 |
|
draw_grids(); |
612 |
< |
dev_flush(); |
612 |
> |
smUpdate(&vwright, qlevel); |
613 |
> |
#ifdef DOBJ |
614 |
> |
dobj_render(); |
615 |
> |
#endif |
616 |
> |
popright(); |
617 |
> |
#endif |
618 |
> |
glClear(GL_COLOR_BUFFER_BIT); |
619 |
> |
draw_grids(); |
620 |
> |
smUpdate(&odev.v, qlevel); |
621 |
> |
#ifdef DOBJ |
622 |
> |
dobj_render(); |
623 |
> |
#endif |
624 |
> |
glFlush(); |
625 |
> |
checkglerr("moving view"); |
626 |
> |
nframes++; |
627 |
> |
thistime = time(0); |
628 |
> |
if (thistime - lasttime >= 3 || |
629 |
> |
nframes > (int)(3*3*TARGETFPS)) { |
630 |
> |
qlevel = thistime<=lasttime ? 1000 : |
631 |
> |
(int)((double)nframes/(thistime-lasttime) |
632 |
> |
/ TARGETFPS * qlevel + 0.5); |
633 |
> |
lasttime = thistime; nframes = 0; |
634 |
> |
if (qlevel > 99) { |
635 |
> |
if (qlevel > 300) { /* put on the brakes */ |
636 |
> |
sleep(1); |
637 |
> |
lasttime++; |
638 |
> |
} |
639 |
> |
qlevel = 99; |
640 |
> |
} else if (qlevel < 1) |
641 |
> |
qlevel = 1; |
642 |
> |
} |
643 |
|
} |
644 |
|
if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */ |
645 |
|
movdir = MOVDIR(levptr(XButtonReleasedEvent)->button); |
646 |
|
wx = levptr(XButtonReleasedEvent)->x; |
647 |
|
wy = levptr(XButtonReleasedEvent)->y; |
648 |
|
moveview(wx, odev.vres-1-wy, movdir, movorb); |
649 |
+ |
} |
650 |
+ |
} |
651 |
+ |
|
652 |
+ |
|
653 |
+ |
static |
654 |
+ |
setglpersp(vp) /* set perspective view in GL */ |
655 |
+ |
register VIEW *vp; |
656 |
+ |
{ |
657 |
+ |
double d, xmin, xmax, ymin, ymax; |
658 |
+ |
|
659 |
+ |
if (mindpth >= maxdpth) { |
660 |
+ |
dev_zmin = 0.1; |
661 |
+ |
dev_zmax = 100.; |
662 |
|
} else { |
663 |
< |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
664 |
< |
redraw(); |
663 |
> |
dev_zmin = 0.5*mindpth; |
664 |
> |
dev_zmax = 1.5*maxdpth; |
665 |
> |
if (dev_zmin > dev_zmax/100.) |
666 |
> |
dev_zmin = dev_zmax/100.; |
667 |
|
} |
668 |
< |
dev_flush(); |
668 |
> |
if (odev.v.vfore > FTINY) |
669 |
> |
dev_zmin = odev.v.vfore; |
670 |
> |
if (odev.v.vaft > FTINY) |
671 |
> |
dev_zmax = odev.v.vaft; |
672 |
> |
if (dev_zmin < dev_zmax/5000.) |
673 |
> |
dev_zmin = dev_zmax/5000.; |
674 |
> |
xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz); |
675 |
> |
xmin = -xmax; |
676 |
> |
d = odev.v.hoff * (xmax - xmin); |
677 |
> |
xmin += d; xmax += d; |
678 |
> |
ymax = dev_zmin * tan(PI/180./2. * odev.v.vert); |
679 |
> |
ymin = -ymax; |
680 |
> |
d = odev.v.voff * (ymax - ymin); |
681 |
> |
ymin += d; ymax += d; |
682 |
> |
/* set view matrix */ |
683 |
> |
glMatrixMode(GL_PROJECTION); |
684 |
> |
glLoadIdentity(); |
685 |
> |
glFrustum(xmin, xmax, ymin, ymax, dev_zmin, dev_zmax); |
686 |
> |
gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2], |
687 |
> |
odev.v.vp[0] + odev.v.vdir[0], |
688 |
> |
odev.v.vp[1] + odev.v.vdir[1], |
689 |
> |
odev.v.vp[2] + odev.v.vdir[2], |
690 |
> |
odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]); |
691 |
|
} |
692 |
|
|
693 |
|
|
694 |
|
static |
695 |
+ |
wipeclean() /* prepare for redraw */ |
696 |
+ |
{ |
697 |
+ |
#ifdef STEREO |
698 |
+ |
setstereobuf(STEREO_BUFFER_RIGHT); |
699 |
+ |
glClear(GL_DEPTH_BUFFER_BIT); |
700 |
+ |
setstereobuf(STEREO_BUFFER_LEFT); |
701 |
+ |
#endif |
702 |
+ |
glClear(GL_DEPTH_BUFFER_BIT); |
703 |
+ |
smClean(); |
704 |
+ |
} |
705 |
+ |
|
706 |
+ |
|
707 |
+ |
static |
708 |
|
getkey(ekey) /* get input key */ |
709 |
|
register XKeyPressedEvent *ekey; |
710 |
|
{ |
735 |
|
inpresflags |= DFL(DC_RESUME); |
736 |
|
return; |
737 |
|
case CTRL('R'): /* redraw screen */ |
738 |
< |
TMapValues(1); |
872 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
873 |
< |
redraw(); |
738 |
> |
wipeclean(); |
739 |
|
return; |
740 |
|
case CTRL('L'): /* refresh from server */ |
741 |
|
if (inpresflags & DFL(DC_REDRAW)) |
743 |
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
744 |
|
glDisable(GL_DEPTH_TEST); |
745 |
|
draw_grids(); |
746 |
+ |
#ifdef STEREO |
747 |
+ |
pushright(); |
748 |
+ |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
749 |
+ |
draw_grids(); |
750 |
+ |
popright(); |
751 |
+ |
#endif |
752 |
|
glEnable(GL_DEPTH_TEST); |
753 |
|
glFlush(); |
754 |
< |
Compost(100); /* get rid of old values */ |
754 |
> |
smInit(rsL.max_samp); /* get rid of old values */ |
755 |
|
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
756 |
+ |
rayqleft = 0; /* hold off update */ |
757 |
|
return; |
758 |
|
case 'K': /* kill rtrace process(es) */ |
759 |
|
inpresflags |= DFL(DC_KILL); |
778 |
|
fixwindow(eexp) /* repair damage to window */ |
779 |
|
register XExposeEvent *eexp; |
780 |
|
{ |
781 |
< |
if (odev.hres == 0 || odev.vres == 0) /* first exposure */ |
781 |
> |
if (odev.hres == 0 | odev.vres == 0) { /* first exposure */ |
782 |
|
resizewindow((XConfigureEvent *)eexp); |
783 |
< |
if (eexp->width == odev.hres && eexp->height == odev.vres) |
912 |
< |
TMapValues(1); |
913 |
< |
if (!eexp->count) { |
914 |
< |
glClear(GL_DEPTH_BUFFER_BIT); |
915 |
< |
redraw(); |
783 |
> |
return; |
784 |
|
} |
785 |
+ |
if (eexp->count) /* wait for final exposure */ |
786 |
+ |
return; |
787 |
+ |
wipeclean(); /* clear depth */ |
788 |
|
} |
789 |
|
|
790 |
|
|
792 |
|
resizewindow(ersz) /* resize window */ |
793 |
|
register XConfigureEvent *ersz; |
794 |
|
{ |
795 |
+ |
glViewport(0, 0, ersz->width, ersz->height); |
796 |
+ |
|
797 |
|
if (ersz->width == odev.hres && ersz->height == odev.vres) |
798 |
|
return; |
799 |
|
|
802 |
|
|
803 |
|
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
804 |
|
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
932 |
– |
|
933 |
– |
setGLview(); |
805 |
|
|
806 |
|
inpresflags |= DFL(DC_SETVIEW); |
807 |
|
} |