Creating a Scene

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <Performer/pf/pfChannel.h>
#include <Performer/pf/pfEarthSky.h>
#include <Performer/pf/pfLightSource.h>
#include <Performer/pf/pfGroup.h>
#include <Performer/pfdu.h>
#include <pfcave.h>

void create_scene(pfChannel *chan,int argc,char **argv);
void load_objects(int argc,char **argv,pfGroup *parent);
void define_earthsky(pfChannel *chan);


int main(int argc,char **argv)
{
 pfInit();
 pfCAVEConfig(&argc,argv,NULL);
 pfConfig();
 pfCAVEInitChannels();
 create_scene(pfCAVEMasterChan(),argc,argv);
 define_earthsky(pfCAVEMasterChan());
 while (!getbutton(ESCKEY))
	{
	pfSync();
	pfCAVEPreFrame();
	pfFrame();
	pfCAVEPostFrame();
	}
 CAVEHalt();
 pfExit();
 return 0;
}

void create_scene(pfChannel *chan,int argc,char **argv)
{
/* Create a pfScene */
 pfScene *scene = new pfScene;
 pfGeoState *gstate = new pfGeoState;
 pfGroup *group = new pfGroup;
/* Set up the default GeoState */
 gstate->setMode(PFSTATE_ENLIGHTING, PF_ON);
 gstate->setMode(PFSTATE_CULLFACE, PFCF_OFF);
 scene->setGState(gstate);
/* Add a light with default settings */
 scene->addChild(new pfLightSource);
/* Add the group, and load the objects under it */
 scene->addChild(group);
 load_objects(argc,argv,group);
/* Assign the scene to the display channel */
 chan->setScene(scene);
}

void load_objects(int argc,char **argv,pfGroup *parent)
{
 int i;
 pfNode *obj;
 if (argc < 2)
	{
	fprintf(stderr,"Usage: %s objectfiles\n",argv[0]);
	pfExit();
	exit(1);
	}
/* Load the object files, and put them under the parent group */
 for (i=1; i < argc; i++)
	{
	if (obj = pfdLoadFile(argv[i]))
		parent->addChild(obj);
	else
		{
		pfExit();
		exit(1);
		}
	}
}

void define_earthsky(pfChannel *chan)
{
 pfEarthSky *esky = new pfEarthSky();
 esky->setMode(PFES_BUFFER_CLEAR, PFES_SKY_GRND);
 esky->setAttr(PFES_GRND_HT, 0.0f);
 esky->setColor(PFES_GRND_FAR, 0.3f, 0.1f, 0.0f, 1.0f);
 esky->setColor(PFES_GRND_NEAR, 0.5f, 0.3f, 0.1f, 1.0f);
 chan->setESky(esky);
}


Previous page    Table of contents    Next page

Last modified 5 February 1996.

Dave Pape, pape@evl.uic.edu