home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_dos.lha / dos / sphsrc.v08 / sphigslocal.h < prev   
Encoding:
C/C++ Source or Header  |  1991-11-26  |  10.2 KB  |  408 lines

  1. #include "mat3defs.h"
  2. #include "sphigs.h"
  3. #include "geom.h"
  4. #include "sph_errtypes.h"
  5. #include "falloc.h"
  6. #include "assert.h"
  7.  
  8. #define REPORT_ERROR  SPH__error
  9. #include "macros.h"
  10.  
  11. #define X 0
  12. #define Y 1
  13. #define Z 2
  14.  
  15.  
  16. #ifdef SPHIGS_BOSS
  17. #define DECLARE
  18. boolean SPH__enabled=FALSE;
  19. boolean    SPH__structureCurrentlyOpen=FALSE;
  20. #else
  21. #define DECLARE extern
  22. extern boolean SPH__enabled;
  23. extern boolean SPH__structureCurrentlyOpen;
  24. #endif
  25.  
  26.  
  27. #define ASSUMED_NUM_OF_OBJECTS     200
  28.  
  29.  
  30.  
  31. /** DEVICE-DEPENDENT MEASUREMENTS
  32. Add one for your own screen if not already listed here.
  33. **/
  34. #ifdef sparc
  35. #define MARKER_SIZE_UNIT_IN_PIXELS  10  /* unit size geared towards Sparcstn */
  36. #define LINE_WIDTH_UNIT_IN_PIXELS    2
  37. #endif
  38. #ifdef THINK_C
  39. #define MARKER_SIZE_UNIT_IN_PIXELS   6  /* unit size geared towards MacII */
  40. #define LINE_WIDTH_UNIT_IN_PIXELS    1
  41. #endif
  42.  
  43. /* a default in case you don't provide on for your machine */
  44. #ifndef MARKER_SIZE_UNIT_IN_PIXELS
  45. #define MARKER_SIZE_UNIT_IN_PIXELS   6  /* I assume big pixels */
  46. #define LINE_WIDTH_UNIT_IN_PIXELS    1
  47. #endif
  48.  
  49.  
  50. typedef matrix  matrix_4by4;
  51.  
  52.  
  53. /** ALLOCATION MACRO USED BY MATRIX PACKAGE
  54. **/
  55. #define ALLOC(PTR, TYPE, NUM, ERR) {                              \
  56.    PTR = (TYPE *) calloc((unsigned)(NUM), (unsigned)sizeof(TYPE)); \
  57.    if (PTR == NULL)                                                 \
  58.       SPH__error (ERR_MALLOC);                         \
  59. }
  60. /* LAST ARGUMENT OF ALLOC() exists only for backward compatibility */
  61.  
  62.  
  63. /** SCREEN DETAILS 
  64. The width (or height) in pixels of one NPC unit.
  65. **/
  66. DECLARE int SPH_ndcSpaceSizeInPixels;
  67.  
  68.  
  69.  
  70. /** SUBSTRUCT_BITSTRING
  71. Each structure uses one of these to keep track of which structures
  72. are subordinates of it.
  73. **/
  74.  
  75. DECLARE int BYTES_PER_BITSTRING;
  76.  
  77. typedef unsigned char *substruct_bitstring;
  78.  
  79. void    ClearBitstring (substruct_bitstring*);
  80.  
  81. #define CopyBitstring(Bd,Bs)          (bcopy(Bs,Bd,BYTES_PER_BITSTRING))
  82. #define SetBit(B,N)              (B[N>>3] |= ((char)1)<<(N&7))
  83. #define ClearBit(B,N)              (B[N>>3] &= ( ! ( ((char)1)<<(N&7))))
  84. boolean BitstringIsClear (substruct_bitstring B);
  85. #define TestBit(B,N)              (B[N>>3] &  ((char)1)<<(N&7))
  86. #define BitstringsAreEqual(B1,B2)     ( ! (bcmp(B1,B2,BYTES_PER_BITSTRING)))
  87.  
  88. #define MergeBitstring(Bdest,Bsrc) \
  89.    {register int i; for (i=0; i<BYTES_PER_BITSTRING; i++) Bdest[i] |= Bsrc[i];}
  90. #define AndBitstrings(Bdest,B1,B2) \
  91.    {register int i; \
  92.     for (i=0; i<BYTES_PER_BITSTRING; i++) Bdest[i] = B1[i] & B2[i];}
  93.  
  94.  
  95.  
  96. /** INTELLIGENT RECTANGLE
  97. A rectangle which may be either empty (meaning non-existent) or nonempty.
  98. **/
  99. typedef struct {
  100.    boolean nonempty;
  101.    srgp__rectangle rect;
  102. } intelligent_rectangle;       
  103.  
  104.  
  105.  
  106.  
  107. /** ATTRIBUTE GROUP
  108. **/
  109. typedef unsigned char Bbyte;  /* to avoid collision with THINK C's "Byte" */
  110.  
  111. typedef struct {
  112.    /*.... line */
  113.    Bbyte line_color;
  114.    Bbyte line_width, line_style;
  115.  
  116.    /*.... marker */
  117.    Bbyte marker_color;
  118.    Bbyte marker_size, marker_style;
  119.  
  120.    /*.... polyhedra and fill areas */
  121.    Bbyte interior_color;
  122.    Bbyte edge_width, edge_style;
  123.    Bbyte edge_flag, edge_color;
  124.  
  125.    /*.... text */
  126.    Bbyte text_color, font;
  127. } attribute_group;
  128.  
  129. #include "sph_face.h"
  130.  
  131.  
  132.    
  133.  
  134. /** FACET
  135. **/
  136. typedef struct {
  137.    vertex_index *vertex_indices;   /* vertex_index defined in sphigs.h */
  138.    Bbyte        vertex_count;
  139.    MAT3hvec     normal;
  140.    boolean     do_draw;
  141. } facet;
  142.  
  143.  
  144. /** PDC POINT
  145. **/
  146. typedef int pdc_point[3];
  147.  
  148.  
  149. /** SPHIGS INFO STRUCT
  150. Each face-set given to the painter-alg must carry with it its attributes.
  151. **/
  152. typedef struct {
  153.    attribute_group attrs;
  154. } sphigs_info_struct;
  155.  
  156.  
  157.  
  158.  
  159. /** SPHIGS' COLOR TABLE
  160. **/
  161.  
  162. DECLARE int NUM_OF_FLEXICOLORS,
  163.         NUM_OF_SHADES_PER_FLEXICOLOR,
  164.         BASE_OF_SHADE_LUT_ENTRIES;
  165.  
  166. #define NUM_OF_APPL_SETTABLE_COLORS  (BASE_OF_SHADE_LUT_ENTRIES-2)
  167.  
  168. #define IS_A_FLEXICOLORINDEX(i)    \
  169.    ( (i > 1) && (i < (2 + NUM_OF_FLEXICOLORS)) )
  170.  
  171. #define IS_LEGAL_COLOR_INDEX(C)         \
  172.    ( (C>=0) && (C<BASE_OF_SHADE_LUT_ENTRIES) )
  173.  
  174. #define IS_CHANGEABLE_COLOR_INDEX(C)         \
  175.    ( (C>=2) && (C<BASE_OF_SHADE_LUT_ENTRIES) )
  176.  
  177.  
  178. /** POLYHEDRON
  179. **/
  180. typedef struct {
  181.    int vertex_count;
  182.    MAT3hvec *vertex_list;  /* POINTS TO ARRAY OF 4-element vectors */
  183.    int facet_count;
  184.    facet *facet_list;   /* POINTS TO ARRAY OF FACET STRUCTURES */
  185. } POLYHEDRON;
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. /** ELEMENT
  194. An element's type field determines which subfields of its two union fields 
  195. are active.
  196. **/
  197. typedef struct element {
  198.    short type;   /* enumerated values begin with ELTYP__ */
  199.    union {
  200.       int count;
  201.       char *textstring;  /* used only by text element */
  202.       int update_type;   /* used only by setModXform element */
  203.    } info;
  204.    union {
  205.       int value;
  206.       MAT3hvec point;
  207.       MAT3hvec *points;    /* ptr to dynamically allocated space */
  208.       POLYHEDRON *poly;    /* ptr to dynamically allocated space */
  209.       matrix_4by4 matrix;
  210.    } data;
  211.    struct element *next, *previous;
  212. } element;
  213.  
  214. /* UNDOCUMENTED and DANGEROUS... aren't the most useful things like that? */
  215. element *SPH__currentElementDirectAccess (void);
  216.  
  217.  
  218.  
  219. /** STORAGE OF A STRUCTURE
  220. **/
  221. typedef struct {
  222.    short refcount;
  223.    short element_count;
  224.    element *first_element, *last_element;
  225.    substruct_bitstring child_list;
  226. } structure;
  227.  
  228. DECLARE structure *SPH__structureTable;
  229.  
  230. void SPH__init_structure_table (void);
  231. void SPH__insertElement (element *baby);
  232. void SPH__add_polyhedron_element (POLYHEDRON *newpoly);
  233.  
  234. /* THE child_list IS ALWAYS UP-TO-DATE.
  235.  * THE descendent_list CAN BECOME OUT-OF-FASHION, AND MUST BE COMPLETELY 
  236.  * RECALCULATED WHENEVER THE FOLLOWING BOOLEAN IS TRUE.
  237.  */
  238. DECLARE boolean SPH__descendentListObsolete;
  239.  
  240.  
  241.  
  242.  
  243. /** REPRESENTATION OF A NETWORK
  244. The ID of the structure which is the root of this network is stored.
  245. **/
  246. typedef struct root_header {
  247.    int root_structID;
  248.    struct root_header *nextHigherOverlapRoot, *nextLowerOverlapRoot;
  249. } root_header;
  250.  
  251.  
  252.  
  253. /** VIEW TRANSFORMATION TABLE
  254. **/
  255. typedef struct view_spec {
  256.    NDC_rectangle viewport;
  257.    srgp__rectangle pdc_viewport;   /* computed from viewport */
  258.    matrix vo_matrix, vm_matrix, cammat;
  259.    double frontPlaneDistance, backPlaneDistance;
  260.    obj *objects, *objectTail;
  261.    FALLOCchunk *objectChunk;
  262.    int vertexCount, vertexArraySize;
  263.    MAT3hvec *uvnVertices, *npcVertices;
  264.    srgp__point *pdcVertices;
  265.    root_header *highestOverlapNetwork, *lowestOverlapNetwork;
  266.    char rendermode;
  267.    MAT3vec uvn_point_light_source;
  268.    substruct_bitstring descendent_list;
  269.    boolean obsolete_descendent_list;
  270.    boolean obsolete_object_list, obsolete_pdc_vertices;
  271.    boolean currently_disabled;
  272.    short background_color;  /* default is WHITE */
  273.    unsigned short curTraversalIndex;
  274. } view_spec;
  275.  
  276. DECLARE view_spec *SPH_viewTable;
  277.  
  278. DECLARE int SPH_implicit_regeneration_mode;
  279.  
  280. void SPH__init_view_table (void);
  281. void SPH__updateViewInfo (int viewIndex);
  282.  
  283. void SPH__translateWCtoPDC (int viewIndex, MAT3hvec inpt, MAT3hvec outpt);
  284. void SPH__translateMCtoPDC (matrix xformmat, MAT3hvec inpt, MAT3hvec outpt);
  285. void SPH__map_to_canon (view_spec *vs);
  286. void SPH__calc_intensity (view_spec *vs);
  287. void SPH__zsort (view_spec *vs);
  288.  
  289. void SPH__refresh_post (int viewIndex);
  290. void SPH__refresh_unpost (int viewIndex);
  291. void SPH__refresh_structure_close (int structID);
  292. void SPH__repaintScreen (void);
  293. void SPH__refresh_viewport_change (int viewIndex, srgp__rectangle old_viewport_rect);
  294.  
  295. void VIEWOPT__newExecuteStructure (int ID_of_open_struct, int structID);
  296. void VIEWOPT__afterChildLoss (int ID_of_open_struct);
  297. void VIEWOPT__afterNewPosting (view_spec *v, int struct_ID);
  298. void VIEWOPT__afterUnposting (view_spec *v, int struct_ID);
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305. /** GLOBALS USED DURING DISPLAY TRAVERSAL 
  306. **/
  307. DECLARE int currentViewIndex;
  308. DECLARE view_spec *currentViewSpec;
  309. DECLARE matrix
  310.    currentCompositeModxform, 
  311.    currentMCtoUVNxform, 
  312.    currentNormalMCtoUVNxform;
  313. DECLARE int currentRendermode;
  314.  
  315. DECLARE matrix currentTOTALxform;
  316. /* FROM MC TO PDC IN ONE SWELL FOOP! */
  317. /* ONLY POSSIBLE BECAUSE NO CLIPPING IS SUPPORTED YET. */
  318.  
  319.  
  320.  
  321.  
  322. /** ERRORS **/
  323. #ifdef THINK_C
  324. /* We hide this from gnu's compiler, which doesn't understand it. */
  325. void SPH__error (int errtype, ...);
  326. #endif
  327.  
  328.  
  329. void OBJECT__addFillArea
  330.    (view_spec *vs, MAT3hvec *points, int count,
  331.     matrix xform, attribute_group *attrs);
  332. void OBJECT__addPoly 
  333.    (view_spec *vp, POLYHEDRON *poly, matrix xform, attribute_group *attrs);
  334. void OBJECT__drawAll (view_spec *vs);
  335. void OBJECT__process (view_spec *vs);
  336. void OBJECT__init (view_spec *vs);
  337.  
  338. void SPH__freePolyhedron (POLYHEDRON *poly);
  339.    
  340.  
  341. /** VIEWING TRANSFORMATIONS **/
  342. void SPH__generate_pdc_vertices (view_spec *vs);
  343. void SPH__clip (view_spec *vs);
  344. void SPH__cull (view_spec *vs);
  345.  
  346. void SPH__traverse_network_for_display (view_spec *viewSpec, root_header *network);
  347. void SPH__traverse_struct_for_display (int structID, 
  348.                        attribute_group *inherited_attrs);
  349.  
  350. void SPH__draw_polyhedron (POLYHEDRON*, attribute_group*);
  351. void SPH__draw_lines (element*, attribute_group*);
  352. void SPH__draw_markers (element*, attribute_group*);
  353. void SPH__draw_text (point, char*, attribute_group*);
  354.  
  355. void SPH__initDefaultAttributeGroup (void);
  356.  
  357. void SPH__initColorTable (int num_of_planes);
  358.  
  359.  
  360.  
  361.  
  362.  
  363. DECLARE FALLOCchunk    *objectChunk;
  364. DECLARE obj        *objects;
  365. DECLARE int        vertexCount;
  366. DECLARE int        vertexArraySize;
  367. DECLARE MAT3hvec    *uvnVertices;
  368. DECLARE srgp__point    *pdcVertices;
  369.  
  370.  
  371.  
  372. /*!*/
  373. /* in ERROR.C */
  374.  
  375.  
  376. #define SPH_check_system_state    \
  377.    if (!SPH__enabled) SPH__error(ERR_NOT_ENABLED)
  378.  
  379. #define SPH_check_rectangle(LX,BY,RX,TY)        \
  380.    if(!((LX<=RX)&&(BY<=TY)))  SPH__error(ERR_BAD_RECT)
  381.  
  382. #define SPH_check_no_open_structure    \
  383.    if (SPH__structureCurrentlyOpen) SPH__error(ERR_STRUCTURE_IS_OPEN)
  384.  
  385. #define SPH_check_open_structure    \
  386.    if ( ! SPH__structureCurrentlyOpen) SPH__error(ERR_NO_STRUCTURE_IS_OPEN)
  387.  
  388. #define SPH_check_structure_id    \
  389.    if ((structID<0) || (structID>MAX_STRUCTURE_ID)) SPH__error(ERR_STRUCTURE_ID)
  390.  
  391. #define SPH_check_name    \
  392.    if ((name<1) || (name>MAX_NAME)) SPH__error(ERR_NAME)
  393.  
  394. #define SPH_check_view_index    \
  395.    if ((viewIndex<0) || (viewIndex>MAX_VIEW_INDEX)) SPH__error(ERR_VIEW_INDEX)
  396.  
  397. #define SPH_check_vertex_count(C)    \
  398.    if (C<2) SPH__error(ERR_VERTEX_COUNT)
  399.  
  400. #define SPH_check_edge_count(C)    \
  401.    if (C<2) SPH__error(ERR_EDGE_COUNT)
  402.  
  403. #define SPH_check_modxform_method    \
  404.    if ((method<ASSIGN) || (method>POSTCONCATENATE)) SPH__error(ERR_METHOD)
  405.  
  406. #define SPH_check_elindex_range         \
  407.    if ( ! (first_index<=second_index)) SPH__error(ERR_BAD_ELEMENT_INDEX_RANGE)
  408.