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 |
|
* Convert Radiance -> OpenGL surfaces. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "radogl.h" |
11 |
|
|
12 |
|
#ifndef NSLICES |
28 |
|
#define NOPOLY() if (curpolysize) {glEnd(); curpolysize = 0;} else |
29 |
|
|
30 |
|
|
31 |
+ |
void |
32 |
|
setmaterial(mp, cent, ispoly) /* prepare for new material */ |
33 |
|
register MATREC *mp; |
34 |
|
FVECT cent; |
37 |
|
if (mp != curmat && domats) { |
38 |
|
NOPOLY(); |
39 |
|
domatobj(curmat = mp, cent); |
40 |
< |
} else if (!ispoly) |
40 |
> |
} else if (!ispoly) { |
41 |
|
NOPOLY(); |
42 |
+ |
} |
43 |
|
} |
44 |
|
|
45 |
|
|
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
< |
static |
84 |
> |
static void |
85 |
|
glu_error(en) /* report an error as a warning */ |
86 |
|
GLenum en; |
87 |
|
{ |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
< |
static |
93 |
> |
static void |
94 |
> |
myCombine(coords, vertex_data, weight, dataOut) |
95 |
> |
register GLdouble coords[3]; |
96 |
> |
GLdouble *vertex_data[4]; |
97 |
> |
GLfloat weight[4]; |
98 |
> |
GLdouble **dataOut; |
99 |
> |
{ |
100 |
> |
register GLdouble *newvert; |
101 |
> |
|
102 |
> |
newvert = (GLdouble *)malloc(3*sizeof(GLdouble)); |
103 |
> |
if (newvert == NULL) |
104 |
> |
error(SYSTEM, "out of memory in myCombine"); |
105 |
> |
VCOPY(newvert, coords); /* no data, just coordinates */ |
106 |
> |
*dataOut = newvert; |
107 |
> |
} |
108 |
> |
|
109 |
> |
|
110 |
> |
static void |
111 |
|
newtess() /* allocate GLU tessellation object */ |
112 |
|
{ |
113 |
|
if ((gluto = gluNewTess()) == NULL) |
115 |
|
gluTessCallback(gluto, GLU_TESS_BEGIN, glBegin); |
116 |
|
gluTessCallback(gluto, GLU_TESS_VERTEX, glVertex3dv); |
117 |
|
gluTessCallback(gluto, GLU_TESS_END, glEnd); |
118 |
< |
gluTessCallback(gluto, GLU_TESS_ERROR, glu_error); |
118 |
> |
gluTessCallback(gluto, GLU_TESS_COMBINE, (void*)myCombine); |
119 |
> |
gluTessCallback(gluto, GLU_TESS_ERROR, (void*)glu_error); |
120 |
|
gluTessProperty(gluto, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
< |
static |
124 |
> |
static void |
125 |
|
newquadric() /* allocate GLU quadric structure */ |
126 |
|
{ |
127 |
|
if ((gluqo = gluNewQuadric()) == NULL) |
128 |
|
error(INTERNAL, "gluNewQuadric failed"); |
129 |
|
gluQuadricDrawStyle(gluqo, GLU_FILL); |
130 |
< |
gluQuadricCallback(gluqo, GLU_ERROR, glu_error); |
130 |
> |
gluQuadricCallback(gluqo, GLU_ERROR, (void*)glu_error); |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
+ |
int |
135 |
|
o_face(o) /* convert a face */ |
136 |
|
register OBJREC *o; |
137 |
|
{ |
139 |
|
FVECT norm, cent; |
140 |
|
register int i; |
141 |
|
|
142 |
< |
if (o->oargs.nfargs < 9 | o->oargs.nfargs % 3) |
142 |
> |
if ((o->oargs.nfargs < 9) | (o->oargs.nfargs % 3)) |
143 |
|
objerror(o, USER, "bad # real arguments"); |
144 |
|
area = polyarea(cent, norm, o->oargs.nfargs/3, (FVECT *)o->oargs.farg); |
145 |
|
if (area <= FTINY) |
146 |
< |
return; |
146 |
> |
return(0); |
147 |
|
if (dolights) /* check for source */ |
148 |
< |
doflatsrc(o->os, cent, norm, area); |
149 |
< |
setmaterial(o->os, cent, 1); /* set material */ |
148 |
> |
doflatsrc((MATREC *)o->os, cent, norm, area); |
149 |
> |
setmaterial((MATREC *)o->os, cent, 1); /* set material */ |
150 |
|
if (o->oargs.nfargs/3 != curpolysize) { |
151 |
|
if (curpolysize) glEnd(); |
152 |
|
curpolysize = o->oargs.nfargs/3; |
178 |
|
(GLdouble)o->oargs.farg[3*i+1], |
179 |
|
(GLdouble)o->oargs.farg[3*i+2]); |
180 |
|
} |
181 |
+ |
return(0); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
+ |
void |
186 |
|
surfclean() /* clean up surface routines */ |
187 |
|
{ |
188 |
|
setmaterial(NULL, NULL, 0); |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
+ |
int |
202 |
|
o_sphere(o) /* convert a sphere */ |
203 |
|
register OBJREC *o; |
204 |
|
{ |
209 |
|
o->otype = o->otype==OBJ_SPHERE ? OBJ_BUBBLE : OBJ_SPHERE; |
210 |
|
o->oargs.farg[3] = -o->oargs.farg[3]; |
211 |
|
} else if (o->oargs.farg[3] <= FTINY) |
212 |
< |
return; |
212 |
> |
return(0); |
213 |
|
if (dolights) |
214 |
< |
dosphsrc(o->os, o->oargs.farg, |
214 |
> |
dosphsrc((MATREC *)o->os, o->oargs.farg, |
215 |
|
PI*o->oargs.farg[3]*o->oargs.farg[3]); |
216 |
< |
setmaterial(o->os, o->oargs.farg, 0); |
216 |
> |
setmaterial((MATREC *)o->os, o->oargs.farg, 0); |
217 |
|
if (gluqo == NULL) newquadric(); |
218 |
|
glu_rout = "making sphere"; |
219 |
|
gluQuadricOrientation(gluqo, |
225 |
|
(GLdouble)o->oargs.farg[2]); |
226 |
|
gluSphere(gluqo, (GLdouble)o->oargs.farg[3], NSLICES, NSTACKS); |
227 |
|
glPopMatrix(); |
228 |
+ |
return(0); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
+ |
int |
233 |
|
o_cone(o) /* convert a cone or cylinder */ |
234 |
|
register OBJREC *o; |
235 |
|
{ |
237 |
|
FVECT cent; |
238 |
|
register int iscyl; |
239 |
|
|
240 |
< |
iscyl = o->otype==OBJ_CYLINDER | o->otype==OBJ_TUBE; |
240 |
> |
iscyl = (o->otype==OBJ_CYLINDER) | (o->otype==OBJ_TUBE); |
241 |
|
if (o->oargs.nfargs != (iscyl ? 7 : 8)) |
242 |
< |
objerror(o, "bad # real arguments"); |
242 |
> |
objerror(o, USER, "bad # real arguments"); |
243 |
|
if (o->oargs.farg[6] < -FTINY) { |
244 |
|
o->oargs.farg[6] = -o->oargs.farg[6]; |
245 |
|
if (iscyl) |
253 |
|
} else if (!iscyl && o->oargs.farg[7] < -FTINY) |
254 |
|
objerror(o, USER, "illegal radii"); |
255 |
|
if (o->oargs.farg[6] <= FTINY && (iscyl || o->oargs.farg[7] <= FTINY)) |
256 |
< |
return; |
257 |
< |
if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ |
258 |
< |
o->oargs.farg[6] = 0.; |
259 |
< |
if (!iscyl && o->oargs.farg[7] < 0.) |
260 |
< |
o->oargs.farg[7] = 0.; |
256 |
> |
return(0); |
257 |
> |
if (!iscyl) { |
258 |
> |
if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ |
259 |
> |
o->oargs.farg[6] = 0.; |
260 |
> |
if (o->oargs.farg[7] < 0.) |
261 |
> |
o->oargs.farg[7] = 0.; |
262 |
> |
} |
263 |
> |
h = sqrt(dist2(o->oargs.farg,o->oargs.farg+3)); |
264 |
> |
if (h <= FTINY) |
265 |
> |
return(0); |
266 |
|
cent[0] = .5*(o->oargs.farg[0] + o->oargs.farg[3]); |
267 |
|
cent[1] = .5*(o->oargs.farg[1] + o->oargs.farg[4]); |
268 |
|
cent[2] = .5*(o->oargs.farg[2] + o->oargs.farg[5]); |
269 |
< |
setmaterial(o->os, cent, 0); |
269 |
> |
setmaterial((MATREC *)o->os, cent, 0); |
270 |
|
if (gluqo == NULL) newquadric(); |
271 |
|
glu_rout = "making cylinder"; |
272 |
< |
gluQuadricOrientation(gluqo, o->otype==OBJ_CUP | o->otype==OBJ_TUBE ? |
272 |
> |
gluQuadricOrientation(gluqo, (o->otype==OBJ_CUP) | (o->otype==OBJ_TUBE) ? |
273 |
|
GLU_INSIDE : GLU_OUTSIDE); |
274 |
|
gluQuadricNormals(gluqo, GLU_SMOOTH); |
275 |
|
glMatrixMode(GL_MODELVIEW); |
278 |
|
glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1], |
279 |
|
(GLdouble)o->oargs.farg[2]); |
280 |
|
/* compute height & rotation angle */ |
251 |
– |
h = sqrt(dist2(o->oargs.farg,o->oargs.farg+3)); |
252 |
– |
if (h <= FTINY) |
253 |
– |
return; |
281 |
|
x1 = o->oargs.farg[1] - o->oargs.farg[4]; |
282 |
|
y1 = o->oargs.farg[3] - o->oargs.farg[0]; |
283 |
|
/* z1 = 0; */ |
284 |
< |
d = 180./PI * asin(sqrt(x1*x1 + y1*y1) / h); |
284 |
> |
d = x1*x1 + y1*y1; |
285 |
> |
if (d <= FTINY*FTINY) |
286 |
> |
x1 = 1.; |
287 |
> |
else |
288 |
> |
d = 180./PI * asin(sqrt(d) / h); |
289 |
|
if (o->oargs.farg[5] < o->oargs.farg[2]) |
290 |
|
d = 180. - d; |
291 |
|
if (d > FTINY) |
293 |
|
gluCylinder(gluqo, o->oargs.farg[6], o->oargs.farg[iscyl ? 6 : 7], |
294 |
|
h, NSLICES, 1); |
295 |
|
glPopMatrix(); |
296 |
+ |
return(0); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
+ |
int |
301 |
|
o_ring(o) /* convert a ring */ |
302 |
|
register OBJREC *o; |
303 |
|
{ |
304 |
< |
double x1, y1, d; |
304 |
> |
double x1, y1, d, h; |
305 |
|
|
306 |
|
if (o->oargs.nfargs != 8) |
307 |
< |
objerror(o, "bad # real arguments"); |
307 |
> |
objerror(o, USER, "bad # real arguments"); |
308 |
|
if (o->oargs.farg[7] < o->oargs.farg[6]) { |
309 |
|
register double d = o->oargs.farg[7]; |
310 |
|
o->oargs.farg[7] = o->oargs.farg[6]; |
315 |
|
if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ |
316 |
|
o->oargs.farg[6] = 0.; |
317 |
|
if (o->oargs.farg[7] - o->oargs.farg[6] <= FTINY) |
318 |
< |
return; |
318 |
> |
return(0); |
319 |
> |
h = VLEN(o->oargs.farg+3); |
320 |
> |
if (h <= FTINY) |
321 |
> |
return(0); |
322 |
|
if (dolights) |
323 |
< |
doflatsrc(o->os, o->oargs.farg, o->oargs.farg+3, |
323 |
> |
doflatsrc((MATREC *)o->os, o->oargs.farg, o->oargs.farg+3, |
324 |
|
PI*(o->oargs.farg[7]*o->oargs.farg[7] - |
325 |
|
o->oargs.farg[6]*o->oargs.farg[6])); |
326 |
< |
setmaterial(o->os, o->oargs.farg, 0); |
326 |
> |
setmaterial((MATREC *)o->os, o->oargs.farg, 0); |
327 |
|
if (gluqo == NULL) newquadric(); |
328 |
|
glu_rout = "making disk"; |
329 |
|
gluQuadricOrientation(gluqo, GLU_OUTSIDE); |
333 |
|
glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1], |
334 |
|
(GLdouble)o->oargs.farg[2]); |
335 |
|
/* compute rotation angle */ |
300 |
– |
d = VLEN(o->oargs.farg+3); |
301 |
– |
if (d <= FTINY) |
302 |
– |
return; |
336 |
|
x1 = -o->oargs.farg[4]; |
337 |
|
y1 = o->oargs.farg[3]; |
338 |
|
/* z1 = 0; */ |
339 |
< |
d = 180./PI * asin(sqrt(x1*x1 + y1*y1) / d); |
339 |
> |
d = x1*x1 + y1*y1; |
340 |
> |
if (d <= FTINY*FTINY) |
341 |
> |
x1 = 1.; |
342 |
> |
else |
343 |
> |
d = 180./PI * asin(sqrt(d) / h); |
344 |
|
if (o->oargs.farg[5] < 0.) |
345 |
|
d = 180. - d; |
346 |
|
if (d > FTINY) |
347 |
|
glRotated(d, (GLdouble)x1, (GLdouble)y1, 0.); |
348 |
|
gluDisk(gluqo, o->oargs.farg[6], o->oargs.farg[7], NSLICES, 1); |
349 |
|
glPopMatrix(); |
350 |
+ |
return(0); |
351 |
|
} |