This is transobj.c in view mode; [Download] [Up]
/* Copyright (c) 1992 The Geometry Center; University of Minnesota 1300 South Second Street; Minneapolis, MN 55454, USA; This file is part of geomview/OOGL. geomview/OOGL is free software; you can redistribute it and/or modify it only under the terms given in the file COPYING, which you should have received along with this file. This and other related software may be obtained via anonymous ftp from geom.umn.edu; email: software@geom.umn.edu. */ /* Authors: Charlie Gunn, Pat Hanrahan, Stuart Levy, Tamara Munzner, Mark Phillips */ #include "transform.h" #include "transobj.h" #include "handleP.h" /* * Operations on TransObj objects. */ void TransPosition(TransObj *tobj, Transform T) /* Get transform into T */ { TmCopy(tobj->T, T); } void TransTransformTo(TransObj *tobj, Transform T) /* Set transform from T */ { TmCopy(T, tobj->T); } void TransDelete(TransObj *tobj) { if(tobj != NULL && RefDecr((Ref *)tobj) <= 0) OOGLFree(tobj); } TransObj * TransCreate( Transform T ) { TransObj *tobj = OOGLNewE(TransObj, "TransObj"); RefInit((Ref*)tobj, TRANSMAGIC); if(T != TMNULL) TmCopy(T, tobj->T); return tobj; } /* * Communications */ HandleOps TransOps = { "trans", TransStreamIn, TransStreamOut, TransDelete, NULL, NULL }; void TransUpdate( Handle **hp, Ref *ignored, Transform Tfixme ) { register Handle *h = *hp; if(h != NULL && h->object != NULL) TmCopy( ((TransObj *)(h->object))->T, Tfixme ); } TransStreamIn( Pool *p, Handle **hp, Transform T ) { Handle *h = NULL; Handle *hname = NULL; register TransObj *tobj = NULL; char *w, *raww; int c; int more = 0; int brack = 0; FILE *inf; if(p == NULL || (inf = PoolInputFile(p)) == NULL) return 0; do { more = 0; switch(c = fnextc(inf, 0)) { case '{': brack++; fgetc(inf); break; case '}': if(brack--) fgetc(inf); break; case 't': if(fexpectstr(inf, "transform")) return 0; more = 1; break; case 'd': if(fexpectstr(inf, "define")) return 0; hname = HandleAssign(ftoken(inf, 0), &TransOps, NULL); break; case '<': case ':': case '@': fgetc(inf); w = fdelimtok("{}()", inf, 0); if(c == '<' && HandleByName(w, &TransOps) == NULL) { w = findfile(PoolName(p), raww = w); if(w == NULL) { OOGLSyntax(inf, "Reading transform from \"%s\": can't find file \"%s\"", PoolName(p), raww); } } h = HandleReferringTo(c, w, &TransOps, NULL); if(h) tobj = (TransObj *)h->object; break; default: /* * Anything else should be a 4x4 matrix */ if(tobj == NULL) tobj = TransCreate( TMNULL ); if(fgettransform(inf, 1, &tobj->T[0][0], 0) <= 0) return 0; } } while(brack || more); if(hname != NULL) { if(tobj) HandleSetObject(hname, (Ref *)tobj); h = hname; } if(h == NULL && tobj != NULL && p->ops == &TransOps) h = HandleAssign(PoolName(p), &TransOps, (Ref *)tobj); if(h != NULL && tobj != NULL) HandleSetObject(h, (Ref *)tobj); if(tobj != NULL && T != TMNULL) TmCopy(tobj->T, T); if(h != NULL && hp != NULL) { if(*hp != h) { if(*hp != NULL) HandlePDelete(hp); *hp = h; } } else { TransDelete(tobj); /* Maintain ref count */ } return (h != NULL || tobj != NULL); } int TransStreamOut( Pool *p, Handle *h, Transform T ) { int putdata; FILE *outf; if((outf = PoolOutputFile(p)) == NULL) return 0; fprintf(outf, "transform {\n"); putdata = PoolStreamOutHandle( p, h, T != TMNULL ); if(putdata) fputtransform(outf, 1, &T[0][0], 0); fputs("}\n", outf); return !ferror(outf); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.