#ifndef _GRF4_H_
#define _GRF4_H_

#define HLS	1	/* Hidden Line Support */

#define GRF_COLOR	  0x010
#define GRF_LIGHTING	  0x020
#define GRF_HARDWARE_A	  0x100
#define GRF_HARDWARE_B	  0x200

#define GRF_IDRAW_PS	  0x10000
#define GRF_VIEW_CONTROL 0x1
#define GRF_X11	  0x2
#define GRF_WIRE_FRAME	  0x4

/* Button control */

#define BF_INACTIVE	0x1
#define BF_NOTBOXED	0x2
#define BF_ILLUMINATED	0x4
#define BF_SAMEROW	0x8

/* Button action codes */

#define BF_INFOCUS	0x01
#define BF_OUTFOCUS	0x02
#define BF_PRESSED	0x04
#define BF_RELEASED	0x08

#define RGBPACK(r,g,b)	(((unsigned)(b)<<16) + ((unsigned)(g)<<8) + \
			  (unsigned)(r))

#define GRF_WHITE	0xffffff
#define GRF_BLACK	0
#define GRF_RED		0xff
#define GRF_BLUE	0xff0000
#define GRF_GREEN	0xff00

#ifndef PI
#define PI        3.14159265358979320
#endif
#ifndef RTOD
#define RTOD	  (180.0/PI)
#endif
#ifndef DTOR
#define DTOR	  (PI/180.0)
#endif

/* XXX *if* we havn't defined these RCCL geometry types yet, then do so.
   There *really* out to be a better way to do this, but not yet. */

#ifndef _TRSF_H_

typedef struct {		/* Basic spatial 3-vector		*/
	float x, y, z;
} VECT, *VECT_PTR;

typedef struct {		/* 4X4 homogenous transform:		*/
	VECT n, o, a, p;	/*   the 4 column vectors of the matrix	*/
} TRSF, *TRSF_PTR;

TRSF *multTrsf();
TRSF *rpyToTrsf();
TRSF *multTrsfRpy();
TRSF *xyzToTrsf();
TRSF *multTrsfXyz();
TRSF *identTrsf();
TRSF *invertTrsf();

#endif 

typedef struct materialDef {
	unsigned long diffuse;
	unsigned long ambient;
	unsigned long emission;
	unsigned long specular;
	float shine;
	float alpha;
	  } MATERIAL_DEF;

typedef struct _cedge {
	struct _cedge *next;
	struct _cedge *prev;

	float x_b, y_b;		/* coordinates on bottom face */
	float x_t, y_t;		/* coordinates on top face */
	int hard;		/* is top-bottom connecting edge visible? */
	float *faceNrml;
	float *vrtxNrml1;
	float *vrtxNrml2;
	float *eNrml;		/* face normal turned into eye coordinates */

	float ex_b, ey_b, ez_b;
	float ex_t, ey_t, ez_t;
	float sx_b, sy_b;
	float sx_t, sy_t;
	int visible;
	  } CEDGE;

typedef struct {
	CEDGE *edges;		/* counter-clockwise list of edges */
	int size;		/* number of edges */
	float depth;		/* distance between top and bottom faces */
	int parallel;		/* top and bottom coordinates are the same */
	int topVisible;
	int bottomVisible;
} PRISM;

typedef struct {
	float *edges;		/* counter-clockwise list of edges */
	int size;
} POLYGON;

typedef struct {
	float *lines;		/* list of lines */
	int num;
} LINESET;

typedef struct {
	int npts;
	float radius;
	void* material;
	int nTheta;
	int nPhi;
	float (*pnts)[3];
  	float (*pntNormals)[3];
	float (*ctrNormals)[3];
} SPHERE;

typedef struct {
	int type;

#define GRF_PRISM	1
#define GRF_DISC	2
#define GRF_CONE	3
#define GRF_SPHERE	4
#define GRF_POLYGON	5
#define GRF_LINESET	6

	union {
	   PRISM *prism;
	   SPHERE *sphere;
	   POLYGON *polygon;
	   LINESET *lineSet;
	} ptr;

	void* material;

	TRSF trsf;
	float x1,y1,z1, x2,y2,z2; /* bounding box */

} Grf4Object;

Grf4Object *grf4GenCone();
Grf4Object *grf4GenPrism();
Grf4Object *grf4GenBox();
Grf4Object *grf4GenSphere();
Grf4Object *grf4GenDisc();
Grf4Object *grf4GenPolygon();
Grf4Object *grf4GenRegPolygon();
Grf4Object *grf4GenLineSet();

double glSetDepth();

TRSF *grf4GetTrans();
TRSF *grf4GetView();
void *grf4DefMaterial();
void *grf4DefMaterialD();
void *grf4DefLight();
long grf4Capacity();

#endif
