static errcode GetObject(FILE * dfile, SceneHandle scene) { char objtype[80]; fscanf(dfile, "%s", objtype); if (!stringcmp(objtype, "END_SCENE")) { return PARSEEOF; /* end parsing */ } if (!stringcmp(objtype, "TEXDEF")) { return GetTexDef(dfile); } if (!stringcmp(objtype, "TEXALIAS")) { return GetTexAlias(dfile); } if (!stringcmp(objtype, "BACKGROUND")) { return GetBackGnd(dfile); } if (!stringcmp(objtype, "CYLINDER")) { return GetCylinder(dfile); } if (!stringcmp(objtype, "FCYLINDER")) { return GetFCylinder(dfile); } if (!stringcmp(objtype, "POLYCYLINDER")) { return GetPolyCylinder(dfile); } if (!stringcmp(objtype, "SPHERE")) { return GetSphere(dfile); } if (!stringcmp(objtype, "PLANE")) { return GetPlane(dfile); } if (!stringcmp(objtype, "RING")) { return GetRing(dfile); } if (!stringcmp(objtype, "BOX")) { return GetBox(dfile); } if (!stringcmp(objtype, "SCALARVOL")) { return GetVol(dfile); } if (!stringcmp(objtype, "TRI")) { return GetTri(dfile); } if (!stringcmp(objtype, "STRI")) { return GetSTri(dfile); } if (!stringcmp(objtype, "LIGHT")) { return GetLight(dfile); } if (!stringcmp(objtype, "SCAPE")) { return GetLandScape(dfile); } if (!stringcmp(objtype, "TPOLYFILE")) { return GetTPolyFile(dfile); } fprintf(stderr, "Found bad token: %s expected an object type\n", objtype); return PARSEBADSYNTAX; }
bool BEZIER::Collide(VERTEX origin, VERTEX direction, VERTEX &outtri) { int i; VERTEX curtri[3]; int retval = 0; float t, u, v; int x, y; for (i = 0; i < NumTris(COLLISION_DIVS) && !retval; i++) { GetTri(COLLISION_DIVS, i, curtri); retval = INTERSECT_FUNCTION(origin.v3(), direction.v3(), curtri[0].v3(), curtri[1].v3(), curtri[2].v3(), &t, &u, &v); if (retval) { if (i % 2 == 0) { u = 1.0 - u; v = 1.0 - v; } u = 1.0 - u; v = 1.0 - v; x = (i/2) % COLLISION_DIVS; y = (i/2) / COLLISION_DIVS; u += (float) x; v += (float) y; u = u / (float) COLLISION_DIVS; v = v / (float) COLLISION_DIVS; //u = 1.0 - u; //v = 1.0 - v; //cout << u << "," << v << endl; outtri = SurfCoord(u, v); return true; } } outtri = origin; return false; }
static errcode GetObject(parsehandle * ph, SceneHandle scene) { char objtype[256]; if (fscanf(ph->ifp, "%s", objtype) == EOF) { return PARSEEOF; } if (!stringcmp(objtype, "TRI")) { return GetTri(ph, scene); } if (!stringcmp(objtype, "STRI")) { return GetSTri(ph, scene); } if (!stringcmp(objtype, "VCSTRI")) { return GetVCSTri(ph, scene); } if (!stringcmp(objtype, "SPHERE")) { return GetSphere(ph, scene); } if (!stringcmp(objtype, "FCYLINDER")) { return GetFCylinder(ph, scene); } if (!stringcmp(objtype, "RING")) { return GetRing(ph, scene); } if (!stringcmp(objtype, "POLYCYLINDER")) { return GetPolyCylinder(ph, scene); } if (!stringcmp(objtype, "CYLINDER")) { return GetCylinder(ph, scene); } if (!stringcmp(objtype, "PLANE")) { return GetPlane(ph, scene); } if (!stringcmp(objtype, "BOX")) { return GetBox(ph, scene); } if (!stringcmp(objtype, "SCALARVOL")) { return GetVol(ph, scene); } if (!stringcmp(objtype, "TEXDEF")) { return GetTexDef(ph, scene); } if (!stringcmp(objtype, "TEXALIAS")) { return GetTexAlias(ph); } if (!stringcmp(objtype, "LIGHT")) { return GetLight(ph, scene); } if (!stringcmp(objtype, "DIRECTIONAL_LIGHT")) { return GetDirLight(ph, scene); } if (!stringcmp(objtype, "SPOTLIGHT")) { return GetSpotLight(ph, scene); } if (!stringcmp(objtype, "SCAPE")) { return GetLandScape(ph, scene); } if (!stringcmp(objtype, "CAMERA")) { return GetCamera(ph, scene); } if (!stringcmp(objtype, "TPOLYFILE")) { return GetTPolyFile(ph, scene); } if (!stringcmp(objtype, "MGFFILE")) { #ifdef USELIBMGF return GetMGFFile(ph, scene); #else printf("MGF File Parsing is not available in this build.\n"); return PARSEBADSYNTAX; #endif } if (!stringcmp(objtype, "#")) { int c; while (1) { c=fgetc(ph->ifp); if (c == EOF || c == '\n') /* eat comment text */ return PARSENOERR; } } if (!stringcmp(objtype, "BACKGROUND")) { return GetBackGnd(ph, scene); } if (!stringcmp(objtype, "FOG")) { return GetFog(ph, scene); } if (!stringcmp(objtype, "INCLUDE")) { char includefile[FILENAME_MAX]; fscanf(ph->ifp, "%s", includefile); return ReadIncludeFile(ph, includefile, scene); } if (!stringcmp(objtype, "START_CLIPGROUP")) { return GetClipGroup(ph, scene); } if (!stringcmp(objtype, "END_CLIPGROUP")) { return GetClipGroupEnd(ph, scene); } if (!stringcmp(objtype, "END_SCENE")) { return PARSEEOF; /* end parsing */ } PrintSyntaxError(ph, "an object or other declaration", objtype); return PARSEBADSYNTAX; }