home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsiii / exttest / exthit.h < prev    next >
C/C++ Source or Header  |  1992-03-16  |  4KB  |  117 lines

  1. /******************************************************************
  2. exthit.h
  3.  
  4. This is the header file for a C++ class for fast n-dimensional extent
  5. overlap checking. An instance of the class is initialized with a
  6. call to the constructor.
  7.  
  8.   ExtHit(size) - where size is the maximum number of extents that
  9.       can be held (and hence tested against each other) in the ExtHit
  10.     class instance.
  11.  
  12. There are three other methods in the ExtHit class:
  13.  
  14.   ~ExtHit () - the ExtHit class destructor frees the memory allocated for
  15.      the class instance's internal tables, and destroys the class instance.
  16.  
  17.   BOOL add( Extent &extent, Ptr obj ) - This method adds an extent to
  18.     the ExtHit class instance. The extent argument is a structure containing
  19.     the values for the extent, and the obj argument is a pointer to the
  20.     the object for the new extent.
  21.  
  22.   void test (void (*func)(Ptr d, Ptr e1, Ptr e2), Ptr data) - This method
  23.     peforms the actual extent overlap checking. The func argument is a
  24.     pointer to a function to be called for each pair of objects whose
  25.     extents overlap. The data argument allows user specified data to be
  26.     passed to func. Func is called with three arguments; the user supplied
  27.     data d, and pointers to the overlapping objects (the pointer passed
  28.     as the obj argument in the add method).
  29. ******************************************************************/
  30.  
  31. #ifndef _EXTHIT_H
  32. #define _EXTHIT_H
  33.  
  34. #ifndef NULL
  35. #define NULL 0
  36. #endif
  37.  
  38. #ifndef TRUE
  39. #define FALSE 0
  40. #define TRUE 1
  41. #endif
  42.  
  43. #ifndef MIN
  44. #define MIN(a,b) (((a)<(b))?(a):(b))
  45. #define MAX(a,b) (((a)>(b))?(a):(b))
  46. #endif
  47.  
  48. typedef void* Ptr;
  49. typedef short BOOL;
  50.  
  51. // The number of dimensions to be used in extent checking 
  52. // This constant should be changed to reflect the number
  53. // of dimensions being checked.
  54. const int num_dimensions=4;
  55.  
  56. typedef struct tagExtent {
  57.   int min [num_dimensions];
  58.   int max [num_dimensions];
  59. } Extent;
  60.  
  61. typedef struct tagCollideRecord CollideRecord; 
  62.  
  63. typedef struct tagMinMaxRecord
  64. {
  65.  CollideRecord *ptr;        // The parent CollideRecord for this MMR
  66.  int value;                    // The extent dimension value for this MMR
  67. } MinMaxRecord;
  68.  
  69. typedef MinMaxRecord *MinMaxRecordPtr;
  70.  
  71. typedef struct tagCollideRecord
  72. {
  73.   int index;                // The index number of the extent represented 
  74.   Ptr obj;                    // A pointer to the extent's parent geometry
  75.   CollideRecord *nextOpen;        // The next element on the open list
  76.   CollideRecord *prevOpen;        // The previous element on the open list
  77.   CollideRecord *nextActive;    // The next element on the active list
  78.   CollideRecord *prevActive;    // The previous element on the active list
  79.   MinMaxRecord min [num_dimensions];    // MMR's for the minimum extent values
  80.   MinMaxRecord max [num_dimensions];    // MMR's for the maximum extent values
  81.   BOOL active;            // Flag specifying CR overlapped with another CR
  82.   BOOL open;            // Flag specifying CR is currently on the open list
  83. } CollideRecord;
  84.  
  85. /******************************************************************
  86.  Definition for the ExtHit class
  87.  ******************************************************************/
  88. class ExtHit
  89. {
  90.   public:
  91.     ExtHit (int size);                        // Class constructor
  92.     ~ExtHit ();                                // Class destructor
  93.     BOOL add( Extent &extent, Ptr obj );    // Adds an extent to the collideList
  94.     void test (void (*func)(Ptr d, Ptr e1, Ptr e2), Ptr data);
  95.                                             // Perform extent overlap testing
  96.  
  97.   private:
  98.     int    maxSize;                // Maximum number of extents that can be held
  99.     int    numColRecs;                // Number of CollideRecords in the CollideList
  100.     int    numOverlaps;            // Number of MMRs in the overlapList
  101.     MinMaxRecord **overlapList;    // Extent values for a single dimension
  102.     BOOL *overlapTable;            // Table specifying which extents overlapped
  103.     CollideRecord *collideList;    // Array holding the extent information
  104.     CollideRecord *activeList;    // The head of the list of active extents
  105.  
  106.     void subtest ( int dim, int oLstSize, void (*func)(Ptr d, Ptr p1, Ptr p2),
  107.                     Ptr data);
  108. };
  109.  
  110. int minMaxCompare( const void* rec1, const void* rec2);
  111.  
  112. #endif
  113.  
  114. /******************************************************************
  115.  End of exthit.h
  116.  ******************************************************************/
  117.