/* This file stores the header definitions for the file parsing program */
/* Created by : Brian Jacobson                      Date: 09/07/94      */
#include <shaders.h>

#define MAX_NAME_SIZE 80    /* Maximum size of object/surface names */
#define MAX_LINE_SIZE 1000  /* Maximum length of input file line    */
#define INTERPOLATE   2     /* Finds an interpolation command       */
#define Z             0.00000001

typedef struct dataT {
  double *data;
  struct dataT *next;
} dataList;

typedef struct {
  Surf_desc    *basicMat;
  Phong_desc   *phongMat;
  Wood_desc    *woodMat;
  Bozo_desc    *bozoMat;
  Marble_desc  *marbleMat;
  Granite_desc *graniteMat;
  Strauss_desc *straussMat;
  Bumpy_desc   *bumpyMat;
  Imagemap_desc *imageMat;
} allMat;

typedef struct intT {
  double         start,end;  /* The beginning and ending time of interp */
  unsigned char  dimension;  /* The number of dimensions of the data    */
  Transf_mat    *M;          /* The type of interpolation               */
  double        *cpoints;    /* Stores the control points               */
  unsigned int   numcpoints; /* The number of control points            */
  double        *def;        /* Stores the default data                 */
  unsigned int   numknots;   /* Stores the number of knots              */
  unsigned char  timed;      /* Indicates if it's timed or not.         */
  struct intT   *next;       /* Pointer to the next interpolation       */
} interpType;

typedef struct tranT {
  Transf_mat *trans;      /* Stores an amalgamated transformation  */
  interpType *movement;   /* Stores an interpolated transformation */
  unsigned char type;     /* The type of the interpolated movement */
  struct tranT *next;     /* The next interpolation                */
} transType;

typedef struct objT {
  char        *name;      /* Stores the name of the object         */
  double       start,end; /* Stores the starting and ending times  */
  Object      *object;    /* Points to the object w/ that name     */
  transType   *transList; /* Linked list of transformations        */
  struct objT *next;      /* Points to the next item in name list  */
} objList;

typedef struct surfT{
  char     *name;      /* Stores the name of the surface        */
  Surface  *surface;   /* Points to the surface w/ that name    */
  struct surfT *next;  /* Points to the next item in name list  */
} surfList;

typedef struct matT {
  char name[MAX_NAME_SIZE];   /* Store the name of the material  */
  unsigned char texture;      /* Stores the material texture     */
  void        *material;      /* Stores the surface description  */
  Shader      *matShader;     /* Stores the material's shader    */
  struct matT *next;          /* Pointer to the next material    */
} materialList;

typedef struct lightT {
  char          *name;        /* Stores the light name             */
  double         start, end;  /* Stores times of when to use light */
  unsigned char  type;        /* Stores the light type (SPOT,etc)  */
  Lightsource   *light;       /* Stores light description          */
  struct lightT *next;        /* Pointer to the next light         */
  interpType    *pos;         /* The light position interpolation  */
  interpType    *targ;        /* The dir/target interpolation      */
  interpType    *angle;       /* Flare angle interpolation         */
  interpType    *color;       /* Light color interpolation         */
} lightList;

typedef struct camT {
  char        *name;           /* Stores the light name             */
  double       start,end;      /* The beginning and ending time     */
  Camera      *camera;         /* Stores light description          */
  struct camT *next;           /* Pointer to the next light         */
  double       hither, yon;    /* The hither and yon clipping planes */
  unsigned char mode;          /* Indicate the rendering mode       */
  unsigned char pause;         /* Indicate if pause after render    */
  interpType  *eyep;           /* The interpolated eye point        */
  interpType  *lookp;          /* The interpolated look point       */
  interpType  *fov;            /* The interpolated field of view    */
  interpType  *up;             /* The interpolated up vector        */
} cameraList;

typedef struct flyarndT {
  char name[MAX_NAME_SIZE];   /* Stores the light name             */
  Vector lookp;               /* Stores look position              */
  double radius,fov;          /* Stores the radius of the flyby    */
  double steptheta;           /* Size of steps in degrees          */
  double stepphi;
  double delay;               /* Speed of the flyby                */
  double aspect;              /* Aspect ratio of the flyaround     */
  char   mode;
  double hither,yon;
  struct flyarndT *next;      /* Pointer to the next flyby         */
} flyarndList;

typedef char FilterFuncType(char *);  /* Prototype of file filter func */

/* Global variable */

extern char   *op;        /* Points to the start of the last word     */

/* Function prototypes */

char *LowerString(char *);

char FilterNone(char *);
char FilterShaders(char *);
char FilterMode(char *);
char FilterCommand(char *);
char FilterNewMaterial(char *);
char FilterNewSurface(char *);
char FilterPolygon(char *);
char FilterNumber(char *);
char FilterNumberI(char *);
char FilterNumber01(char *);
char FilterNumber01I(char *);
char FilterNewLight(char *);
char FilterNewCamera(char *);
char FilterNewCameraFlyAround(char *);

char GetNextWord(FILE *, FilterFuncType, char **, char *);

void AddSurfaceName(Surface *, char *);
Surface *FindNamedSurface(char *);
char *FindSurfaceName(Surface *);
void LoadSurface(FILE *);

objList *AddObjectName(Object *, char *);
objList *FindNamedObject(char *);
char *FindObjectName(Object *);
void PrintObject(Object *, char);
void LoadObject(FILE *);

materialList *CreateNamedMaterial(char *);
materialList *FindNamedMaterial(char *);
void SetCurrMaterial(char *);
void SetDefaultMaterial(Surf_desc *);
void PrintMaterialList();
void LoadMaterial(FILE *);

lightList *CreateNamedLight(char *);
lightList *FindNamedLight(char *);
void InterpolateLights _ANSI_ARGS_((lightList **l, double t));
void PrintLightList();
void LoadLight(FILE *);

cameraList *CreateNamedCamera(char *);
extern cameraList* NextTimedCamera _ANSI_ARGS_((cameraList **curr, double t));
cameraList *FindNamedCamera(char *);
void PrintCameraList();
void LoadCamera(FILE *);

flyarndList *CreateNamedCameraFlyAround(char *);
void LoadCameraFlyAround(FILE *);

void LoadPolygon(FILE *);

void ParseFile(char *, char);

void CreatePyramid(Object *, double, double, double, double, double, 
		       void *, Shader *, int);
void CreateCylPoly(Object *, double, double, double, int, FILE *, void *,
		       Shader *, int);
void CreateSpiral(Object *, double, double, double, double, double, double,
		      double, int, int, void *, Shader *, int);
void CreateKresge(Object *, double, double, double, double, int, void *,
		      Shader *, int);
void CreateStar(Object *, double, double, double, double, void *, 
		    Shader *, int);
void LoadPrism(Object *, FILE *, void *, Shader *, int);
void LoadBezierPatch(Object *, FILE *, void *, Shader *, int);
void LoadCylBezier(Object *, FILE *, void *, Shader *, int);


extern void LoadInterpolation _ANSI_ARGS_((FILE          *fp, 
					   unsigned char  dimension, 
					   interpType   **theInterp,
					   unsigned char  filt01));
extern void KillInterpolation _ANSI_ARGS_((interpType *kill));

extern dataList* AddToList _ANSI_ARGS_((dataList      **head, 
					dataList       *tail, 
					unsigned char   dim,
					double         *data));

extern void KillList _ANSI_ARGS_((dataList *list));

extern void Interpolate _ANSI_ARGS_((interpType **interp,
				     double       time,
				     double      *data));


extern unsigned char DefaultTexture _ANSI_ARGS_((char shad));
