Newer
Older
/*
* Syzygy-related functions for szgPartiview, including main program.
*/
static char local_id[] = "$Id$";
/*
* $Log$
* Revision 1.13 2009/03/25 07:47:39 slevy
* ar_log_XXX logs don't seem to go anywhere, so also append to
* parti.NNNN.log, where NNNN is the SZGClient ProcessID.
* Maybe this too should be changed -- should we just try to log
* to one big file, to limit clutter? Every line is already labelled with [PID] now.
*
* Don't use exit(0) in command parser. Set a shared quit flag instead,
* and have everybody (?) exit later.
*
* <string>.append( C_string, len ) never copies in the string's trailing \000,
* so add it ourselves.
*
* Only create a listenSocket if we're the master -- avoid races to grab the port.
* I'm not sure when is best to determine master-hood, so out of superstition
* we do it in the first preExchange callback.
*
* Yes, we *do* need to initialize cmdbuf_ to be *empty*.
*
* Revision 1.12 2009/03/14 21:32:02 slevy
* Initialize the cmdbuf transfer-buffer size to 1 byte.
* szg gets mad if we try to select size 0.
*
* Revision 1.11 2008/07/28 09:22:58 slevy
* Add CMDTEST hook for testing PpCmd packing/unpacking. Looks like it might work.
*
* Revision 1.10 2008/07/28 08:49:48 slevy
* Scrap pp_ui_postinit(). It just overwrites settings that (a) were initialized
* properly earlier and (b) might have been changed by command-line I/O.
* I.e. let the "run" command work if included in a .cf file.
*
* Revision 1.9 2008/07/28 08:39:41 slevy
* onPreExchange: Point sockp at a new bufferedSocket before passing to ar_accept()!
* Tidy list insert/deletion.
* Call clock_tick() periodically in master to allow time to pass.
* onPostExchange: Add more error checking.
* main: Hack to allow running under Linux+freeglut in standalone mode.
*
* Revision 1.8 2008/07/25 16:10:16 slevy
* Lots of changes from Will Davis: new socket stuff
* for listening for commands from network;
* transfer fields; attempts to get "play" to play, etc.
* Some from Stuart: PpCmd uses string object;
* passing PpCmd commands by transfer-field
* from master to slaves.
*
* Revision 1.7 2008/07/22 23:20:07 slevy
* Need to resize() when adding new elements, not just reserve().
*
* Revision 1.6 2008/07/22 18:46:14 slevy
* Use ar_log_<whatever>() for msg() logging. Send to either _remark or _warning
* according to whether msg() or warn() was called.
*
* Revision 1.5 2008/07/22 17:49:58 slevy
* From Will Davis: globalize argc/argv for use in callback later.
* onWindowStartGL() returns void.
*
* Implement PpCmd interface for serializing commands for network transport.
*
* Revision 1.4 2008/07/15 08:40:17 slevy
* Don't mention "virtual" on *implementation* methods.
*
* Revision 1.3 2008/07/14 17:17:48 slevy
* Attempt to glue in some arMasterSlaveFramework methods -- maybe enough to draw,
* though not to process any commands after command-line startup yet.
*
*/
#include "arPrecompiled.h"
#include "arMasterSlaveFramework.h"
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#ifdef AR_USE_WIN_32
#include "plugins.h"
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "specks.h"
#include "szgPartiview.h"
#include "shmem.h"
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <math.h>
#include <errno.h>
#include "partiviewc.h"
#include "findfile.h"
struct Ppszg ppszg;
static int specks_commandstr( struct stuff **stp, const char *str ) {
int result;
if(stp == NULL || *stp == NULL || str == NULL)
return 0;
#define MAXARGS 128
char *av[MAXARGS];
int ac;
char *txt = (char *)malloc( strlen(str) + 1 );
char *s = txt;
strcpy(txt, str);
for(ac = 0; ac < MAXARGS-1; ac++) {
av[ac] = strtok(s, " \t\n");
if(av[ac] == NULL) break;
s = NULL;
}
av[ac] = NULL;
result = specks_parse_args( stp, ac,av);
free(txt);
return result;
}
int specks_commandfmt( struct stuff **stp, const char *fmt, ... ) {
char cmd[1024], *cp;
int ok;
va_list args;
va_start(args, fmt);
vsprintf(cmd, fmt, args);
va_end(args);
for(cp = cmd; isspace(*cp); cp++)
;
if(*cp == '\0') return 1; // accept null command implicitly
ok = specks_commandstr( stp, cmd );
if(ok) parti_redraw();
else msg("Unrecognized control command: %s", cmd);
return ok;
}
/*
* These two are a quick fix to using argc and argv[] in the
* onStart() function. I don't believe you can pass parameters
* into, but I could be wrong.
*
*/
int globalArgc;
char** globalArgv;
/* =================================================================== */
int pp_read( struct stuff **, int argc, char *argv[], char *fromfname, void * ) {
/* this module defines only one command at present ... */
if(!strcmp( argv[0], "subcam")) {
if(argc >= 9) {
parti_make_subcam( argv[1], argc-2, argv+2 );
} else {
msg("%s: subcam: expected name az el rol L R B T, not %s",
fromfname, rejoinargs( 1, argc, argv ));
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
}
return 1;
}
return 0;
}
void parti_lighting() {
static GLuint lightlist[MAXDSPCTX];
int ctx = get_dsp_context(); /* this would come from Syzygy wall number, say */
int listmaking = 0;
if((unsigned int)ctx < MAXDSPCTX) {
if(lightlist[ctx] > 0) {
glCallList( lightlist[ctx] );
return;
} else {
lightlist[ctx] = glGenLists( 1 );
glNewList( lightlist[ctx], GL_COMPILE_AND_EXECUTE );
listmaking = 1;
}
} else {
listmaking = 0;
}
static GLfloat lmambient[] = { 0.1, 0.1, 0.1, 1.0 };
static GLfloat amblight[] = { 0.1, 0.1, 0.1, 1.0 };
static GLfloat whitelight[] = { 1, 1, 1, 1 };
static GLfloat Ce[] = { 0, 0, 0, 1 };
static GLfloat Ca[] = { 1, 1, 1, 1 };
static GLfloat Cd[] = { 1, 1, 1, 1 };
static GLfloat Cs[] = { 1, 1, 1, 1 };
static GLfloat lightpos[3][4] = {
0, 0, -1, 0,
1, 0, -.5, 0,
0, 1, 0, 0,
};
glShadeModel( GL_SMOOTH );
glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmambient );
glDisable( GL_LIGHTING );
int i;
for(i = 0; i < 8; i++)
glDisable( GL_LIGHT0+i );
for(i = 0; i < 3; i++) {
glLightfv( GL_LIGHT0+i, GL_AMBIENT, amblight );
glLightfv( GL_LIGHT0+i, GL_SPECULAR, whitelight );
glLightfv( GL_LIGHT0+i, GL_DIFFUSE, whitelight );
glLightfv( GL_LIGHT0+i, GL_POSITION, lightpos[i] );
glEnable( GL_LIGHT0+i );
}
glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, Ce );
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, Ca );
glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, Cd );
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, Cs );
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 32.0 );
glColorMaterial( GL_FRONT_AND_BACK, GL_DIFFUSE );
glDisable( GL_COLOR_MATERIAL );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glDisable( GL_BLEND );
if(listmaking)
glEndList();
}
PvObject::PvObject() : st_(0), name_(0), id_(-1), parent_(0) {
}
PvObject::PvObject( const char *name, int id ) {
this->init( name, id );
}
void PvObject::init( const char *name, int id ) {
struct stuff *st = specks_init( 0, NULL );
st->clk = ppszg.clk;
this->st_ = st;
this->To2w( &Tidentity );
this->name_ = name ? strdup(name) : strdup("");
this->id_ = id;
this->parent_ = 0;
}
void PvObject::draw( bool inpick ) {
if(st_ == NULL)
return;
specks_set_timestep( st_ );
specks_current_frame( st_, st_->sl );
glPushMatrix();
glMultMatrixf( & To2w_.m[0] );
st_->inpick = (int)inpick;
drawspecks( st_ );
st_->inpick = 0;
glPopMatrix();
}
void drawetc( const Point *cen, float censize ) {
static Point xyz[3] = {{{1,0,0}}, {{0,1,0}}, {{0,0,1}}};
static Point nxyz[3] = {{{-1,0,0}}, {{0,-1,0}}, {{0,0,-1}}};
static Point zero = {{0,0,0}};
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
static float white[3] = {1,1,1};
int i;
// if(ppszg.drawtrace)
// (*ppszg.drawtrace)();
parti_lighting();
glDisable(GL_LIGHTING);
if(censize > 0) {
glPushMatrix();
glScalef(censize,censize,censize);
glBegin(GL_LINES);
for(i = 0; i < 3; i++) {
glColor3fv(xyz[i].x);
glVertex3fv(xyz[i].x);
glVertex3f(0,0,0);
}
glEnd();
glPopMatrix();
}
if(censize != 0) {
censize = fabs(censize);
glPushMatrix();
glTranslatef(cen->x[0],cen->x[1],cen->x[2]);
glScalef(censize, censize, censize);
glBegin(GL_LINES);
for(i = 0; i < 3; i++) {
glColor3fv(white);
glVertex3fv(nxyz[i].x);
glVertex3fv(zero.x);
glColor3fv(xyz[i].x);
glVertex3fv(zero.x);
glVertex3fv(xyz[i].x);
}
glEnd();
glPopMatrix();
}
}
// Draw entire partiview scene.
// XXX How can we handle background color, ppszg.bgcolor? Do we glClear() here ??
//
// YYY setting "inpick" is part of what's needed to go into OpenGL "selection" mode,
// YYY but we don't need that immediately if at all.
// Just call draw() and let inpick default to false.
void PvScene::draw( bool inpick ) {
drawetc( center(), censize() );
for(int i = 0; i < nobjs(); i++) {
obj(i)->draw( inpick );
}
}
PvObject *PvScene::addobj( const char *objname, int id ) {
if(id < 0)
id = objs_.size();
if(objstuff(id) == 0) {
if(id >= objs_.capacity())
objs_.reserve( id + 15 );
if(id >= objs_.size())
objs_.resize( id+1 );
objs_[id].init( objname, id );
} else {
msg("Warning: Reusing object g%d (named %s)", id, objname);
}
return &objs_[id];
}
// watching file descriptors for external input, e.g. from network.
// XXX good to implement these someday.
void parti_asyncfd( int fd ) {
msg("IGNORING parti_asyncfd(%d)", fd);
}
void parti_unasyncfd( int fd ) {
// XXX
}
typedef enum { REMARK, WARN } MsgLevel;
static MsgLevel msglevel = REMARK;
static int processid = 42;
int vmsg( const char *fmt, va_list args ) {
char str[10240];
#ifdef HAVE_SNPRINTF
vsnprintf(str, sizeof(str), fmt, args);
#else
vsprintf(str, fmt, args);
#endif
// XXX Now do something with str!
fputs(str, stderr);
fputc('\n', stderr);
if(msglevel == REMARK)
ar_log_remark() << str;
else
ar_log_warning() << str;
char logfname[128];
sprintf(logfname, "parti.%04d.log", processid);
FILE *f = fopen(logfname, "a");
if(f != 0) {
fprintf(f, "[%d]: %s\n", processid, str);
fclose(f);
}
}
int msg( const char *fmt, ... ) {
int val;
va_list args;
msglevel = REMARK;
va_start(args, fmt);
val = vmsg( fmt, args );
va_end(args);
return val;
}
void warn( const char *fmt, ... ) {
va_list args;
msglevel = WARN;
va_start(args, fmt);
vmsg(fmt, args);
va_end(args);
}
// partiview <-> syzygy navigation.
void copyfrom_arMatrix( Matrix *dstT, const arMatrix4 *srcarT )
{
int i;
for(i = 0; i < 16; i++)
dstT->m[i] = srcarT->v[i];
}
void copyto_arMatrix( arMatrix4 *dstarT, const Matrix *srcT )
{
int i;
for(i = 0; i < 16; i++)
dstarT->v[i] = srcT->m[i];
}
void parti_getc2w( Matrix *c2w ) {
/*
* Modified July 23, 2008 William Davis
* We needed the non-inverted matrix,
* changed from ar_getNavInvMatrix to
* ar_getNavMatrix();
*/
arMatrix4 navmat = ar_getNavMatrix();
copyfrom_arMatrix( c2w, &navmat );
}
void parti_setc2w( const Matrix *c2w ) {
//msg("IGNORING parti_setc2w() (\"jump\")");
//XXX handle the "jump" command. Something like
/*
* Modified July 23, 2008 William Davis
* Sets the navigation matrix to the coordinates
* specified by the "jump" command
* Removed eucinv( &w2c, c2w )
* Modified copyto_arMatrix() to match
*/
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#if 0
arMatrix4 nowat, jumpby;
nowat = ar_getNavMatrix();
Matrix c2wnow, w2cnow, delta;
copyfrom_arMatrix( &c2wnow, &nowat );
eucinv( &w2cnow, &c2wnow );
mmmul( &delta, &w2cnow, c2w );
copyto_arMatrix( &jumpby, &delta );
#else
arMatrix4 jumpby;
copyto_arMatrix( &jumpby, c2w );
#endif
arMatrix4 wasat = ar_getNavMatrix();
ar_setNavMatrix( jumpby );
arMatrix4 nowat = ar_getNavMatrix();
arMatrix4 hdmat = ppszg.getMatrix( 0 );
msg("head: %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f",
hdmat.v[0],hdmat.v[1],hdmat.v[2],hdmat.v[3],
hdmat.v[4],hdmat.v[5],hdmat.v[6],hdmat.v[7],
hdmat.v[8],hdmat.v[9],hdmat.v[10],hdmat.v[11],
hdmat.v[12],hdmat.v[13],hdmat.v[14],hdmat.v[15]);
msg("navwas: %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f",
wasat.v[0],wasat.v[1],wasat.v[2],wasat.v[3],
wasat.v[4],wasat.v[5],wasat.v[6],wasat.v[7],
wasat.v[8],wasat.v[9],wasat.v[10],wasat.v[11],
wasat.v[12],wasat.v[13],wasat.v[14],wasat.v[15]);
msg("setc2w: %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f",
c2w->m[0],c2w->m[1],c2w->m[2],c2w->m[3],
c2w->m[4],c2w->m[5],c2w->m[6],c2w->m[7],
c2w->m[8],c2w->m[9],c2w->m[10],c2w->m[11],
c2w->m[12],c2w->m[13],c2w->m[14],c2w->m[15]);
msg("navnow: %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f",
nowat.v[0],nowat.v[1],nowat.v[2],nowat.v[3],
nowat.v[4],nowat.v[5],nowat.v[6],nowat.v[7],
nowat.v[8],nowat.v[9],nowat.v[10],nowat.v[11],
nowat.v[12],nowat.v[13],nowat.v[14],nowat.v[15]);
}
double syzygy_time() { // called from sclock.c
return ppszg.getTime() * 0.001;
}
// Camera Animation (from .wf path)
static void playidle( void * ) {
struct wfpath *path = &ppszg.path;
if(!ppszg.playing) {
// XXX disable calling playidle() in this case. // Fl::remove_idle( playidle, NULL );
ppszg.playidling = 0;
return;
}
double now;
#if TESTCAVE
now = ppszg.getTime();
#else
now = wallclock_time();
#endif
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
if(ppszg.playspeed == 0)
ppszg.playspeed = 1;
int frame = ppszg.framebase;
if(ppszg.playevery) {
frame += (int) ((ppszg.playspeed < 0) /* round away from zero */
? ppszg.playspeed - .999f
: ppszg.playspeed + .999f);
ppszg.framebase = frame;
ppszg.playtimebase = now;
} else {
frame += (int) ((now - ppszg.playtimebase) * ppszg.playspeed * path->fps);
}
if(frame < path->frame0 || frame >= path->frame0 + path->nframes) {
frame = (frame < path->frame0)
? path->frame0
: path->frame0 + path->nframes-1;
switch(ppszg.playloop) {
case 0: /* Not looping; just stop at end. */
// XXX disable calling playidle() here // Fl::remove_idle( playidle, NULL );
ppszg.playidling = 0;
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
break;
case -1: /* Bounce: stick at same end of range, change direction */
ppszg.playspeed = -ppszg.playspeed;
break;
case 1: /* Loop: jump to other end of range */
frame = (frame == path->frame0)
? path->frame0 + path->nframes-1
: path->frame0;
}
ppszg.framebase = frame;
ppszg.playtimebase = now;
parti_setframe( frame );
return;
}
/*
* Cases:
* - we're displaying frames slower than real time.
* => use an idle function.
* - we're displaying frames faster than real time.
* => use a timeout.
*/
int needidle = ppszg.playidling;
float dt = 0;
if(frame != path->curframe) {
parti_setframe( frame );
needidle = 1;
} else {
frame += (ppszg.playspeed > 0) ? 1 : -1;
dt = (frame - ppszg.framebase) / (ppszg.playspeed * path->fps)
+ ppszg.playtimebase - now;
needidle = (dt < .05);
}
if(needidle && !ppszg.playidling) {
// XXX enable calling playidle() here // Fl::add_idle( playidle, NULL );
}
if(!needidle && ppszg.playidling) {
// XXX disable calling playidle() here // Fl::remove_idle( playidle, NULL );
}
ppszg.playidling = needidle;
if(!needidle) {
// XXX schedule calling playidle once, "dt" seconds from now // Fl::add_timeout( dt, playidle, NULL );
}
}
void parti_play( const char *rate ) {
struct wfpath *path = &ppszg.path;
int playnow = 1;
int awaitdone = 0;
msg("Inside the parti_play!");
msg(rate);
if(rate != NULL) {
char *ep;
float sp = strtod(rate, &ep);
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
if(strchr(ep, 's')) playnow = 0;
if(strchr(ep, 'l')) ppszg.playloop = 1;
else if(strchr(ep, 'k')) ppszg.playloop = -1; /* rock */
else if(strchr(ep, 'f') || strchr(ep, 'e')) ppszg.playevery = 1;
else if(strchr(ep, 'r') || strchr(ep, 't')) ppszg.playevery = 0;
if(strstr(rate, "wait"))
awaitdone = 1;
if(ep == rate) {
/* No leading number -- did we get just "-" or "-?" or "-help"? */
if(0==strcmp(rate, "-") || strchr(rate, '?') || strchr(rate, 'h')) {
msg("Usage: play [rate][s][l|k][f|r][wait] e.g. \"play\" or \"play 30\" or \"play 10kf wait\"");
msg(" rate frames/sec; [s]et speed, don't play now; [l]oop/roc[k]");
msg(" play every [f]rame/skip to maintain [r]ate; [wait] until done");
return;
}
if(sp == 0) playnow = 0;
else ppszg.playspeed = sp;
}
}
// Disable playidle() idle-function
// Fl::remove_idle( playidle, NULL );
// Fl::remove_timeout( playidle, NULL );
ppszg.playing = 0;
ppszg.playidling = 0;
if(playnow) {
#if CAVE
ppszg.playtimebase = .001 * ppszg.getTime();
#else
ppszg.playtimebase = wallclock_time();
#endif
printf("playtimebase: %f", ppszg.playtimebase);
ppszg.framebase = path->curframe;
if(ppszg.playspeed > 0 && path->curframe >= path->frame0+path->nframes-1)
ppszg.framebase = path->frame0;
else if(ppszg.playspeed < 0 && path->curframe <= path->frame0)
ppszg.framebase = path->frame0 + path->nframes - 1;
parti_setframe( ppszg.framebase );
/* Switch into "play" mode */
// XXX start calling playidle() idle-function
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
ppszg.playing = 1;
}
}
// Idle function -- enabled when data-animation clock is running
void pp_stepper() {
if(ppszg.st) {
clock_tick( ppszg.st->clk );
specks_set_timestep( ppszg.st );
}
}
// Data animation
void parti_set_running( struct stuff *st, int on ) {
if(clock_running(st->clk) != on) {
if(on) {
// XXX enable pp_stepper idle function
} else {
// XXX disable pp_stepper idle function, no longer needed (?)
}
if(st->clk) st->clk->walltimed = 1;
clock_set_running(st->clk, on);
}
}
void readrc( struct stuff **stp ) {
char *rc = findfile( NULL, "~/.partiviewrc" );
if(rc) specks_read( stp, rc );
rc = findfile( NULL, "./.partiviewrc" );
if(rc) specks_read( stp, rc );
}
static int cmdargs(int argc, char **argv, int & optind) {
char *arg = argv[optind];
if(!strcmp("-c", arg)) {
arg = argv[optind+1];
char *t = NewN(char, strlen(arg)+1);
char *av[128];
int ac = tokenize(arg, t, 128, av, NULL);
specks_parse_args( &ppszg.st, ac, av );
Free(t);
optind += 2;
return 1;
}
return 0;
}
int pp_parse_args( struct stuff **, int argc, char *argv[], char *fromfname, void * ) {
if(argc < 1) return 0;
int i;
if(!strcmp( argv[0], "exit" )) {
msg("exiting");
// ppszg.stop( 1 );
ppszg.quitnow_ = 1;
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
} else if(!strcmp( argv[0], "stereo" )) {
for(i = 1; i < argc; i++)
parti_stereo( argv[i] );
msg("stereo %s", parti_stereo(NULL));
} else if(!strcmp( argv[0], "winsize" )) {
msg("winsize %s", parti_winsize( rejoinargs( 1, argc, argv ) ) );
} else if(!strncmp( argv[0], "snapset", 7 ) || !strcmp( argv[0], "snapshot" )) {
char *frameno = NULL, *basename = NULL;
char *size = NULL;
int now = (0 == strcmp(argv[0], "snapshot"));
while(argc > 2) {
if(!strcmp(argv[1], "-w")) {
size = argv[2];
} else if(!strcmp(argv[1], "-n")) {
frameno = argv[2];
} else
break;
argc -= 2, argv += 2;
}
if(argc > 1)
basename = rejoinargs( 1, argc, argv );
parti_snapset( basename, frameno, size );
if(now) {
char snapinfo[1024];
if(parti_snapshot(snapinfo) >= 0)
msg("Snapped %s", snapinfo);
}
} else if(!strcmp( argv[0], "clip" )) {
msg("%s", parti_clip( argv[1], argc>2?argv[2]:NULL ) );
} else if(!strcmp( argv[0], "pickrange" )) {
float pickrange = parti_pickrange( argv[1] );
msg("pickrange %g", parti_pickrange( NULL ));
} else if(!strcmp( argv[0], "fov" ) || !strcmp( argv[0], "fovy" )) {
float fovy = parti_fovy( (argc>1) ? argv[1] : NULL );
msg("fovy %g", fovy);
} else if(!strcmp( argv[0], "subcam")) {
int index;
if(argc > 1) {
if(!strcmp(argv[1], "-") || !strcmp(argv[1], "off")) {
parti_select_subcam(0);
} else {
index = parti_make_subcam( argv[1], argc-2, argv+2 );
if(index > 0) {
parti_select_subcam(index);
} else {
char *what = parti_subcam_list();
msg(what[0]=='\0' ? "No subcams defined yet" :
"Known subcams: %s", what);
}
}
}
index = parti_current_subcam();
if(index > 0) {
char params[100];
char *name = parti_get_subcam( index, params );
msg("subcam %s %s # az el rol L R B T", name, params);
} else {
int wx, wy;
float hx, hy = .5 * parti_fovy(NULL);
sscanf( parti_winsize(NULL), "%d%*c%d", &wx, &wy );
if(wy == 0) wy = 1;
hx = atan( tan(hy*(M_PI/180))*wx / wy ) * (180/M_PI);
msg("subcam off 0 0 0 %g %g %g %g # a e r L R B T (default)",
hx, hx, hy, hy);
}
} else if(!strncmp( argv[0], "focallen", 8 )) {
float focallen = parti_focal( (argc>1) ? argv[1] : NULL );
msg("focallength %g", focallen);
} else if(!strcmp( argv[0], "focalpoint" )) {
/* args:
* on/off
* x y z [minfocallen]
*/
Point fpt;
float minlen;
int ison = parti_focalpoint( argc-1, (argv+1), &fpt, &minlen );
msg(ison ? "focalpoint %g %g %g %g # pointxyz minfocallen"
: "focalpoint off # %g %g %g %g # pointxyz minfocallen",
fpt.x[0],fpt.x[1],fpt.x[2], minlen);
} else if(!strncmp( argv[0], "jump", 4 )) {
Point xyz;
float aer[3];
static int stupid[3] = {1,0,2}; /* aer -> rx ry rz */
Matrix c2w;
parti_getc2w( &c2w );
tfm2xyzaer( &xyz, aer, &c2w );
if(argc>1) {
for(i=1; i<argc && i<4+3; i++) {
if(i-1<3) xyz.x[i-1] = getfloat(argv[i], xyz.x[i-1]);
else aer[stupid[i-4]] = getfloat(argv[i], aer[stupid[i-4]]);
}
xyzaer2tfm( &c2w, &xyz, aer );
parti_setc2w( &c2w );
}
msg("jump %g %g %g %g %g %g (XYZ RxRyRz)",
xyz.x[0],xyz.x[1],xyz.x[2],
aer[1],aer[0],aer[2]);
} else if(!strncmp( argv[0], "home", 4 )) {//marx version 0.7.03
Point xyz;
float aer[3];
static int stupid[3] = {1,0,2}; /* aer -> rx ry rz */
Matrix c2w;
parti_getc2w( &c2w );
tfm2xyzaer( &xyz, aer, &c2w );
if(argc>1) {
for(i=1; i<argc && i<4+3; i++) {
if(i-1<3) xyz.x[i-1] = getfloat(argv[i], xyz.x[i-1]);
else aer[stupid[i-4]] = getfloat(argv[i], aer[stupid[i-4]]);
}
xyzaer2tfm( &c2w, &xyz, aer );
parti_setc2w( &c2w );
ppszg.home[0] = xyz.x[0]; ppszg.home[1] = xyz.x[1]; ppszg.home[2] = xyz.x[2];
//ppszg.home[3] = aer[0]; ppszg.home[4] = aer[1]; ppszg.home[5] = aer[2]; bug in releases >= 0.7.03
ppszg.home[3] = aer[1]; ppszg.home[4] = aer[0]; ppszg.home[5] = aer[2]; //version 0.7.05 fix for the line above
}
msg("home %g %g %g %g %g %g (XYZ RxRyRz)", ppszg.home[0], ppszg.home[1], ppszg.home[2], ppszg.home[3], ppszg.home[4], ppszg.home[5]);
} else if((!strcmp( argv[0], "rdata" ) || !strcmp(argv[0], "readpath"))
&& argc>1) {
bool freet = false;
char *tfname = argv[1];
char *realfile = findfile( fromfname, tfname );
if(realfile == NULL) {
tfname = (char *)malloc(strlen(argv[1]) + 32);
freet = true;
sprintf(tfname, "data/record/%s%s", argv[1],
strstr(argv[1], ".wf") ? "" : ".wf");
realfile = findfile( NULL, tfname+12 );
}
if(realfile == NULL)
realfile = findfile( fromfname, tfname );
if(realfile)
parti_readpath( realfile );
else
msg("%s: can't find \"%s\" nor data/record/... nor ...wf",
argv[0],argv[1]);
if(freet)
free(tfname);
} else if(!strcmp( argv[0], "play" )) {
parti_play( argc>1 ? rejoinargs(1, argc, argv) : NULL );
} else if(!strcmp( argv[0], "frame" )) {
CONST struct wfpath *pp;
i = parti_frame( argv[1], &pp );
msg("frame %d (of %d..%d)", pp->curframe,
pp->frame0, pp->nframes + pp->frame0 - 1);
} else if(!strcmp( argv[0], "interest") || !strcmp( argv[0], "int" ) ||
!strcmp( argv[0], "center" ) ||
!strcmp( argv[0], "cen" )) {
Point cen;
float censize = parti_getcensize();
parti_getcenter( &cen );
if(argc > 1) {
sscanf(argv[1], "%f%*c%f%*c%f%*c%f",
&cen.x[0],&cen.x[1],&cen.x[2], &censize);
if(argc > 3)
for(i=0;i<3;i++)
cen.x[i] = getfloat(argv[i+1], cen.x[i]);
if(argc == 3 || argc == 5)
sscanf(argv[argc-1], "%f", &censize);
parti_center( &cen );
if(censize != parti_getcensize())
parti_censize( censize );
}
msg("center %g %g %g %g(radius)", cen.x[0],cen.x[1],cen.x[2], censize);
} else if(!strcmp( argv[0], "censize" )) {
if(argc>1)
parti_censize( getfloat(argv[1], parti_getcensize()));
msg("censize %g (interest-marker size)", parti_getcensize());
} else {
return 0;
}
return 1;
}
void pp_ui_postinit() {
parti_set_timebase( ppszg.st, 0.0 );
parti_set_timestep( ppszg.st, 0.0 );
parti_set_running( ppszg.st, 0 );
parti_set_fwd( ppszg.st, 1 );
}
void clearBuffer(char* buf, int bufsize)
{
for(int i=0; i < bufsize; i++)
{
buf[i] = '\0';
}
}
PpCmd::PpCmd( CmdType type, int argc, char **argv )
{
this->type = type;
this->argc = argc;
this->argv = argv;
}
PpCmd::~PpCmd() {
}
int PpCmd::frozenLen() const {
int len = 2*argc+2;
for(int i = 0; i < argc; i++)
len += strlen(argv[i]);
return len;
}
/* Serialize the command, and append result to 'buf' */
int PpCmd::freezeInto( string &buf ) const {
int ineed = buf.size() + frozenLen() + 1;
if(buf.capacity() < ineed)
buf.reserve( 2*ineed+1 );
for(int i = 0; i < argc; i++) {
buf.append( argv[i], strlen(argv[i]) );
buf.append( 1, '\000' );
buf.append( 1, '\000' ); // mark end of last arg
return buf.size();
int PpCmd::thawFrom( char *buf, int &offset, bool copystrings ) {
if(buf == 0)
return 0;
int p = offset;
argc = 0;
argv = 0;
type = (CmdType) buf[p];
switch(type) {
case CMD_DATA:
case CMD_CONTROL:
break; // OK.
default:
msg("PpCmd::thawFrom(): Trouble decoding %p at offset %d (got 0x%x not 0/1/2)", buf, p, buf[p]);
type = CMD_NONE;
return -1;
}
// count args
do {
p++;
p += strlen( &buf[p] ) + 1;
argc++;
} while(buf[p] != 0);
argv = new char *[argc+1];
// msg("Found %d args in thawing %d bytes from offset %d", argc, p-offset, offset);
// copy args
p = offset;
for(int a = 0; a < argc; a++) {
p++;
argv[a] = copystrings ? strdup(&buf[p]) : &buf[p];
p += strlen(&buf[p]) + 1;
}
argv[argc] = 0;
offset = p+1;