Re: No Graphics

New Message Reply Date view Thread view Subject view Author view

david pratt (pratt++at++bessie.cs.nps.navy.mil)
Wed, 19 Jan 94 23:00:07 -0800


I beg to differ with Michael Jones, I had to do this for a DIS interface
we did. Basiclly, what I did is not call pfFrame or pfSync in the main loop.

As long as you don't laugh too much, here is my code (version 1.0, running
4.0.5 on an Extreme) that seems to work. I did open a 2D window using GL.

/*
   This is the start of the world modeler.
   Usage world_mod [Network port] [database file]
   assumes port 3001 and
           database at ../namedb/dummydata.dat
Thu Dec 9 00:34:51 PST 1993 - DRP - Created

*/
// cute method to share global varables without having multi defs
#define __COMMON__
#define __COMMON_WM__

      
#include "tcpip.h"
#include "G_data.h"
#include "WM.h"
#include "modem.h"

#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>

#define ALL_MASK 0x0F

#define LINE_LEN 80

/*terrain database stuff*/
pfScene *scene;
pfGroup *root;

main(int argc, char *argv[])
{

  int socket[10]; // the sockets that we are to connect to janus
  int jan = 0; //we are going to use only one janus
  int mess_type;
  int vid = 0;
  char messbuff[1023],arenaname[FILENAME_SIZE],terrain_file[FILENAME_SIZE],
       model_file[FILENAME_SIZE],ether_interf[FILENAME_SIZE];
  char waitmsg[255];
  int loopcnt = 0, ix = 0;
  float last_time = 0;

  float curtime,starttime;
  struct tms timebuffer;

  foreground();
  /*make sure the program is started correctly*/
  if(argc > 4){
    printf("Usage: %s [Config file] [Network port] [database file]\n", argv[0]);
    exit(0);
  }

  //read the configuration file
  if((argc >= 2) && (argc <= 4)){
    read_config_file(argv[1],model_file,terrain_file);
  }
  else{
    read_config_file("Dummy",model_file,terrain_file);
  }

  /* ************************************************************ */
  /* * STEP 1: Read the name database table that JANUS is also * */
  /* * using. * */
  /* ************************************************************ */

  /* Initialize performer */
  pfInit();
  pfConfig();

  //don't blank the screen
  blanktime(0);
  foreground();
  set_up();

  //Find the database file
  if(argc == 4){
    strcpy(terrain_file,argv[3]);
  }
  printf("Using Terrain database %s\n",terrain_file);
  scene = pfNewScene();
  if(strcmp("NONE",terrain_file)){
    if ((root = LoadFlt(terrain_file)) == NULL) {
      printf("Unable to read the terrain datafile %s\n",terrain_file);
      pfExit();
      exit(-1);
    }
  }
  else{
    root = pfNewGroup();
  }
  pfAddChild(scene, root);
  /* Set up the intersection mask for the root node */
   pfNodeTravMask(root,PFTRAV_ISECT,ALL_MASK,
                   PFTRAV_SELF|PFTRAV_DESCEND, PF_SET);
   pfSync();

  /* Allocate the memory for the entity arrays, and set all to NOSHOW */
  initialize_vehicle_arrays();

#ifdef TRACE
  cerr <<"Init veh arrays done\n";
#endif

  /* Read the dynamic models def file and constuct the tree */
  setup_type_table(model_file);
  if (load_veh_data_file() == -1) // jxxl
     printf("Error in loading vehicle file data\n");

  //zero out the clock
  pfInitClock(); // jxxl - removed arg of 0 - compile error

  starttime = times(&timebuffer) /(float)HZ;

  /************************************************************************/
  /******************** Main Application Simulation Loop ******************/
  while(TRUE){
/*
    if(!(loopcnt %10))
      printf("Start of cycle %3d\n",loopcnt);
*/
    loopcnt++;

    //handle the inputs
    process_inputs();

    //Handle the DIS network stuff now
    //read the network
    parse_net_pdus();

    /* Establish a time delta and then update last_time to now */
/* does not work on the extremes
    G_curtime = pfGetTime();
    G_delta_time = G_curtime - last_time;
    last_time = G_curtime;
*/
    curtime = times(&timebuffer) / (float)HZ;
    G_curtime = curtime - starttime;;
    G_delta_time = curtime - last_time;
    last_time = curtime;

    //move all of the network entities and myself
    update_entities();
    //draw the 2D map
    drawmap();
  }
  
}

void exitroutine()
// That is all she wrote
{
  void htl_range(),e2_range();

  htl_range();
  e2_range();

  printf("Graceful exit. \n");
   
  //kill the Janus Recieve process
  kill(L_Janus_pid,SIGKILL);
  net_close();
  /* Exit performer processes */
  pfExit();
  exit(0);
}

int grnd_orient(pfCoord *posture)
// This function set the Z location value and the pitch and roll values
// once the X-Y position and heading are set.
{
   pfIsect result;
   pfSeg segment;
   pfSeg *sp = &segment;

   /* make a ray looking "down" at terrain */
   PFCOPY_VEC3(segment.pos, posture->xyz);
   segment.pos[Z] += 1000.0f;
   PFSET_VEC3(segment.dir, 0.0f, 0.0f, -1.0f);
   pfNormalizeVec3(segment.dir);
   segment.length = 5000.0f;

//printf("IN %10.2f %10.2f %10.2f\n",
// segment.pos[X],segment.pos[Y],segment.pos[Z]);
   /* find intersection with terrain */
   result.node = NULL;
   if ( pfSegsIsectNode(root, &sp, 1, PFTRAV_IS_PRIM|PFTRAV_IS_NORM,
          ALL_MASK, NULL, &result, NULL) ) {
      pfXformPt3(result.point, result.point, result.xform);
      pfXformPt3(result.normal, result.normal, result.xform);
      pfNormalizeVec3 ( result.normal );
      posture->xyz[Z] = result.point[PF_Z];
      if (result.flags & PFIS_NORM) {
        pfVec3 head, head90;
        float sh, ch;
        float dotp;

        pfSinCos(posture->hpr[HEADING], &sh, &ch);
        head[0] = -sh;
        head[1] = ch;
        head[2] = 0.0f;
        dotp = PFDOT_VEC3(head, result.normal);
        posture->hpr[PITCH] = pfArcCos(dotp) - 90.0f;
        head90[0] = ch;
        head90[1] = sh;
        head90[2] = 0.0f;
        dotp = PFDOT_VEC3(head90, result.normal);
        head90[2] = 0.0f;
        dotp = PFDOT_VEC3(head90, result.normal);
        posture->hpr[ROLL] = 90.0f - pfArcCos(dotp);

#ifdef DEBUG
         cerr << "GRND_ORIENT POSTURE X = " << posture->xyz[X] << " Y = "
              << posture->xyz[Y] << " Z = " << posture->xyz[Z] << endl;
         cerr << " H = " << posture->hpr[X] << " P = "
              << posture->hpr[Y] << " R = " << posture->hpr[Z] << endl;
#endif
         return TRUE;
         }
      else
         return FALSE;
      }
   else
      return FALSE;
}

NOTE: I took ous some of the Network / other stuff code to focus on the
database issues.
   Dave

Dave Pratt pratt++at++cs.nps.navy.mil (408) 656-2865
Department of Computer Science, Naval Postgraduate School, Monterey, CA 93943
These are my opinions, talk to the PAO for the Navy's.


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:50:09 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.