/*
** peek v1.0 4/16/95
** Copyright (c) Gordon Kindlmann 1995
*/

/*
** peek.h
*/

#include "defines.h"

/* 
** struct definitions for part_t and image_t
*/
typedef struct part_t {
  int 
    d,        /* dimension of this part */
    ID,       /* ID tag of this part (numbering local to this piece) */
    done,     /* for use with traversals of object web, to
	       * indicate that this part has already been
	       * processed */
    spare;    /* spare variable:
		 on surfaces it indicates closed vs open,
	         on vertices that have undergone intersection, it indicates
		 which side of the slicing space the vertex lies on */
  
  float						
    coord_hold[MAXSPACED],
    /* world coords that were originally read in from object file- these do
       not get altered in object movements but are used in conjuction with
       xform matrix to create up-to-date position information, held in
       coord[] */

    coord[MAXSPACED],	 
    /* current world coords for this part.  Does not yet have meaning if
       d > 0, though this would be a good place to store the center of this 
       part if we are constructing dual of a polytope */

    coord_view[THREE],   /* coordinates in view space */
    coord_screen[TWO],   /* coordinates in screen space */
    norm[MAXSPACED],    /* normal, used for lighting in 3-space */
    color[COLORS];      /* RGB values for this part, and color[COLORS-1] is 
			   its opacity */
  struct image_t
    *thought;	        /* pointer to image of the first part in the
			 * series of parts which comprise this part */
  struct part_t
    *result;		/* pointer to part which is result of some 
			 * operation on this part, like an intersection. */
} Part;

typedef struct image_t {
  struct image_t
    *next;		/* next image in this series of parts */
  struct part_t
    *sense;		/* pointer to the part that this is the image of */
} Image;

typedef struct matx_t {
  float 
    m[MAXSPACED+1][MAXSPACED+1];
} Matx;

typedef struct piece_t {
  int 
    ID_count,            /* number of parts in this piece that have been
			    cataloged */
    cat_size,            /* size of catalog in hundreds */
    piece_d,             /* top dimension of this piece- irrespective of
			    the dimension of the space it lives in. So,
			    piece_d for any line is 1, piece_d for a square
			    is 2, piece_d for a cube is 3, etc. */
    space_d,             /* "Dimension of space that object lies in"  
			    Actually-
			    upper bound on coordinate at and above which you 
			    can count on this part's vertices having zero
			    values.  Not necessarily least upper bound */
    *offset;             /* offset[d] is location in catalog of first part
			    of dimension d */
  
  Matx *xform;           /* matrix of transformation for this object; 
			    to convert from coord_hold to coord arrays
			    of world coordinates.
			    first piece in piece list has only copy.*/
  float
    color[COLORS];       /* for overall piece color, since surfaces don't
			    have color */

  struct image_t
    *thought;             /* pointer to first surface Image in piece */

  struct part_t
    **catalog;            /* catalog of Part pointers- catalog is an 
		 	       array of pointers to Parts */
  struct piece_t
    *result,              /* pointer to result of some operation on this
			     piece */
    *next;                /* pointer to next piece in object */
} Piece;

typedef struct enviro_t {
  float
    eye[THREE],           /* eye position in world space,
			     --> SPHERICAL COORDINATES <-- */
    distance,             /* distance of viewplane from eye
			     (controls amount of perspective) */
    light[THREE],         /* unitary light direction vector */
    amb,                  /* ambient light */
    scale,                /* scalar multiplier for size in screen space */
    frontwidth,           /* width of edges of visible faces, 
			     if 0 then don't draw them */
    backwidth;            /* width of edges of invisible faces
			     if 0 then don't draw them */
} Enviro;

/*
** declaration of globals, definition is in main.
*/
extern char err[];
extern int debug;

/*
** prototypes, sorted by source file
*/

/* xform.c */
int vect_matx(float*, Matx*, float*, int);
int update_coords(Piece*);
int xform(Piece*, Matx*);
int WtoS_sysI(Piece*, Enviro*);

/* util.c */
void dispose_piece(Piece*);
void dispose_object(Piece*);
int fix_cat(Piece*);
void reset(Part*);
void reset_object(Piece*);
char *describe(int);

/* read.c */
int read_vert(FILE*, Piece*, int);
int read_part(FILE*, Piece*, int, int);
int read_partseg(FILE*, Piece*, int, int);
int read_piece(FILE*, Piece**, int);
int read_object(FILE*, Piece**);

/* psdraw.c */
int psdraw_surface(FILE*, Part*, Enviro*, int, char*);
int psslice_4d(char*, Piece*, Matx*, Matx*, Enviro*, int);

/* orient.c */
int center(Part*);
int other_edge(Part*, Part*, Part*, Part**, Part**);
int unedge_face(Part*);
int reverse_face(Part*);
int orient_face(Part*, float*);
int orient_object(Piece*);

/* intx.c */
int slice_vert(Piece*, Part*, Piece*, float, float);
int slice_edge(Piece*, Part*, Piece*, float, float);
int novel(Part*, Image*);
int slice_part(Piece*, Part*, Piece*, float, float);
int slice_piece(Piece*, Piece*, float, float);
int slice_object(Piece*, Piece**, float, float);
int intx_object(Piece*, Piece**, float, int);

/* hcubeslice.c */
int hcubeslice();

/* fileio.c */
FILE *get_source();
FILE *get_output(char*);
int skip(FILE*);
int get_int(FILE*, int*);
int get_float(FILE*, float*);
int next_sect(FILE*);

/* enum.c */
int enumerate(Piece*, Part*, int, FILE*);
int enum_object(FILE*, Piece*);

/* util.c */
int image_alloc(Image**);
int part_alloc(Part**);
int part_alloc(Part**);
int build_part(Part**, int, int, int, float*, float*);
int build_piece(Piece**, int, int, float*, float**);
int tag(Piece*, Part *);

