home *** CD-ROM | disk | FTP | other *** search
/ Dream 41 / Amiga_Dream_41.iso / Amiga / Pro / 3d / ICoons1_0.lzh / icoons / source / general.h < prev    next >
C/C++ Source or Header  |  1992-10-25  |  8KB  |  273 lines

  1. /* :ts=8 */
  2.  
  3. #ifndef GENERAL_H
  4. #define GENERAL_H
  5.  
  6. /************************************************************************/
  7. /*                                    */
  8. /*             General includefile for ICoons.            */
  9. /*                                    */
  10. /* This file defines most of the types and constants used in the program*/
  11. /*                                    */
  12. /************************************************************************/
  13.  
  14. #ifndef TRUE
  15.  
  16. #define TRUE     1
  17. #define FALSE     0
  18.  
  19. #endif
  20.  
  21. #define ABS(x)        ((x) < 0 ? -(x) : (x))
  22. #define MAX(x,y)    ((x) > (y) ? (x) : (y))
  23. #define MIN(x,y)    ((x) < (y) ? (x) : (y))
  24. #define SGN(x)         ((x) < 0 ? -1 : 1)
  25.     
  26.     /* Name of config file:                    */
  27. #define Default_Config_File_Name "ICoons.cfg"
  28.  
  29.     /* Size of character buffers:                */
  30. #define Buffer_Length   255
  31.  
  32.     /* Tiny number, used for "fuzzyness" of doubles:    */
  33. #define FTINY        (double) 1e-6
  34.  
  35.     /* Max size for file and path names:            */
  36. #define File_Name_Length    20
  37. #define Path_Name_Length    100
  38.  
  39.     /* Max possible resolution for splines:            */
  40. #define Max_Spline_Resolution    10
  41.  
  42.     /* Max possible resolution for patches:            */
  43. #define Max_Patch_Resolution    20
  44.  
  45.     /* Max Nbr. of points:                    */
  46. #define Max_Nbr_Points        500
  47.  
  48.     /* Possible values for Flags fields (may be ORed):    */
  49. #define Flags_Hidden        0x01
  50. #define Flags_Selected        0x02
  51. #define Flags_Marked        0x04
  52.  
  53. #define Mask_VSelected        0x03
  54. #define Mask_VMarked        0x05
  55.  
  56.     /* Macros to manipulate Flags fields:            */
  57. #define Do_Mark(X)       (X).Flags |= Flags_Marked
  58. #define Do_Hide(X)       (X).Flags |= Flags_Hidden
  59. #define Do_Select(X)       (X).Flags |= Flags_Selected
  60. #define Do_Unmark(X)       (X).Flags &= ~Flags_Marked
  61. #define Do_Unhide(X)       (X).Flags &= ~Flags_Hidden
  62. #define Do_Deselect(X)  (X).Flags &= ~Flags_Selected
  63.  
  64. #define Is_Marked(X)     ((X).Flags & Flags_Marked)
  65. #define Is_Hidden(X)     ((X).Flags & Flags_Hidden)
  66. #define Is_Visible(X)     (!Is_Hidden(X))
  67. #define Is_Selected(X)     ((X).Flags & Flags_Selected)
  68.  
  69.     /* Is visible and selected:    */
  70. #define Is_VSelected(X) (((X).Flags & Mask_VSelected) == Flags_Selected)
  71.  
  72.     /* Is visible and marked:    */
  73. #define Is_VMarked(X) (((X).Flags & Mask_VMarked) == Flags_Marked)
  74.  
  75.  
  76.     /* Possible values for What parameter (may be ORed)    */
  77. #define What_SX        0x01    /* Draw splines in 3d X view    */
  78. #define What_SY        0x02    /* Draw splines in 3d Y view    */
  79. #define What_SZ        0x04    /* Draw splines in 3d Z view    */
  80. #define What_SP        0x08    /* Draw splines in persp view    */
  81.  
  82. #define What_KX        0x10    /* Draw knots in 3d X view    */
  83. #define What_KY        0x20    /* Draw knots in 3d Y view    */
  84. #define What_KZ        0x40    /* Draw knots in 3d Z view    */
  85. #define What_KP        0x80    /* Draw knots in persp view     */
  86.  
  87.     /* Combination of What masks:                */
  88.  
  89. #define What_S3        0x07    /* Draw splines in all 3d views    */
  90. #define What_K3        0x70    /* Draw knots in all 3d views    */
  91. #define What_S        0x0f    /* Draw splines in all views    */
  92. #define What_K        0xf0    /* Draw knots in all views     */
  93. #define What_X        0x11    /* Draw all in X view        */
  94. #define What_Y        0x22    /* Draw all in Y view        */
  95. #define What_Z        0x44    /* Draw all in Z view        */
  96. #define What_P        0x88    /* Draw all in persp view    */
  97. #define What_All    0xff    /* Draw everything              */
  98.  
  99. typedef unsigned char    Byte_T;
  100. typedef short        Boolean_T;
  101.  
  102. typedef double         Vector_T[3];
  103. typedef double         Vector4_T[4];
  104.  
  105. typedef double         Matrix_T[3][3];
  106. typedef double         Matrix4_T[4][4];
  107.  
  108.     /* Type for drawing mode:                */
  109. typedef enum {
  110.     DM_Normal,    /* Normal draw mode        */
  111.     DM_Erase,    /* Erase draw mode        */
  112.     DM_Plane    /* Draw in separate plane    */
  113. } Draw_Mode_T;
  114.  
  115.     /* Type for rendering mode:                */
  116. typedef enum {
  117.     RM_Line,
  118.     RM_Flat,
  119.     RM_Gouraud,
  120.     RM_Phong
  121. } Rendering_Mode_T;
  122.  
  123.     /********************************************************/
  124.     /*                            */
  125.     /* Type for a point:                    */
  126.     /*                            */
  127.     /*   Flags:                        */
  128.     /*     Flags for this point (selected, marked etc.)    */
  129.     /*                            */
  130.     /*   Reference_Count:                    */
  131.     /*     Nbr of knots referencing this point.        */
  132.     /*     If Reference_Count <= 0, then this point isn't    */
  133.     /*     in use.                        */
  134.     /*   Work:                        */
  135.     /*     Work variable used in file.c            */
  136.     /*                            */
  137.     /*   Pos:                        */
  138.     /*     Position of point in world coordinates.        */
  139.     /*                            */
  140.     /********************************************************/
  141.  
  142. typedef    struct {
  143.     Byte_T        Flags;
  144.     short        Reference_Count;
  145.     short        Work;
  146.     Vector_T    Pos;
  147. } Point_T;
  148.  
  149.     /********************************************************/
  150.     /*                            */
  151.     /* Type for a knot:                    */
  152.     /*                            */
  153.     /*   Next:                         */
  154.     /*     Pointer to next knot in this spline.         */
  155.     /*    If this is a looping spline, then the last knot    */
  156.     /*    will point to the first knot; otherwise it will    */
  157.     /*    point to NULL.                    */
  158.     /*                            */
  159.     /*   Previous:                         */
  160.     /*     Pointer to previous knot in this spline.    */
  161.     /*    If this is a looping spline, then the first knot*/
  162.     /*    will point to the last knot; otherwise it will    */
  163.     /*    point to NULL.                    */
  164.     /*                            */
  165.     /*   Flags:                        */
  166.     /*     Flags for this knot (selected, marked etc.)    */
  167.     /*                            */
  168.     /*   Point_Id:                        */
  169.     /*     Idx in point array for associated point.    */
  170.     /*                            */
  171.     /*   NX, NY, NZ, NP:                    */
  172.     /*     Nbr of entries in ViewX, ViewY, ViewZ and ViewP    */
  173.     /*                            */
  174.     /*   ViewX, ViewY, ViewZ, ViewP:            */
  175.     /*    Polyline data (screen coordinates) for the     */
  176.     /*     spline from this knot to next knot.        */
  177.     /*     Data exist for each of the four views.        */
  178.     /*                            */
  179.     /*   Tension:                        */
  180.     /*     Tension of this knot.                */
  181.     /*                            */
  182.     /*   Bias:                        */
  183.     /*     Bias of this knot.                */
  184.     /*                            */
  185.     /*   Continuity:                    */
  186.     /*     Continuity of this knot.            */
  187.     /*                            */
  188.     /********************************************************/
  189.  
  190. typedef struct Knot_Tag {
  191.     struct Knot_Tag    *Next;
  192.     struct Knot_Tag    *Previous;
  193.     Byte_T        Flags;
  194.     short        Point_Id;
  195.     Byte_T        NX, NY, NZ, NP;
  196.     short        ViewX[Max_Spline_Resolution+1][2];
  197.     short        ViewY[Max_Spline_Resolution+1][2];
  198.     short        ViewZ[Max_Spline_Resolution+1][2];
  199.     short        ViewP[Max_Spline_Resolution+1][2];
  200.     double        Tension;
  201.     double        Bias;
  202.     double        Continuity;
  203. } Knot_T;
  204.  
  205.     /********************************************************/
  206.     /*                            */
  207.     /* Type for a spline:                    */
  208.     /*                            */
  209.     /*   Next:                         */
  210.     /*     Pointer to next spline. NULL if this is last    */
  211.     /*    spline.                        */
  212.     /*                            */
  213.     /*   Previous:                         */
  214.     /*     Pointer to previous spline. NULL if this is     */
  215.     /*    first spline.                    */
  216.     /*                            */
  217.     /*   Flags:                        */
  218.     /*     Flags for this spline (selected, marked etc.)    */
  219.     /*                            */
  220.     /*   Nbr_Knots:                        */
  221.     /*     Number of knots in this spline.            */
  222.     /*                            */
  223.     /*   Loop:                        */
  224.     /*     TRUE if this spline is a closed loop.        */
  225.     /*                            */
  226.     /*   First:                        */
  227.     /*     Pointer to first knot in this spline.        */
  228.     /*                            */
  229.     /*   Last:                        */
  230.     /*     Pointer to last knot in this spline.        */
  231.     /*                            */
  232.     /********************************************************/
  233.  
  234. typedef struct Spline_Tag {
  235.     struct Spline_Tag *Next;
  236.     struct Spline_Tag *Previous;
  237.     Byte_T          Flags;
  238.     short          Nbr_Knots;
  239.     Boolean_T      Loop;
  240.     Knot_T          *First;
  241.     Knot_T          *Last;
  242. } Spline_T;
  243.  
  244.  
  245.     /********************************************************/
  246.     /*                            */
  247.     /* Type for a state:                    */
  248.     /*                            */
  249.     /* This defines the current state of the program.    */
  250.     /*                            */
  251.     /*   Handle_Event:                    */
  252.     /*     Function to be called for IDCMP events.        */
  253.     /*                            */
  254.     /*   Timeout:                        */
  255.     /*     Function to be called when a timeout happens.    */
  256.     /*                            */
  257.     /*   Redraw:                        */
  258.     /*     Function to be called to redraw the screen.    */
  259.     /*                            */
  260.     /*                            */
  261.     /********************************************************/
  262.  
  263. typedef struct {
  264.     Boolean_T     (*Handle_Event)();
  265.     void         (*Timeout)();
  266.     void         (*Redraw)();
  267. } State_T;
  268.  
  269. /* Vector manipulation macros: */
  270. #include "vector.h"
  271.  
  272. #endif
  273.