/* File: pfexLoadModel2.c */ #include #include #include #include #include #include #include #include #include #include #include void pfexInitConverter(char *fname_model); pfScene *pfexInitScene(char *fname_model1, char *fname_model2); void pfexUpdate(void); void usage(void) { fprintf(stderr, "usage: pfexLoadModel fname_model1 fname_model2\n"); fprintf(stderr, " pfexLoadModel [-usage|-help]\n"); exit(-1); } int main(int argc, char **argv) { pfScene *scene; if (argc != 3 || !strcmp(argv[1], "-usage") || !strcmp(argv[1], "-help")) usage(); pfInit(); pfexInitConverter(argv[1]); pfexInitConverter(argv[2]); pfCAVEConfig(&argc, argv, NULL); pfConfig(); pfCAVEInitChannels(); scene = pfexInitScene(argv[1], argv[2]); pfChanScene(pfCAVEMasterChan(), scene); while (!CAVEgetbutton(CAVE_ESCKEY)) { pfSync(); pfexUpdate(); pfCAVEPreFrame(); pfFrame(); pfCAVEPostFrame(); } pfCAVEHalt(); pfExit(); } void pfexInitConverter(char *fname_model) { if (!pfdInitConverter(fname_model)) { fprintf(stderr, "Could not init converter for %s\n", fname_model); pfExit(); exit(-1); } } static pfDCS *g_DCS; void pfexUpdate(void) { static int first = 1; static float t0; float t, ang, angdeg; t = pfGetTime(); if (first) { t0 = t; first = 0; } ang = M_PI * (t-t0); angdeg = 180.0 * (t-t0); pfDCSRot(g_DCS, angdeg-90.0, 0.0, 0.0); pfDCSTrans(g_DCS, 3.0*cos(ang), 3.0*sin(ang), 5.0); } pfScene *pfexInitScene(char *fname_model1, char *fname_model2) { pfScene *scene; pfNode *node; pfGeoState *gstate; pfLightSource *lightsource; pfSCS *SCS; pfMatrix M; scene = pfNewScene(); gstate = pfNewGState(pfGetSharedArena()); pfGStateMode(gstate, PFSTATE_ENLIGHTING, PF_ON); pfGStateMode(gstate, PFSTATE_CULLFACE, PFCF_OFF); pfSceneGState(scene, gstate); lightsource = pfNewLSource(); pfAddChild(scene, lightsource); if (node = pfdLoadFile(fname_model1)) { pfMakeTransMat(M, 0.0, 0.0, 5.0); SCS = pfNewSCS(M); pfAddChild(scene, SCS); pfAddChild(SCS, node); } else { fprintf(stderr, "Could not open %s\n", fname_model1); pfExit(); exit(-1); } if (node = pfdLoadFile(fname_model2)) { g_DCS = pfNewDCS(); pfAddChild(scene, g_DCS); pfAddChild(g_DCS, node); } else { fprintf(stderr, "Could not open %s\n", fname_model2); pfExit(); exit(-1); } return scene; }