/* $Id: sphigs.h,v 1.5 1993/03/09 02:00:54 crb Exp $ */

#ifndef SPHIGS_H_INCLUDED_ALREADY
#define SPHIGS_H_INCLUDED_ALREADY

/* -------------------------------------------------------------------------
		       Public SPHIGS include file
   ------------------------------------------------------------------------- */

#define SPHIGS_USING_SRGP
#include "mat3.h"
#include "srgp_sphigs.h"
#include "srgppublic.h"

#ifdef SPHIGS_BOSS
#define DECLARE
#else
#define DECLARE extern
#endif


/* -----------------------------  Constants  ------------------------------ */

/* LIMITATION CONSTANTS */
#define DEFAULT_MAX_STRUCTURE_ID	15
#define DEFAULT_MAX_VIEW_INDEX		 5
#define DEFAULT_MAX_LIGHT_INDEX	 	 5
#define DEFAULT_MAX_NAME	 	32

#define MAX_HIERARCHY_LEVEL		14

DECLARE short MAX_STRUCTURE_ID
#ifdef SPHIGS_BOSS
   = DEFAULT_MAX_STRUCTURE_ID
#endif
   ;
DECLARE short MAX_VIEW_INDEX
#ifdef SPHIGS_BOSS
   = DEFAULT_MAX_VIEW_INDEX
#endif
   ;
DECLARE short MAX_LIGHT_INDEX
#ifdef SPHIGS_BOSS
   = DEFAULT_MAX_LIGHT_INDEX
#endif
   ;
DECLARE short MAX_NAME
#ifdef SPHIGS_BOSS
   = DEFAULT_MAX_NAME
#endif
   ;


/* RENDERING MODE CONSTANTS */
#define WIREFRAME_RAW		1
#define WIREFRAME		2  /* default */
#define FLAT			3
#define LIT_FLAT		4
#define GOURAUD			5

/* NETWORK DELETION TYPES */
#define UNCONDITIONAL	1
#define CONDITIONAL	2

/* MATRIX CONCATENATION TYPES */
typedef enum {REPLACE=1, PRECONCATENATE, POSTCONCATENATE} mode;
/* Backward compatibility */
#define ASSIGN REPLACE

/* PROJECTION TYPES */
typedef enum {PARALLEL, PERSPECTIVE} projectionType;
/* Backward compatibility */
#define ORTHOGRAPHIC PARALLEL

/* EDGE FLAGS */
typedef enum {EDGE_VISIBLE, EDGE_INVISIBLE} flag;

/* IMPLICIT REGENERATION MODES */
#define ALLOWED    1
#define SUPPRESSED 2

/* RENDERING ALGORITHMS */
#define RENDER_PAINTERS 0
#define RENDER_BSP	1

#include "elementType.h"


/* -------------------------------  Types  -------------------------------- */

/* 2D */
typedef struct { double x, y; }				NDC_point;
typedef struct { NDC_point bottom_left, top_right; }	NDC_rectangle;

/* 3D */
typedef MAT3vec			point;
typedef MAT3vec 		vector_3D;
typedef MAT3mat			matrix_4x4;

typedef short vertexIndex;

/* Backwards compatibility */
#define vertex_index vertexIndex

/* The book says locatorMeasure but definition clashes with srgp
   package, and hence we're calling it SPH__locatorMeasure */

typedef 
   struct {
      point position;
      int   viewIndex;
      buttonStatus   buttonChord[MAX_BUTTON_COUNT];
      int   buttonOfMostRecentTransition;
   } SPH__locatorMeasure;

/* Backwards compatibility */
#undef locator_measure
#define locator_measure SPH__locatorMeasure
#define view_index viewIndex

typedef int elementTypeCode;

typedef
   struct {
     int structureID;
     int elementIndex;
     elementTypeCode elementType;    /* symbolic constants in elementType.h */
     int pickID;
   } pickPathItem;

typedef pickPathItem pickPath[MAX_HIERARCHY_LEVEL];

typedef struct {
     int pickLevel;
     pickPath path;
   } pickInformation;

typedef char   name;      /* a number from 1 to 32 */

/* -------------------------------  Macros  ------------------------------- */

#define SPH_beep      		SRGP_beep

