home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch3_5 / bsp.h next >
Encoding:
C/C++ Source or Header  |  1995-04-04  |  2.9 KB  |  85 lines

  1. /* bsp.h: header file for BSP tree algorithm
  2.  * Copyright (c) Norman Chin 
  3.  */
  4. #ifndef _BSP_INCLUDED
  5. #define _BSP_INCLUDED
  6.  
  7. #include <stdio.h>        
  8. #include <stdlib.h>        /* exit() */
  9. #include <assert.h>        /* assert() */
  10. #include <math.h>        /* fabs() */
  11. #include <values.h>        /* MAXINT */
  12. #include "../ch7-7/GG4D/GGems.h"
  13.  
  14. typedef struct { float rr,gg,bb; } COLOR;
  15. typedef struct { float xx,yy,zz; } POINT;
  16. typedef struct { float aa,bb,cc,dd; } PLANE;
  17.  
  18. typedef struct vertexTag {
  19.    float xx,yy,zz;        /* vertex position */
  20.    struct vertexTag *vnext;    /* pointer to next vertex in CCW order */
  21. } VERTEX;
  22. #define NULL_VERTEX ((VERTEX *) NULL)
  23.  
  24. typedef struct faceTag {
  25.    COLOR color;            /* color of face */
  26.    VERTEX *vhead;        /* head of list of vertices */
  27.    PLANE plane;            /* plane equation of face */
  28.    struct faceTag *fnext;    /* pointer to next face */
  29. } FACE;
  30. #define NULL_FACE ((FACE *) NULL)
  31.  
  32. typedef enum {PARTITION_NODE= 'p', IN_NODE= 'i', OUT_NODE= 'o'} NODE_TYPE; 
  33.  
  34. typedef struct partitionnodeTag {
  35.    FACE *sameDir, *oppDir;    /* pointers to faces embedded in node */
  36.  
  37.    struct bspnodeTag *negativeSide, *positiveSide; /* "-" & "+" branches */
  38. } PARTITIONNODE;
  39. #define NULL_PARTITIONNODE ((PARTITIONNODE *) NULL)
  40.  
  41. typedef struct bspnodeTag {
  42.    NODE_TYPE kind;        /* kind of BSP node */
  43.  
  44.    PARTITIONNODE *node; /* if kind == (IN_NODE || OUT_NODE) then NULL */
  45. } BSPNODE;
  46. #define NULL_BSPNODE ((BSPNODE *) NULL)
  47.  
  48. #define TOLER 0.0000076
  49. #define IS_EQ(a,b) ((fabs((double)(a)-(b)) >= (double) TOLER) ? 0 : 1)
  50. typedef enum {NEGATIVE= -1, ZERO= 0, POSITIVE= 1} SIGN;
  51. #define FSIGN(f) (((f) < -TOLER) ? NEGATIVE : ((f) > TOLER ? POSITIVE : ZERO))
  52.  
  53. /* external functions */
  54. BSPNODE *BSPconstructTree(FACE **faceList);
  55. boolean BSPisViewerInPositiveSideOfPlane(const PLANE *plane,const POINT *position);
  56. void BSPtraverseTreeAndRender(const BSPNODE *bspNode,const POINT *position);
  57. void BSPfreeTree(BSPNODE **bspNode);
  58.  
  59. boolean BSPdidViewerCollideWithScene(const POINT *from, const POINT *to,
  60.                      const BSPNODE *bspTree);
  61.  
  62. VERTEX *allocVertex(float xx,float yy,float zz);
  63. FACE *allocFace(const COLOR *color, VERTEX *vlist,const PLANE *plane);
  64. void appendVertex(VERTEX **vhead,VERTEX **vtail,VERTEX *vertex);
  65. void appendFace(FACE **fhead,FACE **ftail,FACE *face);
  66. void freeVertexList(VERTEX **vlist);
  67. void freeFaceList(FACE **flist);
  68.  
  69. void computePlane(float xx0,float yy0,float zz0,float xx1,float yy1,float zz1,
  70.           float xx2,float yy2,float zz2, PLANE *plane);
  71.  
  72. SIGN anyEdgeIntersectWithPlane(float x1, float y1, float z1,
  73.                    float x2, float y2, float z2,
  74.                    const PLANE *plane,
  75.                    float *ixx, float *iyy, float *izz);
  76. void BSPpartitionFaceListWithPlane(const PLANE *plane,FACE **faceList,
  77.                    FACE **faceNeg, FACE **facePos,
  78.                    FACE **faceSameDir, FACE **faceOppDir);
  79. void drawFaceList(FILE *, const FACE *faceList); 
  80.  
  81. char *MYMALLOC(unsigned num);
  82. void MYFREE(char *ptr);
  83. long MYMEMORYCOUNT(void);
  84. #endif  /* _BSP_INCLUDED */
  85.