Re: pfuPath routines

New Message Reply Date view Thread view Subject view Author view

Michael Jones (mtj++at++babar)
Tue, 31 May 1994 18:11:08 -0700


On May 31, 5:20pm, Drew Hess wrote:
> Subject: pfuPath routines

:I am looking for documentation or (preferably) some example code that details
:the use of the pfuPath routines in libpfu.

man pfupath is the first source. The idea is that a path is a list of
segments,
each of which is either a vector or an arc. The handy thing is that if you set
a radius of curvature, the path routines will make an arc for you that joins
the two vectors. This is how the truck is sent about the performer town demo.

:I realize that libpfu is
:unsupported and subject to change in future releases, but I am hoping that
:someone out there has made good use of these routines. I've started by
looking
:at the path.c source for libpfu, but some actual examples of its use would be
:helpful.

If you develop improvements for the path logic send it to us and we'll include
it in future releases of IRIS Performer.

Here are the path-related excerpts from the "IRIS Performer Town" demo that's
in buttonfly in the demos account. That demo uses a version of perfly that
takes names of models and their paths from the command line (via the "A"
keyword) and maintains a list of vehicles based on this information. Once the
argument list has been processed, a trip is made through the list to load each
model with a pfDCS node above it and to load its path definition as well.
Finally, each model is advanced along the path by one time step in the main
simulation loop. Here are the code fragments:

==================================================================
= handy structure definition used later in code
==================================================================

/* autopilot vehicle support */
typedef struct
{
    char modelName[PF_MAXSTRING];
    char pathName[PF_MAXSTRING];
    char vehicleName[PF_MAXSTRING];
    pfDCS *dcs;
    pfuPath *path;
    pfVec3 xyz;
    pfVec3 hpr;
} Vehicle;

#define MAX_VEHICLES 32
Vehicle vehicle[MAX_VEHICLES] = {"", "", "", NULL, NULL, {0,0,0}, {0,0,0}};
long vehicles = 0;

==================================================================
= parse vehicle definitions: remember vehicles and paths
==================================================================

    /* process command-line arguments */
    while ((opt = getopt(argc, argv, OptionStr)) != -1)
    {
        /* specify "autopilot" vehicle */
        case 'A':
            {
            if (vehicles < MAX_VEHICLES)
            {
                /* initialize vehicle defininition */
                vehicle[vehicles].modelName[0] = '\0';
                vehicle[vehicles].pathName[0] = '\0';
                sprintf(vehicle[vehicles].vehicleName, "%d", vehicles);
                vehicle[vehicles].dcs = NULL;
                vehicle[vehicles].path = NULL;

                /* parse file names from argument */
                sscanf(optarg, "%[^,],%[^,],%s",
                    vehicle[vehicles].modelName,
                    vehicle[vehicles].pathName,
                    vehicle[vehicles].vehicleName);

                /* increment vehicle count */
                vehicles++;
            }
            else
                pfNotify(PFNFY_INFO, PFNFY_PRINT,
                    "Too many autopilot vehicles");
            }
            break;

==================================================================
= pass through vehicle list: loading vehicles and paths
==================================================================

    /* load each of the autopilot vehicles */
    for (i = 0; i < vehicles; i++)
    {
        long j;

        /* has file already been loaded ? */
        for (j = 0, root = NULL; j < i && root == NULL; j++)
            if (strcmp(vehicle[i].modelName, vehicle[j].modelName) == 0)
                root = pfGetChild(vehicle[j].dcs, 0);

        /* load named file */
        if (root == NULL)
            root = LoadFile(vehicle[i].modelName, NULL);
        Loaded = 0;

        /* create new vehicle and attach model to it */
        if (root != NULL)
        {
            /* load database */
            vehicle[i].dcs = pfNewDCS();
            pfAddChild(vehicle[i].dcs, root);
            pfAddChild(scene, vehicle[i].dcs);

            /* load path */
            vehicle[i].path = pfuNewPath();
            pfuAddFile(vehicle[i].path, vehicle[i].pathName);
        }
    }

==================================================================
= advance each vehicle during each trip through the simulation
==================================================================

        /* simulate each autopilot vehicle */
        for (i = 0; i < vehicles; i++)
            if (vehicle[i].dcs != NULL && vehicle[i].path != NULL)
            {
                /* advance along path */
                pfuFollowPath(vehicle[i].path,
                    1.0/pfGetFrameRate(),
                    vehicle[i].xyz,
                    vehicle[i].hpr);

                /* update vehicle DCS */
                pfDCSRot(vehicle[i].dcs,
                    vehicle[i].hpr[PF_H],
                    vehicle[i].hpr[PF_P],
                    vehicle[i].hpr[PF_R]);
                pfDCSTrans(vehicle[i].dcs,
                    vehicle[i].xyz[PF_X],
                    vehicle[i].xyz[PF_Y],
                    vehicle[i].xyz[PF_Z]);
            }

-- 

Be seeing you, Phone:415.390.1455 Fax:415.390.2658 M/S:9U-590 Michael T. Jones Silicon Graphics, Advanced Graphics Division mtj++at++sgi.com 2011 N. Shoreline Blvd., Mtn. View, CA 94039-7311


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:18 PDT

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