#define SPH_setModXform(A, B)   \
                  A, SPH_setModelingTransformation (temp_matrix, B)

/*
 * NOTE: in the original release of SPHIGS, the vector package used performed
 * multiplications using row instead of column vectors, the result being that in
 * order to use SPH_compose on transform matrices generated by SPHIGS, one had
 * to multiply them in reverse order to make composite transforms.
 * 	Oddly enough, this was deemed counterintuitive, and SPH_compose has
 * been replaced by SPH_composeMatrix, which multiplies transforms correctly (as
 * described in the text), and the vector package now treats matrix mults as
 * column vectors (also as found in the text).
 * 	SPH_oldComposeMatrix is provided here for the sake of backward
 * compatibility, and the following macro ensures that programs written with the
 * original (beta) version of SPHIGS will compile and work as intended.
 * 	
 */
#define SPH_compose		SPH_oldComposeMatrix

/* -----------------------------  Prototypes  ----------------------------- */

/* In sph_state.c: */
void		SPH_begin (int width, int height, int color_planes_desired, 
			   int shades_per_flexicolor);
void		SPH_end (void);
void		SPH_setMaxStructureID (int);
void		SPH_setMaxNameID (int);
void		SPH_setMaxViewIndex (int);
void		SPH_setMaxLightSourceIndex (int);

/* In sph_utility.c: */
double *	SPH_defPoint (double *pt, double x, double y, double z);
NDC_rectangle	SPH_defNDCrectangle 
                   (double lx, double by, double rx, double ty);

/* In sph_filter.c: */
/* unimplemented */ void SPH_addToHiliteFilter (int viewID, name); 
/* unimplemented */ void SPH_removeFromHiliteFilter (int viewID, name);
void 		SPH_addToInvisFilter (int viewID, name);
void		SPH_removeFromInvisFilter (int viewID, name);

/* In sph_element.c: */
void 		SPH_addToNameSet (name);
void 		SPH_removeFromNameSet (name);

void 		SPH_polyhedron (int vertexCount, int facetCount, 
				point *vertices, vertexIndex *facets);
void 		SPH_fillArea (int vertexCount, point *vertices);
void 		SPH_polyMarker(int vertexCount, point *vertices);
void 		SPH_polyLine (int vertexCount, point *vertices);
void 		SPH_text (point origin, char *str);

void 		SPH_setInteriorColor (int colorIndex);
void 		SPH_setLineStyle (lineStyle);
void 		SPH_setLineColor (int colorIndex);
void 		SPH_setLineWidthScaleFactor (double scaleFactor);
void 		SPH_setEdgeFlag (flag);
void 		SPH_setEdgeStyle (lineStyle);
void 		SPH_setEdgeColor (int colorIndex);
void 		SPH_setEdgeWidthScaleFactor (double scaleFactor);
void 		SPH_setMarkerStyle (markerStyle);
void 		SPH_setMarkerColor (int colorIndex);
void 		SPH_setMarkerSizeScaleFactor (double scaleFactor);
void 		SPH_setTextFont (int fontIndex);
void 		SPH_setTextColor (int colorIndex);

void		SPH_setLocalTransformation (matrix_4x4 matrix, mode);
void		SPH_setModelingTransformation (matrix_4x4, int method);
void		SPH_clearModelingTransformation (void);
void 		SPH_label (int);
void 		SPH_setPickIdentifier (int);
void 		SPH_executeStructure (int structureID);

/* In sph_post.c: */
void 		SPH_postRoot (int structureID, int viewIndex);
void 		SPH_unpostRoot (int structureID, int viewIndex);
void 		SPH_unpostAllRoots (int viewID);

/* In sph_edit.c: */
void 		SPH_openStructure (int structureID);
void 		SPH_closeStructure (void);

void		SPH_copyStructure (int structureID);

void 		SPH_setElementPointer (int index);
int		SPH_inquireElementPointer (void);
void 		SPH_offsetElementPointer (int delta);
void 		SPH_moveElementPointerToLabel (int id);

void 		SPH_deleteElement (void);
void 		SPH_deleteElementsInRange (int firstIndex, int secondIndex);
void 		SPH_deleteElementsBetweenLabels (int firstLabel, int secondLabel);

