/* ttdddlib.h - definitions needed to interface to TTDDD library
 *            - written by Glenn M. Lewis - 7/19/91
 * $Id: ttdddlib.h,v 1.10 1991/10/10 19:30:24 glewis Exp glewis $
 */

#ifdef AMIGA

/* The following has been tested using SAS/C on an Amiga by Helge Rasmussen */
#include <string.h>
#include <stdlib.h>
#define  bcopy(s,d,n)	(void)memcpy((d),(s),(n))
#define  bzero(d,n)		(void)memset((d),0,(n))
#define  bcmp(b1,b2,n)	memcmp((b1),(b2),(n))
#define  index			strchr
#define  rindex			strrchr

#else

#include <strings.h>
#include <malloc.h>
char *calloc();

#endif

#ifdef SYSV
extern char *memcpy(), *memset();
#define bcopy(s,d,n)	(void)memcpy((d),(s),(n))
#define bzero(d,n)		(void)memset((d),0,(n))
#define bcmp(b1,b2,n)	memcmp((b1),(b2),(n))
#define index			strchr
#define rindex			strrchr
#endif

#ifndef UBYTE
#define UBYTE unsigned char
#endif
#ifndef BYTE
#define BYTE char
#endif

#ifndef UWORD
#define UWORD unsigned short
#endif
#ifndef WORD
#define WORD short
#endif

#ifndef ULONG
#define ULONG unsigned long
#endif
#ifndef LONG
#define LONG long
#endif

typedef struct { double val[3]; } XYZ_st;
typedef struct { UBYTE val[3];  } RGB_st;
typedef struct { XYZ_st came, rota; double foca; } OBSV;
typedef struct { double at, by; RGB_st to; } FADE;
typedef struct { RGB_st hori, zeni; } SKYC;
typedef char BRSH[81];
typedef struct { XYZ_st tran, scal, rota1, rota2, rota3; } MTRX;
typedef struct { XYZ_st xaxi, yaxi, zaxi; } AXIS;
typedef struct { char path[19]; XYZ_st tran, rota, scal; UWORD info; } STRY;
typedef struct {
	MTRX mtrx;
	char filename[81];
} EXTR;
typedef struct {
	UBYTE type;
	float indx;
} MTTR;
struct OBJECT {
	EXTR *extr;	/* Either EXTR or DESC */
	struct DESC *desc;
	struct OBJECT *parent;	/* whose child this OBJECT is */
	struct OBJECT *child;	/* children of this OBJECT - not for EXTR */
	struct OBJECT *next;	/* At this level in the hierarchy */
	void *user;		/* User-defined data for any purpose */
};
typedef struct OBJECT OBJECT;
typedef struct DESC {
	char name[19];
	WORD *shap;
	XYZ_st *posi;
	AXIS *axis;
	XYZ_st *size;
	XYZ_st *pnts;
	RGB_st *colr, *refl, *tran, *spc1;
	UWORD *edge, *face, pcount, ecount, fcount; 
	UBYTE *clst, *rlst, *tlst;
	double *tpar;
	UBYTE *surf;
	MTTR  *mttr;
	UBYTE *spec;
	UBYTE *prp0, *prp1;
	double *ints;
	RGB_st *int1;
	STRY *stry;
} DESC;

extern UBYTE defclst[3], defrlst[3], deftlst[3], defspc1[3];

#define STNC BRSH
#define TXTR BRSH
typedef struct {
	BRSH brsh[8];
	STNC stnc[8];
	TXTR txtr[8];
	OBSV *obsv;
	BYTE otrk[19];
	STRY *ostr;
	FADE *fade;
	SKYC *skyc;
	RGB_st *ambi;
	BYTE *glb0;
} INFO;

typedef struct {
	INFO *info;			/* The INFO description in the file */
	OBJECT *object;		/* The first object in the world */
	void *user;		/* User-defined data for any purpose */
	/* Some private variables needed to parse input file - don't touch! */
	int num_OBJ, num_DESC, num_TOBJ, cur_line;
	FILE *inp;
	OBJECT *curobj;
} WORLD;

typedef struct {
	double minx, maxx, miny, maxy, minz, maxz;
} MBB;

WORLD *read_World();	/* world = read_World(FILE *); ..figures out format */
WORLD *read_TTDDD();	/* world = read_TTDDD(FILE *);      ...0 on failure */
WORLD *read_TDDD();		/* world = read_TDDD(FILE *);       ...0 on failure */
int write_TTDDD();		/* write_TTDDD(world *, FILE *);    ...0 on failure */
int write_TDDD();		/* write_TDDD(world *, FILE *);     ...0 on failure */
int write_Rayshade();	/* write_Rayshade(world *, FILE *); ...0 on failure */
int write_PostScript();	/* write_PostScript(world *, FILE *, view); ..ditto */
int write_MIF();		/* write_MIF(world *, FILE *, view); ..0 on failure */
void calculate_MBB();	/* calculate_MBB(OBJECT *); */
OBJECT *linear_morph();	/* linear_morph(obj1, obj2, time); /* 0.0<=time<=1.0 */
OBJECT *create_object();/* p = create_object(); */
int count_objects();	/* Used by "morph()" */
int morph();			/* morph(world1, world2, num, name, morph_function); */
void free_desc();		/* free_desc(DESC *); */
void match_points();	/* match_points(numpoints, obj1, obj2); */
void sort_points();		/* sort_points(obj1); */
int cmpXYZ();			/* comparison for sort_points */
void move_extr();
void malloc_arrays();
void OUT_MEM();

/* Some stuff for PostScript and MIF output */
extern double XSIZE, YSIZE;	/* (in inches) Default: 8.5x11.0 */

#define VIEW_TOP	0	/* eye at (0,0,+inf) */
#define VIEW_FRONT	1	/* eye at (0,-inf,0) */
#define VIEW_ISO	2	/* eye at (+inf,-inf,+inf) */
#define VIEW_RIGHT	3	/* eye at (+inf,0,0) */
#define VIEW_ALL_FOUR 4	/* Place all on the same page */

