MathEngine
Home Page       Structures       File List       Functions and Macros      

McdFrame.h

Go to the documentation of this file.
00001 /* -*-c++-*-
00002   Copyright MathEngine PLC 2000. All rights reserved.
00003   $RCSfile: McdFrame.h,v $ $Revision: 1.32 $ $Date: 2000/08/15 19:04:55 $
00004 */
00005 /**
00006   @file McdFrame.h
00007   Collision Toolkit main header file.
00008 */
00009 
00010 #ifndef MCDFRAME_H
00011 #define MCDFRAME_H
00012 
00013 #include "MePrecision.h"
00014 #include <stddef.h> /* for size_t */
00015 
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019   
00020   typedef MeReal McdReal; /**< type used for reals in the Mcd API */
00021   typedef short McdBool; /**< @internal */
00022 
00023 /*----------------------------------------------------------------
00024  * Error Reporting
00025  *---------------------------------------------------------------
00026  */
00027 
00028 /** @internal */
00029 typedef void (*McdMessageHandler)(const char *msg);
00030 
00031 /** @internal */
00032 McdMessageHandler McdSetFatalErrorHandler(McdMessageHandler);
00033 /** @internal */
00034 McdMessageHandler McdSetWarningHandler(McdMessageHandler);
00035 /** @internal */
00036 McdMessageHandler McdSetInfoHandler(McdMessageHandler);
00037 
00038 /*----------------------------------------------------------------
00039  * memory management
00040  *---------------------------------------------------------------
00041  */
00042 
00043 #ifdef MCD_NO_MEMEMORY
00044 
00045   /** @internal */
00046 void McdMemorySetFunctions(void *(*create)(size_t bytes),
00047                       void *(*resize)(void * block, size_t bytes),
00048                       void (*destroy)(void * block) );
00049 
00050 #endif
00051 
00052 /*----------------------------------------------------------------
00053  * Framework 
00054  *---------------------------------------------------------------
00055  */
00056 
00057 void
00058 McdInit( int geoTypeMaxCount );
00059 
00060 void
00061 McdTerm();
00062 
00063 /*---------------------------------------------------------------
00064  * McdGeometry
00065  *---------------------------------------------------------------
00066  */
00067 
00068 /** Abstract "base class" for geometrical types. All concrete geometrical
00069     types share a common set of functionality defined by the McdGeometry
00070     interface.
00071 */
00072 
00073 typedef struct _McdGeometry McdGeometry;
00074 
00075 /** References to MathEngine objects are 
00076 made using "ID" tokens instead of explicit pointers 
00077 */
00078 typedef McdGeometry *McdGeometryID;
00079 
00080 int
00081 McdGeometryGetTypeID( McdGeometryID g );
00082 
00083 void
00084 McdGeometryDestroy( McdGeometryID g );
00085 
00086 int
00087 McdGeometryGetMassProperties( McdGeometryID g, 
00088                               MeMatrix4 relativeTransform, 
00089                               MeMatrix3 inertiaMatrix, 
00090                               MeReal *volume );
00091 
00092 /*---------------------------------------------------------------
00093  * McdModel
00094  *---------------------------------------------------------------
00095  */
00096 
00097 /** An McdModel represents a collision model whose geometrical shape is
00098     specified by a concrete McdGeometry type. Collision models are the
00099     principal type of object in the system, for which bounding volume,
00100     culling and intersections queries are available.
00101 */
00102 
00103 typedef struct _McdModel McdModel; 
00104 
00105 /** References to MathEngine objects are 
00106 made using "ID" tokens instead of explicit pointers 
00107 */
00108 typedef McdModel *McdModelID; 
00109 
00110 
00111 /** @internal */
00112 void
00113 McdModelPoolSetSize( int size );
00114 
00115 void
00116 McdModelPoolSetIncrement( int increment );
00117 
00118 McdModelID
00119 McdModelCreateEmpty();
00120 
00121 McdModelID
00122 McdModelCreate( McdGeometryID g );
00123 
00124 void
00125 McdModelSetGeometry( McdModelID cm, McdGeometryID g );
00126 /* calls build, which builds if needed */
00127 
00128 McdGeometryID
00129 McdModelGetGeometry( McdModelID g );
00130 
00131 int
00132 McdModelGetGeometryTypeID( McdModelID g );
00133 
00134 void 
00135 McdModelDestroy( McdModelID cm );
00136 
00137 unsigned int
00138 McdModelRemoveFromSpace( McdModelID cm );
00139 
00140 void
00141 McdUpdateModelInSpace( McdModelID cm );
00142 
00143 unsigned int
00144 McdModelFreezeInSpace( McdModelID cm );
00145 
00146 unsigned int
00147 McdModelUnfreezeInSpace( McdModelID cm );
00148 
00149 unsigned int
00150 McdModelIsFrozenInSpace( McdModelID cm );
00151 
00152   /** @internal */
00153 void
00154 McdModelSetResponseID( McdModelID cm, int reponseID );
00155 
00156   /** @internal */
00157 int
00158 McdModelGetResponseID( McdModelID cm );
00159 
00160 void
00161 McdModelSetContactTolerance( McdModelID cm , McdReal tol );
00162 
00163 McdReal
00164 McdModelGetContactTolerance( McdModelID cm );
00165 
00166 void
00167 McdModelGetBSphere( McdModelID cm, MeVector3 center, McdReal *radius );
00168 
00169 void
00170 McdModelGetAABB( McdModelID cm, MeVector3 minCorner, MeVector3 maxCorner );
00171 
00172 void
00173 McdModelSetTransformPtr( McdModelID cm, MeMatrix4 geometryTM );
00174 
00175 MeMatrix4 *
00176 McdModelGetTransformPtr( McdModelID cm );
00177 
00178 void
00179 McdModelSetUserData( McdModelID cm, void *data );
00180 
00181 void*
00182 McdModelGetUserData( McdModelID cm );
00183 
00184 unsigned int
00185 McdModelSetInteractionEnabled( McdModelID cm1, McdModelID cm2 );
00186 
00187 unsigned int
00188 McdModelSetInteractionDisabled( McdModelID cm1, McdModelID cm2 );
00189 
00190 unsigned int
00191 McdModelInteractionIsEnabled( McdModelID cm1, McdModelID cm2 );
00192 
00193 /*---------------------------------------------------------------
00194  * McdModelPair
00195  *---------------------------------------------------------------
00196  */
00197 
00198   /** Identifies and keeps track of a particular pair of collision models
00199       over multiple time steps. It is used by the farfield module to
00200       identify pairs of models that are nearby to each other and
00201       potentially colliding. It is used as an argument to the McdIntersect
00202       functions, which rely on the same struct being re-used for the same
00203       pair of collision models for multiple time step.*/
00204 
00205 typedef struct 
00206 { 
00207   /** The first model */
00208   McdModelID model1; 
00209   /** The other model */
00210   McdModelID model2; 
00211   /** @internal */
00212   void *pairData;
00213 
00214 } McdModelPair;
00215 
00216 void
00217 McdModelPairInit( McdModelPair *mcdPair, McdModelID model1, McdModelID model2);
00218 
00219 void
00220 McdModelPairTerm( McdModelPair *mcdPair );
00221 
00222   /** @internal */
00223 void
00224 McdModelPairSetUserData( McdModelPair *mcdPair, void *userData );
00225 
00226   /** @internal */
00227 void *
00228 McdModelPairGetUserData( McdModelPair *mcdPair );
00229 
00230   /** @internal */
00231 void
00232 McdModelPairSetResponseData( McdModelPair *mcdPair, void *responseData );
00233 
00234   /** @internal */
00235 void *
00236 McdModelPairGetResponseData( McdModelPair *mcdPair );
00237 
00238 /*----------------------------------------------------------------
00239  * McdModelPairArray 
00240  *---------------------------------------------------------------
00241  */
00242  
00243   /**
00244      An array of references to McdModelPair structures, in which three
00245      "nearby states" are distinguished:
00246      "hello", "staying" and "goodbye".
00247 
00248      The array is partioned into three index ranges, one for each of the
00249      distinct states:
00250 
00251      goodbye pairs:
00252      i = 0 .. goodbyeLastIndex
00253 
00254      hello pairs:
00255      i = helloFirstIndex .. stayingFirstIndex - 1
00256 
00257      staying pairs:
00258      i = stayingFirstIndex .. stayingLastIndex
00259 
00260      The scheme used for index ranges allows all "current pairs" ( hello +
00261      staying) to be iterated through in single loop using the index range
00262      i = helloFirstIndex .. stayingLastIndex
00263 
00264      The user must initialize this structure by setting @a array and @a size
00265      to appropriate values.
00266 
00267    */
00268 
00269   /** @internal */
00270 typedef struct 
00271 {
00272   McdModelPair **array;  /**< array of McdModel pairs */
00273   
00274   int size;              /**< number of elements in @a array */
00275   
00276   int goodbyeLastIndex;  /**< index range for "goodbye" pairs is:
00277                             i = 0 ,,, goodbyeLastIndex  */
00278   
00279   int helloFirstIndex;   /**< index range for "hello" pairs is:
00280                             i = helloFirstIndex ,,, stayingFirstIndex - 1
00281                          */
00282                             
00283   int stayingFirstIndex; /**< index range for "staying" pairs is:
00284                             i = stayingFirstIndex ,,, stayingLastIndex */
00285   
00286    int stayingLastIndex;  /**< index range for "staying" pairs is:
00287                              i = stayingFirstIndex ,,, stayingLastIndex */
00288 } McdModelPairArray;
00289 
00290 /** @internal */
00291 
00292 void
00293 McdModelPairArrayReset( McdModelPairArray* );
00294 
00295 /*----------------------------------------------------------------
00296  * McdContact 
00297  *---------------------------------------------------------------
00298  */
00299 
00300 /** Geometric contact point information. Typically, a number of McdContact
00301     structs are associated with a given McdModelPair. Some of the
00302     information in the McdContact struct depends on the order of the @arg
00303     model1 and @arg model2 fields of the associated McdModelPair.
00304     @see McdModelPair
00305 */
00306 
00307 typedef struct
00308 {
00309 
00310   /** position, in world coordinates, of the point of contact */
00311 
00312     McdReal position[3];            
00313 
00314   /** surface normal at the contact position. Sign chosen so as to point
00315       from @arg model1 to @arg model2 in the associated McdModelPair. */
00316 
00317     McdReal normal[3];              
00318 
00319   /** separation between objects. Negative if there is penetration */
00320 
00321     McdReal separation;             
00322 
00323   /** local curvature of @arg model1's surface at the contact position */
00324 
00325     McdReal curvature1;             
00326 
00327   /** local curvature of @arg model2's surface at the contact position */
00328 
00329     McdReal curvature2;             
00330 
00331   /** dimensional characterisation of the contact. Possible values are  0,
00332       1 and 2, corresponding to  point, line and surface, respectively */ 
00333 
00334   short dims;                     
00335 
00336   /** auxiliary data. Used by some intersection functions. This API element
00337       is subject to change */
00338 
00339   void *auxPtr;    
00340 
00341   /** an auxiliary integer field. Used by some intersection functions. 
00342       This API element is subject to change */ 
00343 
00344   int auxTag;                   
00345 
00346 } McdContact;
00347 
00348 
00349 /** Utility function for reducing a list of contacts to
00350     a smaller list. Useful mostly when several models compose one object.
00351 */
00352 int
00353 McdContactSimplify( McdReal* avgNormal, 
00354                     McdContact* contacts_src, int nContacts_src,
00355                     McdContact* contacts_dst, int nContacts_dest );
00356 
00357 
00358 /*----------------------------------------------------------------
00359  * McdIntersect 
00360  *---------------------------------------------------------------
00361  */
00362 
00363 /** Intersection query data. */
00364 typedef struct
00365 {
00366     McdModelID model1;              /**< one of the collision models */
00367     McdModelID model2;              /**< the other collision model */
00368     McdContact *contacts;           /**< array of contacts to be filled */
00369     int maxContactCount;            /**< size of array */
00370     int contactCount;               /**< number of contacts returned in array */
00371     int touch;                      /**< 1 if objects are in contact, 0 otherwise */
00372     McdReal normal[3];              /**< average normal of contacts returned */
00373 } McdIntersectResult;
00374 
00375 int
00376 McdIntersectHello( McdModelPair* );
00377 
00378 int
00379 McdIntersect( McdModelPair*, McdIntersectResult* );
00380 
00381 int
00382 McdIntersectGoodbye( McdModelPair* );
00383 
00384 /*----------------------------------------------------------------
00385  * McdLineSegIntersect 
00386  *---------------------------------------------------------------
00387  */
00388 
00389 /** Line segment query data. */
00390 typedef struct {
00391     McdReal     isctPoint[3];       /**< Intersection point */
00392     McdReal     normal[3];          /**< Model normal at intersection point */
00393     McdReal     distance;           /**< Distance from the first end point of line segment
00394                                       to the intersection point. */
00395     McdModelID  model;              /**< Collision model intersecting with the 
00396                                       line segment */
00397 } McdLineSegIntersectResult;
00398 
00399 /** Intersect a linesegment with a collision model */
00400 unsigned int
00401 McdLineSegIntersect( McdModelID cm, McdReal* inOrig, McdReal* inDest, 
00402                      McdLineSegIntersectResult *outOverlap);
00403 
00404 
00405 
00406 /*----------------------------------------------------------------
00407  * McdSpace 
00408  *---------------------------------------------------------------
00409  */
00410 
00411 /**
00412     McdSpace keeps track of where collision models are in 3D space.
00413     @see McdSpaceAxisSortCreate
00414 */
00415 typedef struct _McdSpace McdSpace; 
00416 
00417 /** References to MathEngine objects are 
00418 made using "ID" tokens instead of explicit pointers 
00419 */
00420 typedef McdSpace *McdSpaceID; 
00421 
00422 
00423 extern int McdXAxis;    /**< X-axis to be or'ed with McdYAxis and McdZAxis */
00424 extern int McdYAxis;    /**< Y-axis to be or'ed with McdXAxis and McdZAxis */
00425 extern int McdZAxis;    /**< Z-axis to be or'ed with McdXAxis and McdYAxis */
00426 extern int McdAllAxes;  /**< A constant equal to McdXAxis+McdYAxis+McdZAxis.*/
00427 
00428 McdSpaceID
00429 McdSpaceAxisSortCreate( int axes, int objectCount, int pairCount );
00430 
00431 void 
00432 McdSpaceDestroy( McdSpaceID s );
00433 
00434 void
00435 McdSpaceBuild( McdSpaceID s );
00436 
00437 void
00438 McdSpaceUpdate( McdSpaceID s );
00439 
00440 unsigned int
00441 McdSpaceInsertModel( McdSpaceID s, McdModelID cm );
00442 
00443 void
00444 McdSpaceSetUserData( McdSpaceID s, void *data );
00445 
00446 void *
00447 McdSpaceGetUserData( McdSpaceID s );
00448 
00449 int
00450 McdSpaceGetLineSegIntersections( McdSpaceID space, 
00451                                  McdReal* inOrig, McdReal* inDest,
00452                                  McdLineSegIntersectResult *outList, 
00453                                  int inMaxListSize); 
00454 
00455 
00456 /** Iterator for obtaining the "hello" pairs from McdSpace */
00457 typedef struct 
00458 { 
00459   void *d; /**< @internal */ 
00460 
00461 } McdSpaceHelloPairIterator;
00462 
00463 /** Iterator for obtaining the "staying" pairs from McdSpace */
00464 typedef struct 
00465 { 
00466   void *d; /**< @internal */ 
00467 
00468 } McdSpaceStayingPairIterator;
00469 
00470 /** Iterator for obtaining the "goodbye" pairs from McdSpace */
00471 typedef struct 
00472 { 
00473   void *d; /**< @internal */ 
00474 
00475 } McdSpaceGoodbyePairIterator;
00476 
00477 void
00478 McdSpaceHelloPairIteratorInit( McdSpaceID, McdSpaceHelloPairIterator* );
00479 
00480 void
00481 McdSpaceStayingPairIteratorInit( McdSpaceID, McdSpaceStayingPairIterator* );
00482 
00483 void
00484 McdSpaceGoodbyePairIteratorInit( McdSpaceID, McdSpaceGoodbyePairIterator* );
00485 
00486 int
00487 McdSpaceGetHelloPairs( McdSpaceID, McdSpaceHelloPairIterator*, 
00488                          McdModelPair**, int pairMaxCount );
00489 int
00490 McdSpaceGetStayingPairs( McdSpaceID, McdSpaceStayingPairIterator*, 
00491                          McdModelPair**, int pairMaxCount );
00492 int
00493 McdSpaceGetGoodbyePairs( McdSpaceID, McdSpaceGoodbyePairIterator*, 
00494                          McdModelPair**, int pairMaxCount );
00495  
00496 
00497 
00498 /* An iterator for pairs of McdModel's identified by McdSpace.
00499 
00500     McdSpace identifies three distinct states for pairs of McdModels:
00501     "hello", "staying" and "goodbye".
00502 
00503     The "hello" pairs are those
00504     pairs of McdModel's that McdSpace identifies as in close proximity to
00505     each other, but which where not in close proximity after the previous
00506     call to McdSpaceUpdate(). 
00507 
00508     If a pair is found to be in close proximity, and that pair was a
00509     "hello" pair after the previous call to
00510     McdSpaceUpdate(), it becomes a "staying" pair. Pairs that remain in close proximity
00511     remain in the "staying" state after each subsequent call to McdSpaceUpdate().
00512 
00513     When a pair is no longer in close proximity, but
00514     _was_ in close proximity after the previous call to McdSpaceUpdate(),
00515     then it is identified as a "goodbye" pair. 
00516 
00517     When a pair is not in close
00518     proximity, and was not in close proximity after the previous call to
00519     McdSpaceUpdate(), then it is ignored by McdSpace.
00520 
00521     @see McdSpaceUpdate
00522     @see McdSpaceGetHelloPairs
00523     @see McdSpaceGetStayingPairs
00524     @see McdSpaceGetGoodbyePairs
00525     @see McdSpaceGetHelloPairIterator
00526     @see McdSpaceGetStayingPairIterator
00527     @see McdSpaceGetGoodbyePairIterator
00528     @see McdModelPair
00529 */
00530 
00531 /** @internal */
00532 typedef struct 
00533 { 
00534   void *m_h; /**< @internal */
00535   void *m_s; /**< @internal */
00536   void *m_g; /**< @internal */
00537 
00538 } McdSpacePairIterator;
00539 
00540 /** @internal */
00541 void
00542 McdSpacePairIteratorInit( McdSpaceID, McdSpacePairIterator* );
00543 
00544 /** @internal */
00545 McdBool
00546 McdSpaceGetPairs( McdSpaceID, McdSpacePairIterator*, McdModelPairArray* );
00547 
00548 
00549 /*----------------------------------------------------------------
00550  * McdPairHandler
00551  *---------------------------------------------------------------
00552  */
00553 
00554 /** @internal */
00555 void
00556 McdPairHandlerDataPoolSetSize( int size );
00557 
00558 void
00559 McdPairHandlerDataPoolSetIncrement( int increment );
00560 
00561 void
00562 McdPairHandlerSetSpaceMaxCount( int count );
00563 
00564 /** @internal */
00565 int
00566 McdPairHandlerGetNewResponseID( );
00567 
00568 /** @internal */
00569 int
00570 McdPairHandlerGetDefaultResponseID( );
00571 
00572 /** @internal */
00573 void
00574 McdPairHandlerSetResponseIDMaxCount( int count );
00575 
00576 /** @internal */
00577 int
00578 McdPairHandlerGetResponseIDMaxCount( );
00579 
00580 void
00581 McdPairHandlerRegisterSpace( McdSpaceID s );
00582 
00583 void
00584 McdPairHandlerUnregisterSpace( McdSpaceID s );
00585 
00586 void
00587 McdPairHandlerUpdate( );
00588 
00589 
00590 /*---------------------------------------------------------------
00591  * McdIntersect
00592  *---------------------------------------------------------------
00593  */
00594 
00595 void
00596 McdIntersectSetContactBufferSize( int count );
00597 
00598 int
00599 McdIntersectGetContactBufferSize( );
00600 
00601 int
00602 McdIntersectGetNewRequestID();
00603 
00604 int
00605 McdIntersectGetDefaultRequestID();
00606 
00607 void
00608 McdIntersectSetRequestID( McdModelID cm, int requestID );
00609 
00610 int
00611 McdIntersectGetRequestID( McdModelID cm );
00612 
00613 void
00614 McdIntersectSetRequestIDMaxCount( int count );
00615 
00616 int
00617 McdIntersectGetRequestIDMaxCount( );
00618 
00619 void
00620 McdIntersectRequestSetContactMaxCount( int requestID1, int requestID2, int count );
00621 
00622 int
00623 McdIntersectRequestGetContactMaxCount( int requestID1, int requestID2 );
00624 
00625 void
00626 McdIntersectSetFaceNormalsFirst( int requestID1, int requestID2,
00627                                   unsigned int faceNormalsFirst );
00628 
00629 unsigned int
00630 McdIntersectGetFaceNormalsFirst( int requestID1, int requestID2 );
00631 
00632    
00633 #ifdef __cplusplus
00634 } /* extern "C" */
00635 #endif
00636 
00637 
00638 
00639 #endif /* #ifndef MCDFRAME_H */

MathEngine Collision Toolkit - Version 0.0.5 Alpha - Reference Manual generated using doxygen at Wed Oct 11 00:34:41 2000

Copyright MathEngine PLC 2000, all rights reserved.