/* In sph_refresh.c: */
void 		SPH_setDoubleBufferingFlag (boolean);
void		SPH_setRenderingMode (int viewindex, int value);
void 		SPH_setImplicitRegenerationMode (int mode);
void 		SPH_regenerateScreen (void);

/* In sph_view.c: */
void 		SPH_evaluateViewOrientationMatrix 
                   (point  viewRefPoint,
		    vector_3D viewPlaneNormal, 
		    vector_3D viewUpVector,
		    matrix_4x4 voMatrix /*varparm*/ );

void		SPH_evaluateViewMappingMatrix
                   (double umin, double umax,
		    double vmin, double vmax,
		    projectionType,  /* ORTHOGRAPHIC or PERSPECTIVE */
		    point projectionReferencePoint,
		    double frontPlaneDistance, 
		    double backPlaneDistance,
		    double NPCvp_minX, double NPCvp_maxX, 
		    double NPCvp_minY, double NPCvp_maxY, 
		    double NPCvp_minZ, double NPCvp_maxZ, 
		    matrix_4x4 vmMatrix /*varparm*/ );

void 		SPH_setViewRepresentation 
                   (int viewIndex,
		    matrix_4x4 voMatrix,
		    matrix_4x4 vmMatrix,
		    double NPCviewport_minX, double NPCviewport_maxX, 
		    double NPCviewport_minY, double NPCviewport_maxY, 
		    double NPCviewport_minZ, double NPCviewport_maxZ); 
		    
void		SPH_enableView (int viewIndex);
void		SPH_disableView (int viewIndex);

void		SPH_setViewBackgroundColor (int viewIndex, int color);
void 	 	SPH_setViewRenderAlgorithm (int viewIndex, int algorithm);

void		SPH_setViewPointLightSource (int viewIndex, 
		    double u, double v, double n);
void		SPH_addPointLightSource (int viewIndex, int lightIndex,
		    point position, boolean cameraRelative, 
		    double intensity, double attenuation);
void		SPH_removePointLightSource (int viewIndex, int lightIndex);


/* In sph_input.c: */
#define     SPH_setInputMode 			SRGP_setInputMode
#define     SPH_waitEvent 			SRGP_waitEvent
#define     SPH_getKeyboard 			SRGP_getKeyboard
#define     SPH_sampleKeyboard 			SRGP_sampleKeyboard
#define     SPH_setKeyboardProcessingMode 	SRGP_setKeyboardProcessingMode
#define     SPH_setKeyboardEchoColor 		SRGP_setKeyboardEchoColor
#define     SPH_setKeyboardEchoFont 		SRGP_setKeyboardEchoFont
#define     SPH_setKeyboardMeasure 		SRGP_setKeyboardMeasure
#define     SPH_setLocatorEchoCursorShape 	SRGP_setLocatorEchoCursorShape
#define     SPH_setLocatorButtonMask 		SRGP_setLocatorButtonMask

void	    SPH_getLocator (SPH__locatorMeasure*);
void	    SPH_sampleLocator (SPH__locatorMeasure*);
void	    SPH_setLocatorMeasure (point position);
void	    SPH_setKeyboardEchoOrigin (point position);

void 	    SPH_pickCorrelate (point position, int viewIndex, 
			       pickInformation *pickInfo);

/* In sph_modxform.c: */
void	SPH_scale (double scaleX, double scaleY, double scaleZ, matrix_4x4 result);
void	SPH_rotateX (double angle, matrix_4x4 result);
void    SPH_rotateY (double angle, matrix_4x4 result);
void	SPH_rotateZ (double angle, matrix_4x4 result);
void 	SPH_translate (double deltaX, double deltaY, double deltaZ, matrix_4x4 result);
void	SPH_oldComposeMatrix (matrix_4x4 m1, matrix_4x4 m2, matrix_4x4 result);
void    SPH_composeMatrix (matrix_4x4 mat1, matrix_4x4 mat2, matrix_4x4 result);

/* In sph_attrib.c: */
#define 	SPH_loadFont			SRGP_loadFont

void SPH_loadCommonColor (int microcolorindex, char *name);


/* ----------------------------  End of File  ----------------------------- */

#endif /* SPHIGS_H_INCLUDED_ALREADY */

#undef DECLARE
