Skip to content
Snippets Groups Projects
szgPartiview.cc 43.2 KiB
Newer Older
/*
 * Syzygy-related functions for szgPartiview, including main program.
 */

static char local_id[] = "$Id$";

 * Revision 1.18  2010/04/14 21:49:41  slevy
 * Get the head transformation right so that "where" is the inverse of "jump".
 *
slevy's avatar
slevy committed
 * Revision 1.17  2009/03/28 22:48:47  slevy
 * Add some debug code (matstr()).
 * Re-orthogonalize the matrix in FlyNav::navUpdate().
 * Otherwise it'll blow up within a few dozen iterations.
 *
 * Revision 1.16  2009/03/27 16:30:29  slevy
 * Add first attempt at flyer navigation.
 * New "-fly" config option, and "fly <buttonpov>,<buttoncenter>,<tspeed>,<rspeed>"
 * control command.  I don't know which button is which, so it's configurable on the fly.
 *
 * Revision 1.15  2009/03/27 03:26:51  slevy
 * When "jump"ing, align the target point with the head's position,
 * rather than the CAVE origin.  Use position only -- keep the orientation
 * of the CAVE.
 *
 * This still might not be right.  Might be better to put the
 * target point just behind the head, so an origin crosshair doesn't bug us.
 *
 * Revision 1.14  2009/03/26 20:47:13  slevy
 * Add -plog option to control logging.  If present, each szg process logs all msg()/warn() messages
 * to "parti.NNNN.log" for ProcessID NNNN.
 *
 * 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"

# include "winjunk.h"
#endif
 
#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;
// 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];
}
/* =================================================================== */

class FlyNav {
  public:
    bool   flying;	// Flying enabled?  If not, ignore all the below.
    int    bpov;	// While this button# pressed, fly, with point-of-view as rotation center
    int    bcen;	// While this button# pressed, fly, with "center" as rot. center
    float  tspeed;	// translation speed scale factor
    float  rspeed;	// rotation speed scale factor
    int    bstarted;	// has flying started?  If so, on which button?  Else -1.
Loading
Loading full blame...