/* FILE : testpp5.c PROJECT : pxpl5 renderer test Author : Phil Atkin (C) Division Ltd 1993. */ #include #include #include #include #include #include #include "dpl5.h" #include "boot.h" #include "startup.h" #include "camera.h" char *progname; int860 link_A, link_B; extern int860 __acks_per_frame; extern int magicLeftVal, magicRightVal; /*{{{ reproducible random number support*/ /* as always, this is CASIO calculator output */ static float sfx_random_numbers[67] = { 0.990f, 0.196f, 0.030f, 0.452f, 0.165f, 0.663f, 0.737f, 0.774f, 0.996f, 0.269f, 0.676f, 0.786f, 0.123f, 0.474f, 0.755f, 0.919f, 0.873f, 0.603f, 0.628f, 0.045f, 0.089f, 0.509f, 0.413f, 0.416f, 0.304f, 0.011f, 0.083f, 0.110f, 0.177f, 0.602f, 0.810f, 0.181f, 0.723f, 0.394f, 0.035f, 0.873f, 0.678f, 0.331f, 0.407f, 0.499f, 0.132f, 0.210f, 0.081f, 0.550f, 0.344f, 0.894f, 0.469f, 0.307f, 0.641f, 0.936f, 0.779f, 0.833f, 0.373f, 0.915f, 0.972f, 0.887f, 0.019f, 0.613f, 0.540f, 0.898f, 0.755f, 0.689f, 0.076f, 0.173f, 0.870f, 0.825f, 0.364f }; static int sfx_random_ix = 0; static int sfx_random_base = 0; static float float_0to1 () { sfx_random_ix++; if (sfx_random_ix >= 67) sfx_random_ix=0; return sfx_random_numbers[sfx_random_ix]; } /*}}} */ /*{{{ void eyeStuff ( VIEW *view )*/ void eyeStuff ( VIEW *view, int left ) { float scale=1.0; PAZidMatrix(view->f); PAZidMatrix(view->b); if (left) scale *= -1.0f; PAZtranslatePair (view->f, view->b, scale*1.275, 0, 0 ); PAZrotatePair (view->f, view->b, 180, PAZ_Y ); PAZtranslatePair (view->f, view->b, 0, 0, -48 ); if (left == (-1)) view->shift_x=0.0; else if (left) view->shift_x=0.2147; else view->shift_x=-0.2147; /* view->shift_y = 0.0f; */ PAZwriteView ( view ); } /*}}} */ /*{{{ char *makeVizName ( char *name )*/ char vizStr [256]; char *makeVizName ( char *name ) { char *root; if ((root=getenv("VIZPATH")) == NULL) return(name); else { strcpy ( vizStr, root ); strcat ( vizStr, name ); return ( vizStr ); } } /*}}} */ /*{{{ char *makeTexName ( char *name )*/ char texStr [256]; char *makeTexName ( char *name ) { char *root; if ((root=getenv("TEXTURE")) == NULL) return(name); else { strcpy ( texStr, root ); strcat ( texStr, name ); return ( texStr ); } } /*}}} */ /*{{{ char *makedplName ( char *name )*/ char *makedplName ( char *dplstr, char *name ) { char *root; if ((root=getenv("DVIEWBIN")) == NULL) return(name); else { strcpy ( dplstr, root ); strcat ( dplstr, name ); return ( dplstr ); } } /*}}} */ /*{{{ static OBJECT *load_flames( char *fname )*/ static OBJECT *load_flames( char *fname ) { OBJECT *flame; FILE *fp=fopen(makeTexName(fname), "rb" ); int texels[32]; int total_texels=0, n_read; if (fp) { printf ("load flames\n" ); for (n_read = fread ( texels, 1, 32*4, fp ); n_read; n_read = fread ( texels, 1, 32*4, fp )) { PAZfxtexels ( texels, 32 ); total_texels+=32; } fclose(fp); } printf ( "%d texels read\n", total_texels ); flame=PAZcreateObject ( makeVizName("flame.v2z"), makeTexName ); return flame; } /*}}} */ /*{{{ int env2hex ()*/ int env2hex ( char *env_str, int default_v ) { char *s; int v; if (s = getenv(env_str)) { if (sscanf(s, "%x", &v) == 1) { return v; } } printf ("Defaulting on %s to 0x%x\n", env_str, default_v ); return default_v; } /*}}} */ /*{{{ int nain ( int argc, char *argv[])*/ int nain ( int argc, char *argv[]) { /*{{{ local variables*/ LIGHTSOURCE *bulb1, *bulb2; LIGHTSOURCE *fires[2]; INSTANCE *finst[2]; int fireage[2]; int polls=0; INSTANCE *inst, *tanks[16]; OBJECT *obj; OBJECT *flame=NULL, *tank_obj=NULL; MATERIAL *mtl=NULL; MATERIAL *temp_mtl=NULL; TEXTURE *tex=NULL; TEXTURE *tank_tex=NULL; SCENE *s; VIEW *eye, *rye; float scale_fac, t, fogr, fogg, fogb; char *objname; int frames=0, made, ramp, blowup =0, blowup0=0, blowup1=5; int i, j; /*}}} */ s = initialize_all ( 0, -1, &eye, &rye ); sscanf(argv[1], "%f", &scale_fac ); /*{{{ build flames geometry*/ flame=load_flames ( "allovem.svt" ); for (i=0; i<2; i++ ) { finst[i]=PAZcreateInstance(); finst[i]->obj=flame; PAZidMatrix ( finst[i]->f ); PAZtranslate ( finst[i]->f, 0, 0.5, 0, 1 ); PAZscale ( finst[i]->f, 80, 80, 80, 1 ); PAZtranslate ( finst[i]->f, 0, 0, -6000, 1 ); PAZinvert ( finst[i]->b, finst[i]->f ); finst[i]->billboard=1; finst[i]->enable=0; PAZwriteInstance ( finst[i] ); } /*}}} */ tank_tex=PAZcreateTexture ( makeTexName ( "tank.svt" ), 0, "tank" ); /*{{{ create the tanks*/ for (i=0; i<4; i++ ) { for (j=0; j<4; j++ ) { tanks[blowup] = PAZcreateInstance (); if (tank_obj==NULL) tank_obj=PAZcreateObject ( makeVizName ("tank_dea.b2z"), makeTexName ); tanks[blowup]->obj=tank_obj; PAZidMatrix ( tanks[blowup]->f ); PAZrotate ( tanks[blowup]->f, 36.0f * float_0to1(), 1, 1 ); PAZtranslate ( tanks[blowup]->f, (((float) i) - 1.5f)*530.0f, -40, (j-1)*530.0f, 1 ); PAZinvert ( tanks[blowup]->b, tanks[blowup]->f ); tanks[blowup]->enable=1; temp_mtl=PAZcreateMaterial(); temp_mtl->kd[0]=0.99f; temp_mtl->kd[1]=0.99f; temp_mtl->kd[2]=0.99f; temp_mtl->ks=0.0f; temp_mtl->tex=NULL; PAZwriteMaterial(temp_mtl); tanks[blowup]->f_material=temp_mtl->name; tanks[blowup]->f_texture =tank_tex->name; PAZwriteInstance ( tanks[blowup] ); blowup++; } } /*}}} */ /*{{{ create the floor*/ inst = PAZcreateInstance (); obj=PAZcreateObject ( makeVizName(argv[2]), makeTexName ); inst->obj=obj; PAZidMatrixPair ( inst->f, inst->b ); PAZscalePair ( inst->f, inst->b, scale_fac, scale_fac, scale_fac ); PAZtranslatePair ( inst->f, inst->b, 0, -40, 0 ); inst->enable=1; PAZwriteInstance ( inst ); /*}}} */ /*{{{ create the lights*/ /* create 2 light bulbs, 1 of which ambient */ bulb2=PAZcreateLight (); PAZinitLight ( bulb2, light_ambient, 0.2, 0.2, 0.3, -0.577, 0.577, -0.577 ); PAZwriteLight ( bulb2 ); bulb1=PAZcreateLight (); PAZinitLight ( bulb1, light_directional, 0.65, 0.65, 0.43, 1, 1, -1 ); PAZwriteLight ( bulb1 ); /* create the flame light sources */ for (i=0; i<2; i++ ) { fires[i]=PAZcreateLight (); PAZinitLight ( fires[i], light_null, 0.99, 0.55, 0.2, -10000, -10000, -10000 ); fires[i]->min_rad=0.0f; fires[i]->max_rad=0.01f; PAZwriteLight ( fires[i] ); } /*}}} */ fireage[0]=100; fireage[1]=100; PAZsetBackGND ( 0.2, 0.3, 0.6 ); blowup =0; blowup0=0; blowup1=5; PAZfog ( 1, 7000.0f, 12000.0f, 0.1f, 0.2f, 0.3f ); PAZrenderScene(); while (1) { frames++; { float ff=(float) frames; ff/=200.0f; fogr=0.2f+0.3f*(1.0+sin(1.14f*ff)); fogg=0.2f+0.3f*(1.0+sin(1.4f*ff)); fogb=0.2f+0.3f*(1.0+cos(1.734f*ff)); } camera_move_kbd ( eye, "tankview.spl", &inst->f[3][0], 1.0f, 0.0057f ); polls=0; while (PAZpollAck() == 0) { polls++; if ((polls & 0xffff) == 0xffff) printf ("Waited %d times\n", polls ); } if (polls==0) printf ("Polls 0 frame %d\n", frames ); PAZfog ( 1, 7000.0f, 12000.0f, fogr, fogg, fogb ); PAZrenderScene(); if (frames == 100) { /*{{{ fire off a new explosion*/ MATRIX m; frames=0; i=blowup; blowup^=1; PAZidMatrix (m); if (i==0) { m[3][0]=tanks[blowup0]->f[3][0]; m[3][1]=tanks[blowup0]->f[3][1]; m[3][2]=tanks[blowup0]->f[3][2]; blowup0++; blowup0&=15; } else { m[3][0]=tanks[blowup1]->f[3][0]; m[3][1]=tanks[blowup1]->f[3][1]; m[3][2]=tanks[blowup1]->f[3][2]; blowup1++; blowup1&=15; } PAZsfx ( 1, 0.0f, m ); PAZidMatrix ( finst[i]->f ); PAZtranslate ( finst[i]->f, 0, 0.5, 0, 1 ); PAZscale ( finst[i]->f, 80, 80, 80, 1 ); PAZtranslate ( finst[i]->f, m[3][0], m[3][1], m[3][2], 1 ); finst[i]->enable=1; PAZinvert ( finst[i]->b, finst[i]->f ); PAZwriteInstance ( finst[i] ); fires[i]->position[0]=m[3][0]; fires[i]->position[1]=180.0f + m[3][1]; fires[i]->position[2]=m[3][2]; fires[i]->positional=light_positional; fires[i]->colour[0]=0.99f; fires[i]->colour[1]=0.99f; fires[i]->colour[2]=0.99f; fires[i]->min_rad=480.0f; fires[i]->max_rad=1200.0f; PAZwriteLight ( fires[i] ); /*}}} */ } else { /*{{{ step current ones*/ for (i=0; i<2; i++ ) { if (finst[i]->enable) { fireage[i]++; if (fireage[i] > 170) { fireage[i]=0; finst[i]->enable=0; PAZwriteInstance ( finst[i] ); fires[i]->positional=light_null; fires[i]->min_rad=0.0f; fires[i]->max_rad=0.01f; PAZwriteLight ( fires[i] ); } else { PAZtranslate ( finst[i]->f, 0, -0.7, 0, 1 ); PAZwriteMatrix ( finst[i] ); fires[i]->position[1]-=0.7f; fires[i]->min_rad*=0.976; fires[i]->max_rad*=0.976; fires[i]->colour[1]*=0.984f; fires[i]->colour[2]*=0.976f; PAZwriteLight ( fires[i] ); } } } /*}}} */ } } } /*}}} */ /*{{{ int main ( int argc, char *argv[] )*/ int main ( int argc, char *argv[] ) { link_A= 1; link_B=-1; progname=argv[0]; if (argc < 4) { printf ("usage %s: \n", argv[0] ); exit(666); } else { char dplStr1 [256]; char dplStr2 [256]; magicLeftVal =env2hex("LEFTMAGIC", 0x3281); magicRightVal=env2hex("RIGHTMAGIC", 0x3281); size_from_magic ( magicLeftVal ); near_clip=12.8; far_clip =12000.0f; start_dView ( makedplName ( dplStr1, "pp5mon2.btl"), NULL, makedplName ( dplStr2, "pazpl5.mng"), env2hex("TRANSPUTER", 0x200), 1, -1 ); nain ( argc, argv ); } } /*}}} */