Newer
Older
for(i = 0; i < MAXPTSIZE*2; i++)
nsized[i] = 0;
glBegin( GL_POINTS );
for(sl = slhead; sl != NULL; sl = sl->next) {
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
for(i = 0, p = sl->specks; i < sl->nspecks; i+=skip, p= NextSpeck(p, sl, skip)) {
int lum, myalpha;
float dist = VDOT( &p->p, &fwd ) + fwdd;
if(dist <= 0) /* Behind eye plane */
continue;
if(usethresh & p->rgba)
continue;
if(useclip &&
(p->p.x[0] < clipp0.x[0] ||
p->p.x[0] > clipp1.x[0] ||
p->p.x[1] < clipp0.x[1] ||
p->p.x[1] > clipp1.x[1] ||
p->p.x[2] < clipp0.x[2] ||
p->p.x[2] > clipp1.x[2]))
continue;
lum = 256 * plum * p->size / (dist*dist);
if(lum < pxmin) {
if(lum <= faintrand[(i*i+i) /*randix++*/ & 0xFF])
continue;
pxsize = 1;
myalpha = pxmin;
} else if(lum < 256) {
pxsize = 1;
myalpha = lum;
} else if(lum < pxmax) {
pxsize = apxsize[lum>>8];
myalpha = lum / (pxsize*pxsize);
} else {
/* Could use a polygon here, instead. */
pxsize = st->plarge;
myalpha = 255;
}
if(pxsize < 1 || pxsize > 6 || myalpha <= 0 || myalpha > 255) {
static int oops;
oops++;
}
if(myalpha < 0 || myalpha > 255 || invgamma[myalpha] <= 0 || invgamma[myalpha] > 255) {
static int oops2;
oops2++;
}
rgba = RGBALPHA( p->rgba&~THRESHBIT, invgamma[myalpha] & 0xFC );
if(pxsize != oldpxsize) {
if(nsized[pxsize] >= PERBUCKET) {
glEnd();
glPointSize(pxsize);
glBegin( GL_POINTS );
dumpcpoints( &sized[pxsize][0], PERBUCKET );
nsized[pxsize] = 0;
oldpxsize = pxsize;
glColor4ubv( (GLubyte *)&rgba );
prevrgba = rgba;
glVertex3fv( &p->p.x[0] );
} else {
struct cpoint *cp = &sized[pxsize][nsized[pxsize]];
cp->rgba = rgba;
cp->p = p->p;
nsized[pxsize]++;
}
} else {
/* same as current pointsize */
if(rgba != prevrgba) {
glColor4ubv( (GLubyte *)&rgba );
prevrgba = rgba;
}
glVertex3fv( &p->p.x[0] );
}
}
}
glEnd();
for(i = 0; i < MAXPTSIZE; i++) {
if(nsized[i] > 0) {
glPointSize( i );
glBegin( GL_POINTS );
dumpcpoints( &sized[i][0], nsized[i] );
glEnd();
}
}
} else {
/*
* Render using anti-aliased points
*/
static unsigned char apxsize[(MAXPTSIZE*2)*(MAXPTSIZE*2)];
unsigned char faintrand[256];
static float percoverage[MAXPTSIZE*2];
static int needMesaHack = 0;
int pxsize, oldpxsize;
int pxmin, pxmax;
int minsize, minalpha;
pxmin = (256 * (2*2)) * st->pfaint;
if(st->plarge > MAXPTSIZE*2) st->plarge = MAXPTSIZE*2;
pxmax = (256 * (2*2)) * st->plarge * st->plarge;
if(apxsize[1] == 0) {
char *version = (char *)glGetString( GL_VERSION );
/* Hack: MESA doesn't handle small anti-aliased points well;
* force them all to be of size 1.0 or 2.0 (i.e. pxsize == 2 or 4),
* and non-antialiased.
*/
if(getenv("MESAHACK") != NULL)
needMesaHack = atoi(getenv("MESAHACK"));
else if(version &&
(!strncmp(version, "CRIME", 5) || !strncmp(version, "IR", 2)))
needMesaHack = 0; /* O2 & IR: nice anti-aliased points */
else
needMesaHack = -1; /* IMPACT (& others?): ugly AA points */
for(i=0; i<COUNT(apxsize); i++) {
apxsize[i] = (int)ceil(sqrtf(i+1));
if(needMesaHack>0) {
if(apxsize[i] <= 2) apxsize[i] = 2;
else if(needMesaHack<2 && apxsize[i] <= 4) apxsize[i] = 4;
}
}
for(i = 1; i < MAXPTSIZE*2; i++) {
percoverage[i] = 1.0 / (i*i);
if(needMesaHack>0) {
if(i <= 2) percoverage[i] = .25;
else if(needMesaHack<2 && i <= 4) percoverage[i] = .0625;
}
}
percoverage[0] = 1.0;
if(needMesaHack < 0)
percoverage[1] = 0.25; /* if gfx treats psize 0.5 == 1.0 */
}
minsize = apxsize[ pxmin >> 8 ];
minalpha = pxmin * percoverage[ minsize ];
for(i = 0; i < 256; i++)
faintrand[i] = randskip[i] * st->pfaint;
/* Render using antialiased points */
glEnable( GL_POINT_SMOOTH );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, additive_blend ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA );
prevrgba = 0;
prevsize = 0;
sl = slhead;
pxsize = 2;
oldpxsize = 99;
glPointSize( pxsize );
glColor4ubv( (GLubyte *)&rgba );
for(i = 0; i < MAXPTSIZE*2; i++)
nsized[i] = 0;
glBegin( GL_POINTS );
for(sl = slhead; sl != NULL; sl = sl->next) {
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
int lum, myalpha;
float dist, dist2, dx, dy, dz;
if(usethresh & p->rgba)
continue;
if(useclip &&
(p->p.x[0] < clipp0.x[0] ||
p->p.x[0] > clipp1.x[0] ||
p->p.x[1] < clipp0.x[1] ||
p->p.x[1] > clipp1.x[1] ||
p->p.x[2] < clipp0.x[2] ||
p->p.x[2] > clipp1.x[2]))
continue;
switch(fademodel) {
case F_PLANAR:
dist = VDOT( &p->p, &fwd ) + fwdd;
if(dist <= 0) /* Behind eye plane */
continue;
dist2 = dist*dist;
break;
case F_CONSTANT:
dist2 = orthodist2;
break;
case F_SPHERICAL:
dx = p->p.x[0]-eyepoint.x[0];
dy = p->p.x[1]-eyepoint.x[1];
dz = p->p.x[2]-eyepoint.x[2];
dist2 = dx*dx + dy*dy + dz*dz;
break;
case F_LREGION: /* not impl yet */
dist = VDOT( &p->p, &fwd ) + fwdd;
if(dist <= 0) /* Behind eye plane */
continue;
dx = p->p.x[0] - fadecen.x[0];
dy = p->p.x[1] - fadecen.x[1];
dz = p->p.x[2] - fadecen.x[2];
dist2 = dist * st->fadeknee2
/ (1 + (dx*dx + dy*dy + dz*dz) * faderball2);
break;
case F_LINEAR:
dist = VDOT( &p->p, &fwd ) + fwdd;
if(dist <= 0) /* Behind eye plane */
continue;
dist2 = dist * st->fadeknee2;
break;
case F_KNEE2:
dx = p->p.x[0]-eyepoint.x[0];
dy = p->p.x[1]-eyepoint.x[1];
dz = p->p.x[2]-eyepoint.x[2];
dist2 = dx*dx + dy*dy + dz*dz;
if(dist2 > knee2dist2)
dist2 *= 1 + steep2knee2 * (dist2 - knee2dist2);
break;
case F_KNEE12:
dx = p->p.x[0]-eyepoint.x[0];
dy = p->p.x[1]-eyepoint.x[1];
dz = p->p.x[2]-eyepoint.x[2];
dist2 = dx*dx + dy*dy + dz*dz;
if(dist2 < knee1dist2)
dist2 = knee1dist2;
else if(dist2 > knee2dist2)
dist2 *= 1 + steep2knee2 * (dist2 - knee2dist2);
break;
}
lum = (256 * (2*2)) * plum * p->size / dist2;
if(lum <= pxmin) {
if(lum <= faintrand[(i*i+i) /*randix++*/ & 0xFF])
continue;
pxsize = minsize;
myalpha = minalpha;
} else if(lum < pxmax) {
pxsize = apxsize[lum>>8];
myalpha = lum * percoverage[pxsize];
} else {
/* Could use a polygon here, instead. */
pxsize = 2 * st->plarge;
myalpha = 255;
}
if(pxsize < 1 || pxsize >= MAXPTSIZE*2 || myalpha <= 0 || myalpha > 255) {
static int oops;
oops++;
pxsize = MAXPTSIZE*2 - 1;
myalpha = 255;
}
rgba = RGBALPHA( p->rgba&~THRESHBIT, invgamma[myalpha] & 0xFC );
if(pxsize != oldpxsize) {
if(nsized[pxsize] >= PERBUCKET) {
glEnd();
if(needMesaHack>0 && (pxsize <= 4) != (oldpxsize <= 4)) {
if(pxsize <= 4) glDisable( GL_POINT_SMOOTH );
else glEnable( GL_POINT_SMOOTH );
}
glPointSize(.5*pxsize);
glBegin( GL_POINTS );
dumpcpoints( &sized[pxsize][0], PERBUCKET );
nsized[pxsize] = 0;
oldpxsize = pxsize;
glColor4ubv( (GLubyte *)&rgba );
prevrgba = rgba;
glVertex3fv( &p->p.x[0] );
} else {
struct cpoint *cp = &sized[pxsize][nsized[pxsize]];
cp->rgba = rgba;
cp->p = p->p;
nsized[pxsize]++;
}
} else {
/* same as current pointsize */
if(rgba != prevrgba) {
glColor4ubv( (GLubyte *)&rgba );
prevrgba = rgba;
}
glVertex3fv( &p->p.x[0] );
}
}
}
glEnd();
if(needMesaHack>0)
glDisable( GL_POINT_SMOOTH );
for(i = 0; i < MAXPTSIZE*2; i++) {
if(needMesaHack>0 && i == 4)
glEnable( GL_POINT_SMOOTH );
if(nsized[i] > 0) {
glPointSize( .5*i );
glBegin( GL_POINTS );
dumpcpoints( &sized[i][0], nsized[i] );
glEnd();
}
}
}
}
if(st->usetext && st->textsize != 0) {
int cment = -1;
glColor3f(1,1,1);
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
for(sl = slhead, slno = 1; sl != NULL; sl = sl->next, slno++) {
if(sl->text != NULL && (p = sl->specks) != NULL) {
float dist = VDOT( &p->p, &fwd ) + fwdd;
float tsize;
if(dist <= 0)
continue;
if(inpick) glLoadName(slno);
tsize = st->textsize * p->size;
if(tsize < dist * (radperpix * st->textmin)) {
/* Could draw a stub here -- a simple line segment of
* about the right length
*/
Point ep;
/* extract top row of Ttext -- this is the unit screen-space X
* vector, expressed in world coords. Scale to suit.
*/
vcomb( &ep,
p->size * sfStrWidth(sl->text), (Point *)&Ttext.m[0],
1, &p->p );
if(p->rgba != cment) {
if((unsigned int)p->rgba >= st->textncmap)
glColor3f( 1, 1, 1 );
else
glColor3ubv( (GLubyte *)&st->textcmap[ p->rgba ].cooked );
cment = p->rgba;
}
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
glBegin( GL_LINES );
glVertex3fv( p->p.x );
glVertex3fv( ep.x );
glEnd();
continue;
}
/* Otherwise, it's big enough to see -- draw actual text */
glPushMatrix();
glTranslatef( p->p.x[0], p->p.x[1], p->p.x[2] );
if(st->usetextaxes) {
static unsigned char col[3][3] = {255,0,0, 0,255,0, 0,0,255};
static float pos[3][3] = {1,0,0, 0,1,0, 0,0,1};
glPushMatrix();
glScalef( tsize, tsize, tsize );
glBegin(GL_LINES);
for(k = 0; k < 3; k++) {
glColor3ubv( &col[k][0] );
glVertex3f(0,0,0);
glVertex3fv( &pos[k][0] );
}
glEnd();
glPopMatrix();
}
if(p->rgba != cment || st->usetextaxes) {
if((unsigned int)p->rgba >= st->textncmap)
glColor3f( 1, 1, 1 );
else
glColor3ubv( (GLubyte *)&st->textcmap[ p->rgba ].cooked );
cment = p->rgba;
}
glMultMatrixf( Ttext.m );
sfStrDraw( sl->text, p->size, NULL );
glPopMatrix();
}
}
}
if(inpick) glLoadName(0);
if(st->usemeshes) {
struct mesh *m;
int texturing = 0;
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, additive_blend ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA );
glColor4f(1, 1, 1, st->alpha);
for(m = st->staticmeshes; m != NULL; m = m->next)
specks_draw_mesh(st, m, &texturing);
if(texturing) txbind(NULL, NULL);
}
for(i = 0; i < 6; i++) /* in case clipbox was enabled when we began */
glDisable( GL_CLIP_PLANE0 + i );
glColor4ub(255,255,255,255);
glDisable( GL_BLEND );
glEnable( GL_DEPTH_TEST ); /* was already enabled */
glDepthMask( GL_TRUE );
}
void specks_draw_ellipsoids( struct stuff *st, struct specklist *asl )
{
struct specklist *sl;
struct speck *sp;
for(sl = asl; sl != NULL; sl = sl->next) {
if(sl->special != ELLIPSOIDS || sl->text != NULL)
continue;
}
}
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
void specks_draw_mesh( struct stuff *st, register struct mesh *m, int *texturing )
{
int u, v, prev, cur;
int usetx;
usetx = (st->usetextures && m->tx != NULL
&& m->txno >= 0 && m->txno < st->ntextures
&& st->textures[m->txno] != NULL);
txbind( usetx ? st->textures[m->txno] : NULL, texturing );
for(v = 1; v < m->nv; v++) {
prev = (v-1) * m->nu;
cur = v * m->nu;
glBegin( GL_QUAD_STRIP );
for(u = 0; u < m->nu; u++) {
if(usetx) {
glTexCoord2fv( &m->tx[prev+u].x[0] );
glVertex3fv( &m->pts[prev+u].x[0] );
glTexCoord2fv( &m->tx[cur+u].x[0] );
glVertex3fv( &m->pts[cur+u].x[0] );
} else {
glVertex3fv( &m->pts[prev+u].x[0] );
glVertex3fv( &m->pts[cur+u].x[0] );
}
}
glEnd();
}
}
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
void specks_draw_boxes( struct stuff *st, struct AMRbox *boxes, int boxlevelmask, Matrix Ttext, int oriented )
{
static short arcs[] = {
5, 4, 6, 2, 3, 1, 5, 7, 6,
-1,
7, 3,
0, 1,
0, 2,
0, 4
};
struct AMRbox *box;
int i;
int blevels = (st->boxlevels > 1 ? st->boxlevels-1 : 1);
float boxscale, s0, s1;
int isscaled;
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glLineWidth( st->boxlinewidth );
glEnable( GL_BLEND );
glDisable( GL_LINE_SMOOTH );
/* Scan through the array, whose end is marked with a box at level -1. */
for(box = boxes; box->level >= 0; box++) {
boxscale = (box->level < 0) ? 1.0
: st->boxscale[ box->level>=MAXBOXLEV ? MAXBOXLEV-1 : box->level ];
isscaled = (boxscale != 0 && boxscale != 1);
if(isscaled) {
s0 = .5*(1 + boxscale);
s1 = .5*(1 - boxscale);
}
if((1 << box->level) & boxlevelmask) {
int cval = RGBALPHA(st->boxcmap[
box->level<0 ? 0
: box->level>=st->boxncmap ?
st->boxncmap-1 : box->level ].cooked,
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
0xFF);
int colorme = 0;
if(oriented)
cval = orientboxcolor;
glColor4ubv( (GLubyte *)&cval );
glBegin( GL_LINE_STRIP );
for(i = 0; i < COUNT(arcs); i++) {
int vert = arcs[i];
if(vert < 0) {
glEnd();
glBegin( GL_LINES );
} else {
if(oriented) {
if(vert == 0) {
glColor4ubv( (GLubyte *)&cval );
colorme = 1;
} else if(colorme) {
glColor3f( vert&1?1:0, vert&2?1:0, vert&4?1:0 );
}
}
if(isscaled && !oriented && box->level >= 0) {
glVertex3f(
vert&1 ? s0*box->p0.x[0] + s1*box->p1.x[0]
: s1*box->p0.x[0] + s0*box->p1.x[0],
vert&2 ? s0*box->p0.x[1] + s1*box->p1.x[1]
: s1*box->p0.x[1] + s0*box->p1.x[1],
vert&4 ? s0*box->p0.x[2] + s1*box->p1.x[2]
: s1*box->p0.x[2] + s0*box->p1.x[2] );
} else {
glVertex3f(
(vert&1 ? box->p1.x : box->p0.x)[0],
(vert&2 ? box->p1.x : box->p0.x)[1],
(vert&4 ? box->p1.x : box->p0.x)[2]
);
}
}
}
glEnd();
if(st->boxlabels && st->boxlabelscale != 0) {
float sz = .16 * vdist( &box->p0, &box->p1 ) / st->textsize;
char lbl[16];
glPushMatrix();
glTranslatef( .75*box->p0.x[0] + .25*box->p1.x[0],
.75*box->p0.x[1] + .25*box->p1.x[1],
.75*box->p0.x[2] + .25*box->p1.x[2]);
glMultMatrixf( Ttext.m );
sprintf(lbl, "%d", box->boxno);
sfStrDraw( lbl, sz, NULL );
glPopMatrix();
}
}
}
glLineWidth( 1 );
}
int specks_partial_pick_decode( struct stuff *st, int id,
int nhits, int nents, GLuint *hitbuf,
unsigned int *bestzp, struct specklist **slp,
int *specknop, Point *pos )
{
int i, hi, ns, slno;
GLuint z0, bestz = *bestzp;
int bestslno = 0, bestspeck = -1;
struct specklist *sl, *slhead;
if(st == NULL)
return 0;
for(hi = 0, i = 0; hi < nhits && i < nents; hi++, i += ns + 3) {
ns = hitbuf[i];
if(ns < 1 || ns > 16)
break; /* trouble */
z0 = hitbuf[i+1];
if(st->usepoly>1) /* debug */
printf(ns>1?"[%x %d/%d]":"[%x %d]", z0, hitbuf[i+3],hitbuf[i+4]);
if(id == hitbuf[i+3] && bestz > z0 && ns > 1 && (slno = hitbuf[i+4]) > 0) {
bestz = z0;
bestslno = slno;
bestspeck = (ns>2) ? hitbuf[i+5] : 0;
}
}
if(bestslno <= 0)
return 0;
slhead = st->frame_sl; /* st->sl as snapped by specks_ffn() */
if(slhead == NULL) slhead = st->sl; /* maybe there is no specks_ffn() */
if(slhead == NULL) return 0;
for(sl = slhead, slno = 1; sl != NULL; sl = sl->next, slno++) {
if(slno == bestslno) {
if(bestspeck < 0 || bestspeck >= sl->nspecks) {
msg("Bogus pick result: sl %x bestspeck %d of 0..%d!\n",
sl, bestspeck, sl->nspecks-1);
return 0;
}
if(slp) *slp = sl;
if(specknop) *specknop = bestspeck;
if(pos) {
if(bestspeck < 0 || bestspeck >= sl->nspecks)
bestspeck = 0;
*pos = NextSpeck( sl->specks, sl, bestspeck )->p;
}
*bestzp = bestz;
return 1;
}
}
return 0;
}
#if CAVE
void parti_seto2w( struct stuff *st, int objno, CONST Matrix *newTo2w ) {
st->objTo2w = *newTo2w; /* ignores objno -- there's only one right now! */
}
void parti_geto2w( struct stuff *st, int objno, Matrix *curTo2w ) {
*curTo2w = st->objTo2w; /* ignores objno -- there's only one right now! */
}
void specks_display( struct stuff *st )
{
int showmenus;
int menuhit = 0;
static int hidescene;
if( CAT_dsp_mode == APP_DSP_NORMAL ) {
#if !(MENU_IN_PPR)
if( CAVEEye == CAVE_LEFT_EYE ) {
menu_check( pmenu, pmenu->cavewall );
menu_check( stubmenu, stubmenu->cavewall );
menu_sethidden( pmenu, st->hidemenu || empty );
menu_sethidden( stubmenu, st->hidemenu<=0 || empty );
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
}
#endif
glPushMatrix();
/* The following only works if our transformation is exactly the
* Cave nav transform, i.e. if the CAT system hasn't
* translated us further; but that's true for this app.
*/
CAVENavInverseTransform();
menu_draw( pmenu );
if(!pmenu->hidden) {
menuhit = (pmenu->wallhit > 0);
menu_setpos( stubmenu, ment.menu->x0, ment.menu->y0 );
}
menu_draw( stubmenu );
glPopMatrix();
}
if(hidescene && !menuhit)
hidescene = 0;
if(menuhit && *CAVEFramesPerSecond < st->menudemandfps)
hidescene = 1; /* Don't draw scene if too slow to operate menu easily */
if(hidescene)
return;
glPushMatrix();
glTranslatef( st->gtrans.x[0], st->gtrans.x[1], st->gtrans.x[2] );
glScalef( st->gscale, st->gscale, st->gscale );
glMultMatrixf( st->objTo2w.m );
drawspecks( st );
glPopMatrix();
}
#endif /*NOCAVE*/
static void addchunk( struct stuff *st, int nsp, int bytesperspeck,
float scaledby, struct speck *sp, char *text,
int outbytesperspeck )
{
struct specklist **slp, *sl = NewN( struct specklist, 1 );
memset( sl, 0, sizeof(*sl) );
sl->bytesperspeck = outbytesperspeck;
sl->specks = NewNSpeck( sl, nsp );
sl->nspecks = nsp;
sl->scaledby = scaledby;
if(text) {
sl->text = NewN( char, strlen(text)+1 );
strcpy(sl->text, text);
} else {
sl->text = NULL;
}
if(bytesperspeck == outbytesperspeck) {
memcpy( sl->specks, sp, nsp*sl->bytesperspeck );
} else {
int i;
for(i = 0; i < nsp; i++)
memcpy(((char *)sl->specks) + i*outbytesperspeck,
((char *)sp) + i*bytesperspeck,
outbytesperspeck);
}
slp = specks_timespecksptr(st, st->curdata, st->datatime);
sl->next = *slp;
*slp = sl;
st->sl = specks_timespecks(st, st->curdata, st->curtime); /* in case it changed */
sl->colorseq = -1; /* Force recomputing colors */
sl->sizeseq = -1; /* Force recomputing sizes */
}
int specks_count( struct specklist *sl ) {
int n;
for(n = 0; sl != NULL; sl = sl->next)
if(sl->text == NULL)
n += sl->nspecks * (sl->subsampled>0 ? sl->subsampled : 1);
return n;
}
static float speckscale = 1;
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
#define LINEBUFSIZE 2048
static char *getline(FILE *f, char *buf) {
buf[0] = '\0';
while(fgets(buf, LINEBUFSIZE, f) != NULL) {
char *cp = buf;
while(isspace(*cp)) cp++;
if(*cp != '#' && *cp != '\0')
return cp;
}
return NULL;
}
void specks_read_mesh( struct stuff *st, char *key, FILE *f, char *buf )
{
char *cp, *ep;
int count, alloced, err = 0;
int havetx = 0;
Point pts[300], txs[300];
struct mesh *m = NewN( struct mesh, 1 );
memset(m, 0, sizeof(*m));
m->type = TSTRIPS;
m->txno = -1;
m->pts = pts; m->tx = txs;
alloced = COUNT(pts);
if(key[0] == 'm' || key[0] == 'q') {
m->type = QUADMESH;
} else if(!strncmp(key, "tfan", 4) || !strncmp(key, "trifan", 6)) {
m->type = TFANS;
} else {
m->type = TSTRIPS;
}
key = strtok(NULL, separ);
if(!strcmp(key, "-t") && (key = strtok(NULL, separ)) != NULL) {
sscanf(key, "%d", &m->txno);
havetx = 1; /* expect texture coords too */
}
if(m->type == QUADMESH) {
getline(f, buf);
if(sscanf(buf, "%d%d", &m->nu, &m->nv) != 2
|| m->nu <= 0 || m->nv <= 0) {
msg("quadmesh: expected nu nv, got %s", buf);
Free(m);
return;
}
alloced = m->nverts = m->nu * m->nv;
m->pts = NewN( Point, m->nverts );
m->tx = havetx ? NewN( Point, m->nverts ) : NULL;
}
count = 0;
while((cp = getline(f, buf)) != NULL) {
int ngot;
Point *tp;
#define BRA '{'
#define CKET '}'
if(*cp == BRA) continue;
if(*cp == CKET) break;
if(count >= alloced) {
if(m->type == QUADMESH) {
err = 1;
msg("Only expected %d*%d=%d vertices; what's %s",
m->nu,m->nv, alloced, cp);
break;
}
/* otherwise, ask for more */
/* XXX maybe later */
break;
}
tp = &m->pts[count];
for(ngot = 0; ngot < 3; ngot++, cp = ep) {
tp->x[ngot] = strtod(cp, &ep);
if(cp == ep) break;
}
if(havetx && ngot == 3) {
tp = &m->tx[count];
for(ngot = 0; ngot < 2; ngot++, cp = ep) {
tp->x[ngot] = strtod(cp, &ep);
if(cp == ep) break;
}
ngot++;
}
if(ngot != 3) {
msg("Expected %d numbers per line; what's %s",
havetx?5:3, buf);
err = 1;
break;
}
count++;
}
if(m->type == QUADMESH && count < alloced) {
err = 1;
msg("Expected %d*%d = %d vertices, only got %d", m->nu,m->nv, alloced, count);
}
if(err) {
if(m->pts != pts) Free(m->pts);
if(m->tx != txs && m->tx != NULL) Free(m->tx);
Free(m);
return;
}
m->next = st->staticmeshes;
st->staticmeshes = m;
}
void specks_read( struct stuff **stp, char *fname )
{
FILE *f;
char line[LINEBUFSIZE], oline[LINEBUFSIZE];
char *key;
struct stuff *st = *stp;
int maxfields = 0;
#define SPECKCHUNK 2001 /* should be bigger, but too many machines have tiny stack areas! */
struct speck sp[SPECKCHUNK];
struct speck s;
int i, nsp;
int ignorefirst = 0;
int lno = 0;
if(fname == NULL) return;
key = NewA( char, strlen(fname)+1 ); /* fname's space might get reused */
strcpy(key, fname);
fname = key;
if((f = fopen(fname, "r")) == NULL) {
msg("%s: can't open: %s", fname, strerror(errno));
return;
}
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
s.size = 1;
nsp = 0;
#define SPFLUSH() \
if(nsp>0) { \
addchunk( st, nsp, sizeof(struct speck), \
speckscale, sp, NULL, \
maxfields > MAXVAL ? sizeof(struct speck) \
: SMALLSPECKSIZE( maxfields ) ); \
nsp = maxfields = 0; \
}
line[sizeof(line)-1] = '\1';
while( fgets(line, sizeof(line), f) != NULL ) {
lno++;
if(line[sizeof(line)-1] != 1) {
if(line[sizeof(line)-2] != '\n') {
while((i = getc(f)) != EOF && i != '\n')
;
}
line[sizeof(line)-1] = '\1';
line[sizeof(line)-2] = '\0';
msg("%s line %d: truncated (>%d chars long!)", fname, lno, sizeof(line)-2);
}
strcpy(oline, line);
do {
key = strtok(line, separ);
} while(key != NULL && 0==strcmp(key, "add")); /* ignore "add" prefix */
if(key == NULL || key[0] == '#' || key[0] == '\0')
continue;
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
if(nsp >= SPECKCHUNK || (isalnum(key[0]) && !isdigit(key[0]))) {
SPFLUSH();
}
if(!strcmp(key, "include") || !strcmp(key, "read")) {
float oldscale = speckscale;
char *infname = strtok(NULL, separ);
char *realfile = findfile( fname, infname );
if(realfile == NULL) {
msg("%s: Can't find include-file %s", fname, infname);
} else {
specks_read( &st, realfile );
}
speckscale = oldscale;
#ifdef USE_IEEEIO
} else if(!strcmp(key, "ieee")) {
int timestepno = st->datatime;
char *realfile;
char *s = strtok(NULL, separ);
if(s != NULL && !strcmp(s, "-t")) {
s = strtok(NULL, separ);
if(s == NULL || (timestepno = getfloat(s, st->datatime)) < 0) {
msg("ieee -t: expected timestepnumber(0-based), not %s", s);
continue;
}
s = strtok(NULL, separ);
}
realfile = findfile( fname, s );
if(realfile == NULL) {
msg("%s: ieee: can't find file %s", fname, s);
} else {
/* Load IEEE dataset into time slot */
specks_ieee_open( st, realfile, st->curdata, timestepno );
}
#endif
} else if(!strcmp(key, "object")) {
key = strtok(NULL, separ);
parti_object( key, &st );
if(eq) {
parti_set_alias( st, eq+1 );
} else {
key = strtok(NULL, separ);
if(key) {
parti_set_alias( st, key[0]=='='
? strtok(NULL, separ) : key );
}
}
} else if(!strcmp(key, "kira")) {
char *s = strtok(NULL, separ);
char *verbose = strtok(NULL, separ);
#ifndef USE_KIRA
msg("Need to recompile with -DUSE_KIRA");
#else
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
} else if(!strcmp(key, "sdb")) {
char *s = strtok(NULL, separ);
int tno = st->datatime;
char *realfile;
if(s != NULL && !strcmp(s, "-t")) {
if((tno = getfloat(s=strtok(NULL, separ), st->datatime)) < 0) {
msg("sdb -t: expected timestepnumber(0-based), not %s", s);
continue;
}
s = strtok(NULL, separ);
}
realfile = findfile( fname, s );
if(realfile == NULL) {
msg("%s: sdb: can't find file %s", fname, s);
} else {
specks_read_sdb( st, realfile, tno );
}
} else if(!strcmp(key, "sdbvars")) {
char *s = strtok(NULL, separ);
if(s != NULL) {
if(s[strspn(s, "mMcrogtxyzSn")] != '\0') {
msg("sdbvars: pattern must contain only chars from: mMcrogtxyzSn, not %s",
s);
} else {
if(st->sdbvars) Free(st->sdbvars);
st->sdbvars = shmstrdup(s);
}
} else {
msg("sdbvars %s", st->sdbvars);
}
} else if(!strcmp(key, "box") || !strcmp(key, "boxes")) {
char *args[16], **av;
Point cen, rad;
struct AMRbox box;
int ac, k;
int tno = -1;
for(ac = 0; ac < COUNT(args) && (args[ac] = strtok(NULL, separ)) != NULL; ac++)