home *** CD-ROM | disk | FTP | other *** search
- /* spherize.c - Read in an Imagine object, map to unit sphere, spit it out.
- * - Written by Glenn M. Lewis - 8/6/92
- * - Reads from stdin, writes to stdout.
- */
-
- static char rcs_id[] = "$Id: spherize.c,v 1.6 1993/01/31 17:22:21 glewis Exp $";
-
- #include <stdio.h>
- #include <ctype.h>
- #include <math.h>
- #include "t3dlib.h"
- #include "noise.h"
- #ifdef __STDC__
- #include <stdlib.h>
- #include <strings.h>
- #include "spherize_protos.h"
- #endif
-
- double atof(), sqrt();
- #define NUMARGS 6
- double args[NUMARGS];
- double defargs[NUMARGS] = {
- 0.0, /* point_X */
- 0.0, /* point_Y */
- 0.0, /* point_Z */
- 1.0, /* radius_X */
- 1.0, /* radius_Y */
- 1.0 /* radius_Z */
- };
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int i;
- register OBJECT *o;
- WORLD *world;
-
- if (argc-1 > NUMARGS) {
- USAGE:
- fprintf(stderr, "Usage: %s point_X point_Y point_Z radius_X radius_Y radius_Z <in.iob >out.iob\n", argv[0]);
- exit(-1);
- }
- for (i=1; i<argc; i++) {
- if (argv[i][0]=='-' && argv[i][1]=='h') goto USAGE;
- args[i-1] = atof(argv[i]);
- }
- while (i-1<NUMARGS) { args[i-1] = defargs[i-1]; i++; }
-
- world = read_World(stdin);
- if (!world) {
- fprintf(stderr, "Could not load object from stdin.\n");
- exit(-1);
- }
-
- /* Now, iterate over all objects, blowing up verticies */
- for (o=world->object; o; o=o->next)
- process_DESC(o);
-
- /* Write the object back out. */
- write_TDDD(world, stdout);
- exit(0);
- }
-
- void process_DESC(object)
- OBJECT *object;
- {
- register OBJECT *obj;
- register DESC *desc = object->desc;
- register int i;
- double distance;
-
- /* Loop through list of verticies, and bump */
-
- if (desc->pcount) {
- for (i=desc->pcount; i--; ) {
- distance = (desc->pnts[i].x - args[0]) *
- (desc->pnts[i].x - args[0]) +
- (desc->pnts[i].y - args[1]) *
- (desc->pnts[i].y - args[1]) +
- (desc->pnts[i].z - args[2]) *
- (desc->pnts[i].z - args[2]);
- if (distance>0.0) distance = 1.0/sqrt(distance);
- else continue;
-
- /* Move point along vector by distance*scale value */
- if (args[3]>0.0)
- desc->pnts[i].x =
- (desc->pnts[i].x - args[0])*distance*args[3] + args[0];
- if (args[4]>0.0)
- desc->pnts[i].y =
- (desc->pnts[i].y - args[1])*distance*args[4] + args[1];
- if (args[5]>0.0)
- desc->pnts[i].z =
- (desc->pnts[i].z - args[2])*distance*args[5] + args[2];
- }
- }
-
- for (obj=object->child; obj; obj=obj->next)
- if (!obj->extr) process_DESC(obj);
- }
-