home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / VOGLE.H < prev    next >
C/C++ Source or Header  |  1993-05-28  |  10KB  |  475 lines

  1. /*
  2.  * default location for font library
  3.  */
  4. #ifdef PC    /* Stupid pox head crap */
  5. #define    FONTLIB    "c:\\lib\\hershey\\"
  6. char    *vallocate();
  7. char    *malloc();
  8. #endif
  9.  
  10. #ifndef FONTLIB
  11. #define FONTLIB    "/usr/local/lib/hershey/"
  12. #endif
  13.  
  14. /*
  15.  * standard colour indices
  16.  */
  17. #define    BLACK        0
  18. #define    RED        1
  19. #define    GREEN        2
  20. #define    YELLOW        3
  21. #define    BLUE        4
  22. #define    MAGENTA        5
  23. #define    CYAN        6
  24. #define    WHITE        7
  25.  
  26. /*
  27.  * when (if ever) we need the precision
  28.  */
  29. #ifdef DOUBLE
  30. #define    float    double
  31. #endif
  32.  
  33. /*
  34.  * How to convert degrees to radians
  35.  */
  36. #define    PI    3.14159265358979
  37. #define D2R    (PI / 180.0)
  38.  
  39. /*
  40.  * miscellaneous typedefs and type defines
  41.  */
  42. typedef float    Vector[4];
  43. typedef float    Matrix[4][4];
  44. typedef float    Tensor[4][4][4];
  45.  
  46. /*
  47.  * when register variables get us into trouble
  48.  */
  49. #ifdef NOREGISTER
  50. #define    register
  51. #endif
  52.  
  53. /*
  54.  * max number of vertices in a ploygon
  55.  */
  56. #define    MAXVERTS    128
  57.  
  58. /*
  59.  * max number of characters in a font name
  60.  */
  61. #define    FONTNAMELEN    32
  62.  
  63. /*
  64.  * object definitions
  65.  */
  66. #define MAXENTS        101        /* size of object table */
  67. #define    MAXTOKS        100        /* num. of tokens alloced at once in
  68.                        an object  */
  69.  
  70. /*
  71.  * functions which can appear in objects
  72.  */
  73. #define    ARC        1
  74. #define    BOXTEXT        2
  75. #define    CALLOBJ        3
  76. #define    CENTERTEXT    4
  77. #define    CIRCLE        5
  78. #define    CLEAR        6
  79. #define    COLOR        7
  80. #define    DRAW        8
  81. #define    DRAWCHAR    9
  82. #define    DRAWSTR        10
  83. #define    FIXEDWIDTH    11
  84. #define    FONT        12
  85. #define    HATCHANG    13
  86. #define    HATCHPITCH    14
  87. #define    LOADMATRIX    15
  88. #define    MAPCOLOR    16
  89. #define    MOVE        17
  90. #define    MULTMATRIX    18
  91. #define    POLY        19
  92. #define    POLYFILL    20
  93. #define    POLYHATCH    21
  94. #define    POPATTRIBUTES    22
  95. #define    POPMATRIX    23
  96. #define    POPVIEWPORT    24
  97. #define    PUSHATTRIBUTES    25
  98. #define    PUSHMATRIX    26
  99. #define    PUSHVIEWPORT    27
  100. #define    RCURVE        28
  101. #define    RPATCH        29
  102. #define    SECTOR        30
  103. #define    TEXTANG        31
  104. #define    TEXTSIZE    32
  105. #define    VIEWPORT    33
  106. #define    BACKBUFFER    34
  107. #define    FRONTBUFFER    35
  108. #define    SWAPBUFFER    36
  109. #define    BACKFACING    37
  110. #define    TRANSLATE    38
  111. #define    ROTATE        39
  112. #define    SCALE        40
  113. #define    VFLUSH        41
  114.  
  115. /*
  116.  * data types for object tokens
  117.  */
  118. typedef union tk {
  119.     int        i;
  120.     float        f;
  121. } Token;
  122.  
  123. typedef struct tls {
  124.     int        count;
  125.     Token        *toks;
  126.     struct tls    *next;
  127. } TokList;
  128.  
  129. /*
  130.  * attributes
  131.  */
  132. typedef struct {
  133.     char    fill,
  134.         hatch,
  135.         backface,
  136.         centered,
  137.         fixedwidth;
  138.     int     color;
  139.     int     softtext;
  140.     float   fontheight;
  141.     float   fontwidth;
  142.     float    hatchcos,
  143.         hatchsin,
  144.         hatchpitch;
  145.     float    textcos,
  146.         textsin;
  147.     char    font[FONTNAMELEN];
  148. } Attribute;
  149.  
  150. /*
  151.  * viewport
  152.  */
  153. typedef struct vp {
  154.     float    left;
  155.     float    right;
  156.     float    bottom;
  157.     float    top;
  158. } Viewport; 
  159.  
  160. /*
  161.  * stacks
  162.  */
  163. typedef    struct    ms {    /* Matrix stack entries    */
  164.     Matrix        m;
  165.     Matrix        p;
  166.     struct    ms    *back;
  167. } Mstack;
  168.  
  169. typedef    struct    as {    /* Attribute stack entries */
  170.     Attribute    a;
  171.     struct    as    *back;
  172. } Astack;
  173.  
  174. typedef    struct    vs {    /* Viewport stack entries */
  175.     Viewport    v;
  176.     struct    vs    *back;
  177. } Vstack;
  178.  
  179. /*
  180.  * vogle device structures
  181.  */
  182. typedef struct dev {
  183.     char    *devname;        /* name of device */
  184.     char    *large,            /* name of large font */
  185.         *small;            /* name of small font */
  186.     int    (*Vbackb)(),        /* Set drawing in back buffer */
  187.         (*Vchar)(),        /* Draw a hardware character */
  188.         (*Vcheckkey)(),        /* Ckeck if a key was hit */
  189.         (*Vclear)(),        /* Clear the screen to current color */
  190.         (*Vcolor)(),        /* Set current color */
  191.         (*Vdraw)(),        /* Draw a line */
  192.         (*Vexit)(),        /* Exit graphics */
  193.         (*Vfill)(),        /* Fill a polygon */
  194.         (*Vfont)(),        /* Set hardware font */
  195.         (*Vfrontb)(),        /* Set drawing in front buffer */
  196.         (*Vgetkey)(),        /* Wait for and get the next key hit */
  197.         (*Vinit)(),        /* Initialise the device */
  198.         (*Vlocator)(),        /* Get mouse/cross hair position */
  199.         (*Vmapcolor)(),        /* Set color indicies */
  200.         (*Vstring)(),        /* Draw a hardware string */
  201.         (*Vswapb)(),        /* Swap front and back buffers */
  202.         (*Vsync)();        /* Syncronise the display */
  203. } DevEntry;
  204.  
  205. typedef struct vdev {
  206.     char        initialised,
  207.             clipoff,
  208.             inobject,
  209.             inpolygon,
  210.             upset,            /* is up vector set */
  211.             cpVvalid,        /* is the current device position valid */
  212.             sync,            /* Do we syncronise the display */
  213.             inbackbuffer,        /* are we in the backbuffer */
  214.             clipplanes;        /* active clipping planes */
  215.     void        (*pmove)(),        /* Polygon moves */
  216.             (*pdraw)();        /* Polygon draws */
  217.     TokList        *tokens;        /* ptr to list of tokens for current object */
  218.     Mstack        *transmat;        /* top of transformation stack */
  219.     Astack        *attr;            /* top of attribute stack */
  220.     Vstack        *viewport;        /* top of viewport stack */
  221.     float        hheight, hwidth;    /* hardware character height, width */
  222.     Vector        cpW,            /* current postion in world coords */
  223.             cpWtrans,        /* current world coords transformed */
  224.             upvector;        /* world up */
  225.     int        depth,            /* # bit planes on screen */
  226.             maxVx, minVx,
  227.             maxVy, minVy,
  228.             sizeX, sizeY,         /* size of square on screen */
  229.             sizeSx, sizeSy,        /* side in x, side in y (# pixels) */
  230.             cpVx, cpVy;
  231.     DevEntry    dev;
  232. } Device;
  233.  
  234. extern Device    vdevice;        /* device structure */
  235.  
  236. #define    V_X    0            /* x axis in cpW */
  237. #define    V_Y    1            /* y axis in cpW */
  238. #define    V_Z    2            /* z axis in cpW */
  239. #define    V_W    3            /* w axis in cpW */
  240.  
  241. /*
  242.  * function definitions
  243.  */
  244.  
  245. /*
  246.  * arc routines
  247.  */
  248. extern void    arcprecision();
  249. extern void    arc();
  250. extern void    circle();
  251. extern void    circleprecision();
  252. extern void    sector();
  253.  
  254. /*
  255.  * attr routines
  256.  */
  257. extern void    popattributes();
  258. extern void    pushattributes();
  259.  
  260. /*
  261.  * curve routines
  262.  */
  263. extern void    curve();
  264. extern void    rcurve();
  265. extern void    curven();
  266. extern void    drcurve();
  267. extern void    curvebasis();
  268. extern void    curveprecision();
  269.  
  270. /*
  271.  * draw routines
  272.  */
  273. extern void    draw();
  274. extern void    draw2();
  275. extern void    rdraw();
  276. extern void    rdraw2();
  277. extern void    sdraw2();
  278. extern void    rsdraw2();
  279.  
  280. /*
  281.  * device routines
  282.  */
  283. extern void    clear();
  284. extern void    color();
  285. extern int    getkey();
  286. extern int    getplanes();
  287. extern int    locator();
  288. extern int    slocator();
  289. extern void    mapcolor();
  290.  
  291. extern void    vinit();
  292. extern void    vexit();
  293. extern void    verror();
  294. extern void    voutput();
  295. extern void    vnewdev();
  296. extern char    *vgetdev();
  297.  
  298. /*
  299.  * mapping routines
  300.  */
  301. extern int    WtoVx();
  302. extern int    WtoVy();
  303. extern void    VtoWxy();
  304. extern void    CalcW2Vcoeffs();
  305.  
  306. /*
  307.  * general matrix and vector routines
  308.  */
  309. extern void    mult4x4();
  310. extern void    copymatrix();
  311. extern void    identmatrix();
  312. extern void    copytranspose();
  313.  
  314. extern void    multvector();
  315. extern void    copyvector();
  316. extern void    premultvector();
  317.  
  318. /*
  319.  * matrix stack routines
  320.  */
  321. extern void    getmatrix();
  322. extern void    popmatrix();
  323. extern void    loadmatrix();
  324. extern void    pushmatrix();
  325. extern void    multmatrix();
  326. extern Matrix    *getmstackaddress();
  327.  
  328. /*
  329.  * move routines
  330.  */
  331. extern void    move();
  332. extern void    move2();
  333. extern void    rmove();
  334. extern void    rmove2();
  335. extern void    smove2();
  336. extern void    rsmove2();
  337.  
  338. /*
  339.  * object routines
  340.  */
  341. extern int    isobj();
  342. extern int    genobj();
  343. extern void    delobj();
  344. extern void    makeobj();
  345. extern void    loadobj();
  346. extern void    saveobj();
  347. extern void    callobj();
  348. extern void    closeobj();
  349. extern int    getopenobj();
  350. extern Token    *newtokens();
  351.  
  352. /*
  353.  * patch routines.
  354.  */
  355. extern void    patch();
  356. extern void    rpatch();
  357. extern void    drpatch();
  358. extern void    patchbasis();
  359. extern void    patchcurves();
  360. extern void    patchprecision();
  361. extern void    transformtensor();
  362.  
  363. /*
  364.  * point routines
  365.  */
  366. extern void    point();
  367. extern void    point2();
  368. extern void    spoint2();
  369.  
  370. /*
  371.  * polygon routines.
  372.  */
  373. extern void    poly();
  374. extern void     hatchang();
  375. extern void    makepoly();
  376. extern void    polyfill();
  377. extern void    closepoly();
  378. extern void    polyhatch();
  379. extern void     hatchpitch();
  380. extern void    backface();
  381. extern void    backfacedir();
  382.  
  383. /*
  384.  * rectangle routine
  385.  */
  386. extern void    rect();
  387.  
  388. /*
  389.  * tensor routines
  390.  */
  391. extern void multtensor();
  392. extern void copytensor();
  393. extern void premulttensor();
  394. extern void copytensortrans();
  395.  
  396. /*
  397.  * text routines
  398.  */
  399. extern void    font();
  400. extern void    boxfit();
  401. extern void    boxtext();
  402. extern void    drawstr();
  403. extern void    textang();
  404. extern int    numchars();
  405. extern void    drawchar();
  406. extern void    textsize();
  407. extern float    strlength();
  408. extern float    sstrlength();
  409. extern void    centertext();
  410. extern void    fixedwidth();
  411. extern void    getcharsize();
  412. extern void    getfontsize();
  413. extern float    getfontwidth();
  414. extern float    getfontheight();
  415.  
  416. /*
  417.  * transformation routines
  418.  */
  419. extern void    scale();
  420. extern void    translate();
  421. extern void    rotate();
  422.  
  423. /*
  424.  * window definition routines
  425.  */
  426. extern void    ortho();
  427. extern void    ortho2();
  428. extern void    lookat();
  429. extern void    window();
  430. extern void    polarview();
  431. extern void    perspective();
  432. extern void    up();
  433.  
  434. /*
  435.  * routines for manipulating the viewport
  436.  */
  437. extern void    viewport();
  438. extern void    popviewport();
  439. extern void    pushviewport();
  440.  
  441. /*
  442.  * routines for retrieving the graphics position
  443.  */
  444. extern void    getgp();
  445. extern void    getgp2();
  446. extern void    sgetgp2();
  447.  
  448. /*
  449.  * routines for retrieving the aspect details of the device
  450.  */
  451. extern float    getaspect();
  452. extern void    getfactors();
  453. extern void    getdisplaysize();
  454.  
  455. /*
  456.  * routines for handling the buffering
  457.  */
  458. extern int    backbuffer();
  459. extern void    frontbuffer();
  460. extern int    swapbuffers();
  461.  
  462. /*
  463.  * routines for window sizing and positioning
  464.  */
  465. extern void    prefsize();
  466. extern void    prefposition();
  467.  
  468. /* 
  469.  * Misc control routines
  470.  */
  471. extern void    clipping();
  472. extern void    vsetflush();
  473. extern void    vflush();
  474.  
  475.