[Fwd: clouds]

New Message Reply Date view Thread view Subject view Author view

Svend Tang-Petersen (svend++at++digi.lego.com)
Wed, 27 May 1998 09:26:41 +0200


> Hi Micheal.
>
> Clouds: a repeated texture on a large polygon, and you change texture
> (u,v) as a function of
> time to make it move.
>
> Fire: find a sequence of textures/movie clip with a fire. Load the
> textures into an array, and
> change the texture on your polygon/billboard for each frame to
> animate.
>
> --
>
> Svend Tang-Petersen, MSc
>
> Silicon Graphics
> Stationsparken 25
> 2600 Glostrup
> Denmark
>
> svend++at++copen.sgi.com
>
> Currently:
>
> LEGO, wiZards
> Kloevermarken 120
> 7190 Billund
> Denmark
>
> svend++at++digi.lego.com
>
> ------------------------------------------------------------------------
>
> /* clouds.c Do moving clouds, and add ligthing effects
> *
> * Usage: clouds
> *
> * Key commands:
> *
> * <f> key - decrease requested frame rate
> * <F> key - increase requested frame rate
> * <p> key - change phase
> * <h> key - print help
> * <l> key - toggle load managment
> * <r> key - reset transformer position
> * <s> key - toggle statistics
> * ESCAPE key - exit program
> *
> */
>
> #include <Performer/pf.h>
> #include <Performer/pfdu.h>
> #include <Performer/pfutil.h>
> #include <Performer/pfui.h>
> #include <stdio.h>
>
> /* Function prototypes */
>
> void windowSetup( char *title );
> void sceneSetup(void);
> void channelSetup(void);
> void xformerSetup(void);
> void updateView(void);
> void updateSim(void);
> void changeFrameRate( int increment );
> void changePhase(void);
> void toggleLoadMgmt(void);
> void handleEvents(void);
> void printHelp( char *progName );
>
> /* Global variables */
>
> pfScene *scene;
> pfChannel *chan;
> pfGeoSet *cloud_gset;
> pfVec2 *cloud_texcoords;
> char *progName;
> int exitFlag = 0, showStats = 0, handleStress = 0;
> float cloud_x = 0.0f;
> pfuEventStream events;
> pfuMouse mouse;
> pfiTDFXformer *xformer;
>
> int main( int argc, char *argv[] )
> {
>
> extern char *progName;
> extern int exitFlag;
>
> /* Initialize Performer and create the pipe */
>
> pfInit();
> pfuInitUtil();
> pfiInit();
> pfConfig();
>
> /* Set up a window, scene graph and channel */
>
> progName = argv[0];
> windowSetup( progName );
> sceneSetup();
> channelSetup();
> xformerSetup();
>
> /* Simulate */
>
> printHelp( progName );
> pfInitClock( 0.0f );
> pfPhase( PFPHASE_FREE_RUN );
> pfFrameRate( 30.0f );
>
> while ( !exitFlag ) {
> pfSync();
> updateView();
> pfFrame();
> updateSim();
> };
>
> /* Clean up */
>
> pfuExitInput();
> pfuExitUtil();
> pfExit();
> return 0;
>
> }
>
> void windowSetup( char *title )
> {
>
> pfPipe *pipe;
> pfPipeWindow *win;
>
> pipe = pfGetPipe(0);
> win = pfNewPWin( pipe );
> pfPWinName( win, title );
> pfPWinSize( win, 800, 500 );
>
> pfPWinType( win, PFPWIN_TYPE_X );
> pfuInitInput( win, PFUINPUT_X );
>
> pfOpenPWin( win );
>
> }
>
> void sceneSetup(void)
> {
>
> extern pfScene *scene;
> extern pfGeoSet *cloud_gset;
> extern pfVec2 *cloud_texcoords;
> pfGeode *cloud_geode;
> pfGeoState *cloud_gstate;
> pfNode *model;
> pfVec3 *cloud_verts;
> pfVec4 *cloud_colors;
> pfTexture *cloud_tex;
> pfTexEnv *cloud_tev;
> pfLightSource *light;
> void *arena;
>
> scene = pfNewScene();
> light = pfNewLSource();
> /* pfLSourceOn( light ); */
> pfLSourcePos( light, 2500.0f, 2200.0f, 2000.0f, 0.0f );
> pfLSourceColor( light, PFLT_AMBIENT, 1.0f, 1.0f, 1.0f );
> pfAddChild( scene, light );
>
> pfFilePath("/usr/share/Performer/data/town:.:Textures");
> model = pfdLoadFile("town.pfb");
> pfAddChild( scene, model );
>
> /* Add a top polygon to hold clouds that slide */
>
> cloud_gset = pfNewGSet( arena );
> pfGSetPrimType( cloud_gset, PFGS_QUADS );
> pfGSetNumPrims( cloud_gset, 1 );
>
> cloud_geode = pfNewGeode();
> pfAddGSet( cloud_geode, cloud_gset );
>
> cloud_verts= (pfVec3 *)pfMalloc( 4 * sizeof(pfVec3), arena );
> cloud_colors= (pfVec4 *)pfMalloc( 4 * sizeof(pfVec4), arena );
> cloud_texcoords= (pfVec2 *)pfMalloc( 4 * sizeof(pfVec2), arena );
>
> pfSetVec3( cloud_verts[0],-1000.0f,-1000.0f, 550.0f );
> pfSetVec3( cloud_verts[1],-1000.0f, 6000.0f, 550.0f );
> pfSetVec3( cloud_verts[2], 6000.0f, 6000.0f, 550.0f );
> pfSetVec3( cloud_verts[3], 6000.0f,-1000.0f, 550.0f );
>
> pfSetVec4( cloud_colors[0], 1.0f, 1.0f, 1.0f, 1.0f );
> pfSetVec4( cloud_colors[1], 1.0f, 1.0f, 1.0f, 1.0f );
> pfSetVec4( cloud_colors[2], 1.0f, 1.0f, 1.0f, 1.0f );
> pfSetVec4( cloud_colors[3], 1.0f, 1.0f, 1.0f, 1.0f );
>
> pfSetVec2( cloud_texcoords[0], 0.0f, 0.0f );
> pfSetVec2( cloud_texcoords[1], 0.0f, 4.0f );
> pfSetVec2( cloud_texcoords[2], 4.0f, 4.0f );
> pfSetVec2( cloud_texcoords[3], 4.0f, 0.0f );
>
> pfGSetAttr( cloud_gset, PFGS_COORD3, PFGS_PER_VERTEX, cloud_verts, NULL );
> pfGSetAttr( cloud_gset, PFGS_COLOR4, PFGS_PER_VERTEX, cloud_colors, NULL );
> pfGSetAttr( cloud_gset, PFGS_TEXCOORD2, PFGS_PER_VERTEX, cloud_texcoords, NULL );
>
> cloud_gstate = pfNewGState( arena );
> cloud_tex = pfNewTex( arena );
> pfTexFormat( cloud_tex, PFTEX_INTERNAL_FORMAT, PFTEX_RGB_5 );
> pfLoadTexFile( cloud_tex, "clouds.rgb" );
> pfTexRepeat( cloud_tex, PFTEX_WRAP_S, PFTEX_REPEAT );
> pfTexRepeat( cloud_tex, PFTEX_WRAP_T, PFTEX_REPEAT );
>
> cloud_tev = pfNewTEnv( arena );
> pfGStateMode( cloud_gstate, PFSTATE_ENTEXTURE, PF_ON );
> pfGStateAttr( cloud_gstate, PFSTATE_TEXTURE, cloud_tex );
> pfGStateAttr( cloud_gstate, PFSTATE_TEXENV, cloud_tev );
>
> pfGSetGState( cloud_gset, cloud_gstate );
> pfAddChild( scene, cloud_geode );
>
> }
>
> void channelSetup(void)
> {
>
> extern pfScene *scene;
> extern pfChannel *chan;
> pfPipe *pipe;
> pfSphere bsphere;
> pfEarthSky *esky;
>
> pipe = pfGetPipe(0);
> chan = pfNewChan( pipe );
> pfChanScene( chan, scene );
>
> esky = pfNewESky();
> pfESkyColor( esky, PFES_GRND_NEAR, 0.0f, 0.4f, 0.0f, 1.0f );
> pfESkyColor( esky, PFES_GRND_FAR, 0.0f, 0.4f, 0.0f, 1.0f );
> pfESkyMode( esky, PFES_BUFFER_CLEAR, PFES_SKY_CLEAR );
> pfChanESky( chan, esky );
>
> pfGetNodeBSphere( scene, &bsphere );
> pfChanNearFar( chan, 1.0f, 100.0f * bsphere.radius );
> pfChanFOV( chan, 60.0f, -1.0f );
>
> }
>
> void xformerSetup(void)
> {
>
> extern pfScene *scene;
> extern pfChannel *chan;
> extern pfuEventStream events;
> extern pfiTDFXformer *xformer;
> extern pfuMouse mouse;
> pfCoord view;
> pfSphere bsphere;
> pfBox bbox;
> float speed;
>
> xformer = pfiNewTDFXformer( pfGetSharedArena() );
> pfiXformerAutoInput( xformer, chan, &mouse, &events );
> pfiXformerAutoPosition( xformer, chan, NULL );
> pfiSelectXformerModel( xformer, PFITDF_FLY );
>
> pfGetNodeBSphere( scene, &bsphere );
> pfSetVec3( view.xyz, 2472.0f, 2200.0f, 4.0f );
> pfSetVec3( view.hpr, -110.0f, 0.0f, 0.0f );
> pfiXformerCoord( xformer, &view );
> pfiXformerResetCoord( xformer, &view );
>
> pfuTravCalcBBox( scene, &bbox );
> speed = bsphere.radius / 30.0f;
> pfiXformerLimits( xformer, speed, 90.0f, speed/2.0f, &bbox );
>
> }
>
> void updateView(void)
> {
>
> extern pfuMouse mouse;
> extern pfiTDFXformer *xformer;
>
> pfuGetMouse( &mouse );
> pfiUpdateXformer( xformer );
>
> }
>
> void updateSim(void)
> {
>
> extern pfChannel *chan;
> extern int showStats;
> extern pfVec2 *cloud_texcoords;
> extern pfGeoSet *cloud_gset;
> extern float cloud_x;
> float time;
> int i;
>
> time = pfGetTime();
>
> /* make the sky drift */
>
> cloud_x = cloud_x + 0.001f;
> if (cloud_x > 0.0f) cloud_x = cloud_x - 4.0f;
>
> pfSetVec2( cloud_texcoords[0], 0.0f, -cloud_x );
> pfSetVec2( cloud_texcoords[1], 0.0f, -cloud_x + 4.0f );
> pfSetVec2( cloud_texcoords[2], 4.0f, -cloud_x + 4.0f );
> pfSetVec2( cloud_texcoords[3], 4.0f, -cloud_x );
>
> pfGSetAttr( cloud_gset, PFGS_TEXCOORD2, PFGS_PER_VERTEX,
> cloud_texcoords, NULL );
>
> /* check keyboard events and draw channel stats */
>
> handleEvents();
> if (showStats) pfDrawChanStats( chan );
>
> }
>
> void changeFrameRate(int increment)
> {
>
> float vrate;
> int fields;
>
> fields = pfGetFieldRate();
> fields += increment;
>
> if ( fields < 0 ) fields = 1;
>
> pfFieldRate( fields );
>
> }
>
> void changePhase(void)
> {
>
> int currPhase;
>
> currPhase = pfGetPhase();
> switch (currPhase) {
>
> case PFPHASE_FREE_RUN : currPhase = PFPHASE_LIMIT;
> break;
>
> case PFPHASE_LIMIT : currPhase = PFPHASE_FLOAT;
> break;
>
> case PFPHASE_FLOAT : currPhase = PFPHASE_LOCK;
> break;
>
> case PFPHASE_LOCK : currPhase = PFPHASE_FREE_RUN;
> break;
>
> default : currPhase = PFPHASE_FREE_RUN;
> break;
>
> };
>
> pfPhase(currPhase);
>
> }
>
> void toggleLoadMgmt(void)
> {
>
> extern pfChannel *chan;
> float frac = 1.0, lo = 0.6, hi = 0.8;
> float scale = 0.1, max = 30.0f;
>
> handleStress = !handleStress;
> if (!handleStress) {
> scale = 0.0f;
> pfChanStress( chan, 1 );
> }
>
> pfChanStressFilter( chan, frac, lo, hi, scale, max );
> printf("Load managment is %s\n", handleStress ? "ON" : "OFF" );
>
> }
>
> void handleEvents(void)
> {
>
> extern pfuEventStream events;
> extern char *progName;
> extern int exitFlag;
> int i, j;
> int key, dev, val, numDevs;
> pfuEventStream *pEvents = &events;
>
> pfuGetEvents( &events );
> numDevs = pEvents -> numDevs;
>
> for ( j= 0; j < numDevs; ++j ) {
>
> dev = pEvents -> devQ[j];
> val = pEvents -> devVal[j];
>
> if ( pEvents -> devCount[dev] > 0 ) {
>
> switch ( dev ) {
>
> case PFUDEV_REDRAW: pEvents -> devCount[dev] = 0;
> break;
>
> case PFUDEV_WINQUIT: exitFlag = 1;
> pEvents -> devCount[dev] = 0;
> break;
>
> case PFUDEV_KEYBD: for ( i= 0; i < pEvents -> numKeys; ++i ) {
>
> key = pEvents -> keyQ[i];
> if ( pEvents -> keyCount[key] ) {
>
> switch ( key ) {
>
> case 27: exitFlag = 1;
> break;
>
> case 'f': changeFrameRate(1); break;
>
> case 'F': changeFrameRate(-1); break;
>
> case 'p': changePhase(); break;
>
> case 'h': printHelp( progName );
> break;
>
> case 'r': pfiStopXformer( xformer );
> pfiResetXformerPosition( xformer );
> break;
>
> case 'l': toggleLoadMgmt(); break;
>
> case 's': showStats = !showStats;
> break;
>
> default : break;
>
> };
> };
> };
>
> pEvents -> devCount[dev] = 0;
> break;
>
> default: break;
>
> }
> }
> };
>
> pEvents -> numKeys = 0;
> pEvents -> numDevs = 0;
>
> }
>
> void printHelp( char *progName )
> {
>
> printf("\n%s - playing with fire\n\n"
> "<f> key\t\t\t - decrease the requested frame rate\n"
> "<F> key\t\t\t - increase the requested frame rate\n"
> "<p> key\t\t\t - change phase\n"
> "<h> key\t\t\t - print help\n"
> "<r> key\t\t\t - reset transformer position\n"
> "<l> key\t\t\t - toggle load managment\n"
> "<s> key\t\t\t - toggle graphics stats\n"
> "ESCAPE key\t\t - exit the program\n\n",
> progName );
>
> }
>
> ------------------------------------------------------------------------
>
> Name: clouds.rgb
> clouds.rgb Type: RGB Image (image/x-rgb)
> Encoding: base64
>
> ------------------------------------------------------------------------
>
> /* flames.c make a moving and textured flag.
> * Add sequence of animated textures.
> * Add moving clouds.
> *
> * Usage: flames
> *
> * Key commands:
> *
> * <f> key - decrease requested frame rate
> * <F> key - increase requested frame rate
> * <p> key - change phase
> * <h> key - print help
> * <l> key - toggle load managment
> * <r> key - reset transformer position
> * <s> key - toggle statistics
> * ESCAPE key - exit program
> *
> */
>
> #include <Performer/pf.h>
> #include <Performer/pfdu.h>
> #include <Performer/pfutil.h>
> #include <Performer/pfui.h>
> #include <stdio.h>
>
> /* type definitions */
>
> typedef struct MovieData
> {
> pfTexture *frame;
> } MovieData;
>
> /* Function prototypes */
>
> void windowSetup( char *title );
> void sceneSetup(void);
> void channelSetup(void);
> void xformerSetup(void);
> void updateView(void);
> void updateSim(void);
> void changeFrameRate( int increment );
> void changePhase(void);
> void toggleLoadMgmt(void);
> void handleEvents(void);
> void printHelp( char *progName );
>
> /* Global variables */
>
> pfScene *scene;
> pfChannel *chan;
> pfDCS *rotDCS;
> pfGeoSet *gset, *bb_gset, *cloud_gset;
> pfGeoState *bb_gstate;
> pfVec2 *cloud_texcoords;
> pfVec3 *verts;
> pfTexture *frame;
> MovieData movie[32];
> char *progName;
> int exitFlag = 0, showStats = 0, handleStress = 0, frame_no = 0;
> float cloud_x = 0.0f;
> pfuEventStream events;
> pfuMouse mouse;
> pfiTDFXformer *xformer;
>
> int main( int argc, char *argv[] )
> {
>
> extern char *progName;
> extern int exitFlag;
>
> /* Initialize Performer and create the pipe */
>
> pfInit();
> pfuInitUtil();
> pfiInit();
> pfConfig();
>
> /* Set up a window, scene graph and channel */
>
> progName = argv[0];
> windowSetup( progName );
> sceneSetup();
> channelSetup();
> xformerSetup();
>
> /* Simulate */
>
> printHelp( progName );
> pfInitClock( 0.0f );
> pfPhase( PFPHASE_FREE_RUN );
> pfFrameRate( 30.0f );
>
> while ( !exitFlag ) {
> pfSync();
> updateView();
> pfFrame();
> updateSim();
> };
>
> /* Clean up */
>
> pfuExitInput();
> pfuExitUtil();
> pfExit();
> return 0;
>
> }
>
> void windowSetup( char *title )
> {
>
> pfPipe *pipe;
> pfPipeWindow *win;
>
> pipe = pfGetPipe(0);
> win = pfNewPWin( pipe );
> pfPWinName( win, title );
> pfPWinSize( win, 800, 500 );
>
> pfPWinType( win, PFPWIN_TYPE_X );
> pfuInitInput( win, PFUINPUT_X );
>
> pfOpenPWin( win );
>
> }
>
> void sceneSetup(void)
> {
>
> extern pfScene *scene;
> extern pfGeoSet *gset, *bb_gset, *cloud_gset;
> extern pfVec3 *verts;
> extern pfTexture *frame;
> extern MovieData movie[32];
> extern pfGeoState *bb_gstate;
> extern pfVec2 *cloud_texcoords;
> pfGeode *geode, *cloud_geode;
> pfGeoState *gstate, *cloud_gstate;
> pfNode *model;
> pfVec2 *texcoords, *bb_texcoords;
> pfVec3 vec3, *bb_verts, *cloud_verts;
> pfVec4 *colors, *bb_colors, *cloud_colors;
> pfTexture *tex, *cloud_tex;
> pfTexEnv *tev, *bb_tev, *cloud_tev;
> pfSCS *scs;
> pfMatrix mat;
> pfLightSource *light;
> pfBillboard *bill;
> void *arena;
>
> int i;
> char *filename;
>
> scene = pfNewScene();
> light = pfNewLSource();
> /* pfLSourceOn( light ); */
> pfLSourcePos( light, 2500.0f, 2200.0f, 2000.0f, 0.0f );
> pfLSourceColor( light, PFLT_AMBIENT, 1.0f, 1.0f, 1.0f );
> pfAddChild( scene, light );
>
> pfFilePath("/usr/share/Performer/data/town:.:Textures");
> model = pfdLoadFile("town.pfb");
> pfAddChild( scene, model );
>
> /* make a flag to wave */
>
> arena = pfGetSharedArena();
> gset = pfNewGSet( arena );
> pfGSetPrimType( gset, PFGS_QUADS );
> pfGSetNumPrims( gset, 10 );
>
> verts = (pfVec3 *)pfMalloc( 40 * sizeof(pfVec3), arena );
> colors = (pfVec4 *)pfMalloc( 40 * sizeof(pfVec4), arena );
> texcoords = (pfVec2 *)pfMalloc( 40 * sizeof(pfVec2), arena );
>
> for ( i= 0; i < 10; i++ ) {
>
> /* pfSetVec2( texcoords[2*i ], 0.1f*i, 1.0f);
> pfSetVec2( texcoords[2*i+1], 0.1f*i, 0.0f);
>
> pfSetVec3( verts[2*i ], i * 2.0f, 0.0f, 10.0f );
> pfSetVec3( verts[2*i+1], i * 2.0f, 0.0f, -10.0f );
>
> pfSetVec4( colors[2*i ], 1.0, 1.0, 1.0, 1.0);
> pfSetVec4( colors[2*i+1], 1.0, 1.0, 1.0, 1.0); */
>
> pfSetVec2( texcoords[4*i ], 0.1f*i, 1.0f);
> pfSetVec2( texcoords[4*i+1], 0.1f*(i+1), 1.0f);
> pfSetVec2( texcoords[4*i+2], 0.1f*(i+1), 0.0f);
> pfSetVec2( texcoords[4*i+3], 0.1f*i, 0.0f);
>
> pfSetVec3( verts[4*i ], 0.0f, i* 0.2f, 1.0f );
> pfSetVec3( verts[4*i+1], 0.0f, (i+1)* 0.2f, 1.0f );
> pfSetVec3( verts[4*i+2], 0.0f, (1+i)* 0.2f, -1.0f );
> pfSetVec3( verts[4*i+3], 0.0f, i* 0.2f, -1.0f );
>
> pfSetVec4( colors[4*i ], 1.0, 1.0, 1.0, 1.0);
> pfSetVec4( colors[4*i+1], 1.0, 1.0, 1.0, 1.0);
> pfSetVec4( colors[4*i+2], 1.0, 1.0, 1.0, 1.0);
> pfSetVec4( colors[4*i+3], 1.0, 1.0, 1.0, 1.0);
>
> };
>
> pfGSetAttr( gset, PFGS_COORD3, PFGS_PER_VERTEX, verts, NULL );
> pfGSetAttr( gset, PFGS_COLOR4, PFGS_PER_VERTEX, colors, NULL );
> pfGSetAttr( gset, PFGS_TEXCOORD2, PFGS_PER_VERTEX, texcoords, NULL );
>
> geode = pfNewGeode();
> pfAddGSet( geode, gset );
>
> /* Load and apply a texture to flag */
>
> gstate = pfNewGState( arena );
> pfGStateMode( gstate, PFSTATE_CULLFACE, PFCF_OFF );
> /* pfFilePath( "." ); */
> tex = pfNewTex( arena );
> if ( pfLoadTexFile( tex, "wizard.rgb" ) != 0 ) {
> pfTexRepeat( tex, PFTEX_WRAP_S, PFTEX_CLAMP );
> pfTexRepeat( tex, PFTEX_WRAP_T, PFTEX_CLAMP );
>
> tev = pfNewTEnv( arena );
> pfGStateMode( gstate, PFSTATE_ENTEXTURE, PF_ON );
> pfGStateAttr( gstate, PFSTATE_TEXTURE, tex );
> pfGStateAttr( gstate, PFSTATE_TEXENV, tev );
> }
>
> pfGSetGState( gset, gstate );
>
> pfMakeTransMat( mat, 2488.6f, 2191.97f, 5.5f );
> scs = pfNewSCS( mat );
>
> pfAddChild( scs, geode );
> pfAddChild( scene, scs );
>
> /* Add a top polygon to hold clouds that slide */
>
> cloud_gset = pfNewGSet( arena );
> pfGSetPrimType( cloud_gset, PFGS_QUADS );
> pfGSetNumPrims( cloud_gset, 1 );
>
> cloud_geode = pfNewGeode();
> pfAddGSet( cloud_geode, cloud_gset );
>
> cloud_verts= (pfVec3 *)pfMalloc( 4 * sizeof(pfVec3), arena );
> cloud_colors= (pfVec4 *)pfMalloc( 4 * sizeof(pfVec4), arena );
> cloud_texcoords= (pfVec2 *)pfMalloc( 4 * sizeof(pfVec2), arena );
>
> pfSetVec3( cloud_verts[0],-1000.0f,-1000.0f, 550.0f );
> pfSetVec3( cloud_verts[1],-1000.0f, 6000.0f, 550.0f );
> pfSetVec3( cloud_verts[2], 6000.0f, 6000.0f, 550.0f );
> pfSetVec3( cloud_verts[3], 6000.0f,-1000.0f, 550.0f );
>
> pfSetVec4( cloud_colors[0], 1.0f, 1.0f, 1.0f, 1.0f );
> pfSetVec4( cloud_colors[1], 1.0f, 1.0f, 1.0f, 1.0f );
> pfSetVec4( cloud_colors[2], 1.0f, 1.0f, 1.0f, 1.0f );
> pfSetVec4( cloud_colors[3], 1.0f, 1.0f, 1.0f, 1.0f );
>
> pfSetVec2( cloud_texcoords[0], 0.0f, 0.0f );
> pfSetVec2( cloud_texcoords[1], 0.0f, 4.0f );
> pfSetVec2( cloud_texcoords[2], 4.0f, 4.0f );
> pfSetVec2( cloud_texcoords[3], 4.0f, 0.0f );
>
> pfGSetAttr( cloud_gset, PFGS_COORD3, PFGS_PER_VERTEX, cloud_verts, NULL );
> pfGSetAttr( cloud_gset, PFGS_COLOR4, PFGS_PER_VERTEX, cloud_colors, NULL );
> pfGSetAttr( cloud_gset, PFGS_TEXCOORD2, PFGS_PER_VERTEX, cloud_texcoords, NULL );
>
> cloud_gstate = pfNewGState( arena );
> cloud_tex = pfNewTex( arena );
> pfTexFormat( cloud_tex, PFTEX_INTERNAL_FORMAT, PFTEX_RGB_5 );
> pfLoadTexFile( cloud_tex, "clouds.rgb" );
> pfTexRepeat( cloud_tex, PFTEX_WRAP_S, PFTEX_REPEAT );
> pfTexRepeat( cloud_tex, PFTEX_WRAP_T, PFTEX_REPEAT );
>
> cloud_tev = pfNewTEnv( arena );
> pfGStateMode( cloud_gstate, PFSTATE_ENTEXTURE, PF_ON );
> pfGStateAttr( cloud_gstate, PFSTATE_TEXTURE, cloud_tex );
> pfGStateAttr( cloud_gstate, PFSTATE_TEXENV, cloud_tev );
>
> pfGSetGState( cloud_gset, cloud_gstate );
> pfAddChild( scene, cloud_geode );
>
> /* Add a single QUAD billboard with an RGBA texture */
>
> bb_gset = pfNewGSet( arena );
> pfGSetPrimType( bb_gset, PFGS_QUADS );
> pfGSetNumPrims( bb_gset, 1 );
>
> bb_verts = (pfVec3 *)pfMalloc( 4 * sizeof(pfVec3), arena );
> bb_colors = (pfVec4 *)pfMalloc( 4 * sizeof(pfVec4), arena );
> bb_texcoords = (pfVec2 *)pfMalloc( 4 * sizeof(pfVec2), arena );
>
> pfSetVec2( bb_texcoords[0], 0.0f, 0.0f );
> pfSetVec2( bb_texcoords[1], 1.0f, 0.0f );
> pfSetVec2( bb_texcoords[2], 1.0f, 1.0f );
> pfSetVec2( bb_texcoords[3], 0.0f, 1.0f );
>
> pfSetVec3( bb_verts[0], 0.0f, 0.0f, 0.0f );
> pfSetVec3( bb_verts[1], 2.0f, 0.0f, 0.0f );
> pfSetVec3( bb_verts[2], 2.0f, 0.0f, 3.0f );
> pfSetVec3( bb_verts[3], 0.0f, 0.0f, 3.0f );
>
> pfSetVec4( bb_colors[0], 1.0, 1.0, 1.0, 1.0);
> pfSetVec4( bb_colors[1], 1.0, 1.0, 1.0, 1.0);
> pfSetVec4( bb_colors[2], 1.0, 1.0, 1.0, 1.0);
> pfSetVec4( bb_colors[3], 1.0, 1.0, 1.0, 1.0);
>
> pfGSetAttr( bb_gset, PFGS_COORD3, PFGS_PER_VERTEX, bb_verts, NULL );
> pfGSetAttr( bb_gset, PFGS_COLOR4, PFGS_PER_VERTEX, bb_colors, NULL );
> pfGSetAttr( bb_gset, PFGS_TEXCOORD2, PFGS_PER_VERTEX, bb_texcoords, NULL );
>
> bb_gstate = pfNewGState( arena );
> pfGStateMode( bb_gstate, PFSTATE_CULLFACE, PFCF_OFF );
> /* pfFilePath("Textures"); */
> frame = pfNewTex( arena );
> pfTexFormat( frame, PFTEX_INTERNAL_FORMAT, PFTEX_RGBA_8 );
> pfLoadTexFile( frame, "f01");
> pfTexRepeat( frame, PFTEX_WRAP_S, PFTEX_CLAMP );
> pfTexRepeat( frame, PFTEX_WRAP_T, PFTEX_CLAMP );
>
> bb_tev = pfNewTEnv( arena );
> pfGStateMode( bb_gstate, PFSTATE_TRANSPARENCY, PFTR_ON );
> pfGStateMode( bb_gstate, PFSTATE_ENTEXTURE, PF_ON );
> pfGStateAttr( bb_gstate, PFSTATE_TEXTURE, frame );
> pfGStateAttr( bb_gstate, PFSTATE_TEXENV, bb_tev );
>
> pfGSetGState( bb_gset, bb_gstate );
>
> bill= pfNewBboard();
> pfSetVec3( vec3, 0.0f, 0.0f, 1.0f );
> pfBboardAxis( bill, vec3 );
> pfSetVec3( vec3, 2507.0f, 2199.8f, 8.2f );
> pfBboardPos( bill, 0, vec3 );
> pfAddGSet( bill, bb_gset );
> pfAddChild( scene, bill );
>
> /* load sequence of images for flame animation */
>
> filename = (char *)malloc(10 * sizeof(char));
> /* pfFilePath("Textures"); */
> for (i= 0; i < 32 ; i++ ) {
> movie[i].frame = pfNewTex( arena );
> printf("f%02i\n", i+1);
> sprintf( filename, "f%02i", i+1);
> pfTexFormat( movie[i].frame, PFTEX_INTERNAL_FORMAT, PFTEX_RGBA_8 );
> pfLoadTexFile( movie[i].frame, filename );
> pfTexRepeat( movie[i].frame, PFTEX_WRAP_S, PFTEX_CLAMP );
> pfTexRepeat( movie[i].frame, PFTEX_WRAP_T, PFTEX_CLAMP );
> }
>
> }
>
> void channelSetup(void)
> {
>
> extern pfScene *scene;
> extern pfChannel *chan;
> pfPipe *pipe;
> pfSphere bsphere;
> pfEarthSky *esky;
>
> pipe = pfGetPipe(0);
> chan = pfNewChan( pipe );
> pfChanScene( chan, scene );
>
> esky = pfNewESky();
> pfESkyColor( esky, PFES_GRND_NEAR, 0.0f, 0.4f, 0.0f, 1.0f );
> pfESkyColor( esky, PFES_GRND_FAR, 0.0f, 0.4f, 0.0f, 1.0f );
> pfESkyMode( esky, PFES_BUFFER_CLEAR, PFES_SKY_CLEAR );
> pfChanESky( chan, esky );
>
> pfGetNodeBSphere( scene, &bsphere );
> pfChanNearFar( chan, 1.0f, 100.0f * bsphere.radius );
> pfChanFOV( chan, 60.0f, -1.0f );
>
> }
>
> void xformerSetup(void)
> {
>
> extern pfScene *scene;
> extern pfChannel *chan;
> extern pfuEventStream events;
> extern pfiTDFXformer *xformer;
> extern pfuMouse mouse;
> pfCoord view;
> pfSphere bsphere;
> pfBox bbox;
> float speed;
>
> xformer = pfiNewTDFXformer( pfGetSharedArena() );
> pfiXformerAutoInput( xformer, chan, &mouse, &events );
> pfiXformerAutoPosition( xformer, chan, NULL );
> pfiSelectXformerModel( xformer, PFITDF_FLY );
>
> pfGetNodeBSphere( scene, &bsphere );
> pfSetVec3( view.xyz, 2472.0f, 2200.0f, 4.0f );
> pfSetVec3( view.hpr, -110.0f, 0.0f, 0.0f );
> pfiXformerCoord( xformer, &view );
> pfiXformerResetCoord( xformer, &view );
>
> pfuTravCalcBBox( scene, &bbox );
> speed = bsphere.radius / 30.0f;
> pfiXformerLimits( xformer, speed, 90.0f, speed/2.0f, &bbox );
>
> }
>
> void updateView(void)
> {
>
> extern pfuMouse mouse;
> extern pfiTDFXformer *xformer;
>
> pfuGetMouse( &mouse );
> pfiUpdateXformer( xformer );
>
> }
>
> void updateSim(void)
> {
>
> extern pfChannel *chan;
> extern int showStats, frame_no;
> extern pfVec2 *cloud_texcoords;
> extern pfVec3 *verts;
> extern pfGeoSet *gset, *cloud_gset;
> extern pfGeoState *bb_gstate;
> extern pfTexture *frame;
> extern MovieData movie[32];
> extern int frame_no;
> extern float cloud_x;
> float sin, cos, sin1, cos1, time;
> int i;
>
> time = pfGetTime();
>
> /* make the sky drift */
>
> cloud_x = cloud_x + 0.001f;
> if (cloud_x > 0.0f) cloud_x = cloud_x - 4.0f;
>
> pfSetVec2( cloud_texcoords[0], 0.0f, -cloud_x );
> pfSetVec2( cloud_texcoords[1], 0.0f, -cloud_x + 4.0f );
> pfSetVec2( cloud_texcoords[2], 4.0f, -cloud_x + 4.0f );
> pfSetVec2( cloud_texcoords[3], 4.0f, -cloud_x );
>
> pfGSetAttr( cloud_gset, PFGS_TEXCOORD2, PFGS_PER_VERTEX, cloud_texcoords, NULL );
>
> /* wave the flag */
>
> for (i= 0; i < 10 ; i++ ) {
> pfSinCos( time *120.0f - 60.0f * i, &sin, &cos );
> pfSinCos( time *120.0f - 60.0f *(i+1), &sin1, &cos1 );
> pfSetVec3( verts[4*i ], i* 0.02f* cos , i* 0.2f, 1.0f - i*i*0.005f );
> pfSetVec3( verts[4*i+1], (i+1)*0.02f* cos1, (i+1)* 0.2f, 1.0f - (i+1)*(i+1)*0.005f );
> pfSetVec3( verts[4*i+2], (i+1)*0.02f* cos1, (1+i)* 0.2f, -1.0f - (i+1)*(i+1)*0.005f );
> pfSetVec3( verts[4*i+3], i* 0.02f* cos , i* 0.2f, -1.0f - i*i*0.005f );
> };
> pfGSetAttr( gset, PFGS_COORD3, PFGS_PER_VERTEX, verts, NULL );
>
> /* Change the flame texture */
>
> /* frame_no = ((int) (16.0f*time) ) % 32; */
> frame_no = ( frame_no + 1 ) % 32;
> frame = movie[frame_no].frame;
> pfGStateAttr( bb_gstate, PFSTATE_TEXTURE, frame );
>
> /* check keyboard events and draw channel stats */
>
> handleEvents();
> if (showStats) pfDrawChanStats( chan );
>
> }
>
> void changeFrameRate(int increment)
> {
>
> float vrate;
> int fields;
>
> fields = pfGetFieldRate();
> fields += increment;
>
> if ( fields < 0 ) fields = 1;
>
> pfFieldRate( fields );
>
> }
>
> void changePhase(void)
> {
>
> int currPhase;
>
> currPhase = pfGetPhase();
> switch (currPhase) {
>
> case PFPHASE_FREE_RUN : currPhase = PFPHASE_LIMIT;
> break;
>
> case PFPHASE_LIMIT : currPhase = PFPHASE_FLOAT;
> break;
>
> case PFPHASE_FLOAT : currPhase = PFPHASE_LOCK;
> break;
>
> case PFPHASE_LOCK : currPhase = PFPHASE_FREE_RUN;
> break;
>
> default : currPhase = PFPHASE_FREE_RUN;
> break;
>
> };
>
> pfPhase(currPhase);
>
> }
>
> void toggleLoadMgmt(void)
> {
>
> extern pfChannel *chan;
> float frac = 1.0, lo = 0.6, hi = 0.8;
> float scale = 0.1, max = 30.0f;
>
> handleStress = !handleStress;
> if (!handleStress) {
> scale = 0.0f;
> pfChanStress( chan, 1 );
> }
>
> pfChanStressFilter( chan, frac, lo, hi, scale, max );
> printf("Load managment is %s\n", handleStress ? "ON" : "OFF" );
>
> }
>
> void handleEvents(void)
> {
>
> extern pfuEventStream events;
> extern char *progName;
> extern int exitFlag;
> int i, j;
> int key, dev, val, numDevs;
> pfuEventStream *pEvents = &events;
>
> pfuGetEvents( &events );
> numDevs = pEvents -> numDevs;
>
> for ( j= 0; j < numDevs; ++j ) {
>
> dev = pEvents -> devQ[j];
> val = pEvents -> devVal[j];
>
> if ( pEvents -> devCount[dev] > 0 ) {
>
> switch ( dev ) {
>
> case PFUDEV_REDRAW: pEvents -> devCount[dev] = 0;
> break;
>
> case PFUDEV_WINQUIT: exitFlag = 1;
> pEvents -> devCount[dev] = 0;
> break;
>
> case PFUDEV_KEYBD: for ( i= 0; i < pEvents -> numKeys; ++i ) {
>
> key = pEvents -> keyQ[i];
> if ( pEvents -> keyCount[key] ) {
>
> switch ( key ) {
>
> case 27: exitFlag = 1;
> break;
>
> case 'f': changeFrameRate(1); break;
>
> case 'F': changeFrameRate(-1); break;
>
> case 'p': changePhase(); break;
>
> case 'h': printHelp( progName );
> break;
>
> case 'r': pfiStopXformer( xformer );
> pfiResetXformerPosition( xformer );
> break;
>
> case 'l': toggleLoadMgmt(); break;
>
> case 's': showStats = !showStats;
> break;
>
> default : break;
>
> };
> };
> };
>
> pEvents -> devCount[dev] = 0;
> break;
>
> default: break;
>
> }
> }
> };
>
> pEvents -> numKeys = 0;
> pEvents -> numDevs = 0;
>
> }
>
> void printHelp( char *progName )
> {
>
> printf("\n%s - playing with fire\n\n"
> "<f> key\t\t\t - decrease the requested frame rate\n"
> "<F> key\t\t\t - increase the requested frame rate\n"
> "<p> key\t\t\t - change phase\n"
> "<h> key\t\t\t - print help\n"
> "<r> key\t\t\t - reset transformer position\n"
> "<l> key\t\t\t - toggle load managment\n"
> "<s> key\t\t\t - toggle graphics stats\n"
> "ESCAPE key\t\t - exit the program\n\n",
> progName );
>
> }

=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


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:57:26 PDT

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