home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <math.h>
- #include "stdio.h"
- #include "gl.h"
- #include "device.h"
-
- #include "fastobj.h"
-
-
- fastobj *readfastobj(name)
- char *name;
- {
- FILE *inf;
- fastobj *obj;
- int i, j;
- int nlongs;
- int magic;
- int *ip;
- char filename[512];
-
- inf = fopen(name,"r");
- if(!inf) {
- sprintf(filename,"%s",name);
- inf = fopen(filename,"r");
- if(!inf) {
- fprintf(stderr,"readfast: can't open input file %s\n",name);
- exit(1);
- }
- }
- fread(&magic,sizeof(int),1,inf);
- if(magic != FASTMAGIC) {
- fprintf(stderr,"readfast: bad magic in object file\n");
- fclose(inf);
- exit(1);
- }
- obj = (fastobj *)malloc(sizeof(fastobj));
- fread(&obj->npoints,sizeof(int),1,inf);
- fread(&obj->colors,sizeof(int),1,inf);
-
- /*
- * Insure that the data is quad-word aligned and begins on a page
- * boundary. This shields us from the performance loss which occurs
- * whenever we try to fetch data which straddles a page boundary (the OS
- * has to map in the next virtual page and re-start the DMA transfer).
- */
- nlongs = 8 * obj->npoints;
- /* Not important here...
- obj->data = (int *) malloc(nlongs*sizeof(int) + 4096);
- obj->data = (int *) (((int)(obj->data)) + 0xfff);
- obj->data = (int *) (((int)(obj->data)) & 0xfffff000);
- */
- obj->data = (int *) malloc(nlongs*sizeof(int));
-
- for (i = 0, ip = obj->data; i < nlongs/4; i++, ip += 4)
- fread(ip, 3 * sizeof(int), 1, inf);
- fclose(inf);
- return obj;
- }
-
-
- #if FALSE
- drawfastobj(obj)
- fastobj *obj;
- {
- register int *p,*end;
- register int npolys;
-
- p = obj->data;
- end = p + 8 * obj->npoints;
-
- if(obj->colors) {
- npolys = obj->npoints/4;
- p = obj->data;
- while(npolys--) {
- PolyOrLine();
- c3i(p);
- v3f(p+4);
- c3i(p+8);
- v3f(p+12);
- c3i(p+16);
- v3f(p+20);
- c3i(p+24);
- v3f(p+28);
- EndPolyOrLine();
- p += 32;
- }
- } else {
- while ( p < end) {
- PolyOrLine();
- n3f(p);
- v3f(p+4);
- n3f(p+8);
- v3f(p+12);
- n3f(p+16);
- v3f(p+20);
- n3f(p+24);
- v3f(p+28);
- EndPolyOrLine();
- p += 32;
- }
- }
- }
-
-
- /*
- * objmaxpoint
- *
- * find the vertex farthest from the origin,
- * so we can set the near and far clipping planes tightly.
- */
-
- #define MAXVERT(v) if ( (len = sqrt( (*(v)) * (*(v)) + \
- (*(v+1)) * (*(v+1)) + \
- (*(v+2)) * (*(v+2)) )) > max) \
- max = len;
-
- float
- objmaxpoint(obj)
- fastobj *obj;
- {
- register float *p, *end;
- register int npolys;
- register float len;
- register float max = 0.0;
-
- p = (float *) (obj->data);
-
- if (obj->colors) {
- npolys = obj->npoints/4;
- while(npolys--) {
- MAXVERT(p+4);
- MAXVERT(p+12);
- MAXVERT(p+20);
- MAXVERT(p+28);
- p += 32;
- }
- } else {
- end = p + 8 * obj->npoints;
- while ( p < end) {
- MAXVERT(p+4);
- MAXVERT(p+12);
- MAXVERT(p+20);
- MAXVERT(p+28);
- p += 32;
- }
- }
-
- return max;
- }
-
- splitobj(obj, objs, start, end)
- fastobj *obj;
- fastobj objs[];
- int start;
- int end;
- {
- int *p, quad_per_piece, quad, factor, curp;
-
- factor = end - start;
- if (obj->npoints /4 < factor) {
- perror("not enough 4vtx polygons to split into %d pieces\n", obj->npoints);
- exit(-1);
- }
-
- p = obj->data;
- quad = obj->npoints/4;
- quad_per_piece = quad / factor;
-
- if (obj->colors) {
- perror("can't do yet\n");
- }
- else {
- objs[start].npoints = ((quad % factor) + quad_per_piece) * 4;
- while (--factor) {
- curp = (start + factor);
- objs[curp].npoints = quad_per_piece * 4;
- objs[curp].data = p;
- p += quad_per_piece * 32;
- }
- objs[start].data = p;
- obj->swirl = &(objs[start]);
- }
- }
- #endif
-