MathEngine
Home Page       Structures       File List       Functions and Macros      

MdtTypes.h

Go to the documentation of this file.
00001 #ifndef _MDTTYPES_H
00002 #define _MDTTYPES_H
00003 /*
00004   Copyright MathEngine PLC 2000
00005 
00006   $Name: t-release-0-0-5-msvcrt $:
00007 
00008   $Id: MdtTypes.h,v 1.37 2000/09/09 00:02:03 michaelc Exp $
00009 */
00010 
00011 /** @file
00012  * Declares all the high level data structures used by the
00013  * Mdt library.
00014  */
00015 
00016 typedef struct MdtConstraintHeader MdtConstraintHeader;
00017 
00018 typedef struct MdtWorld          MdtWorld;
00019 typedef struct MdtBody           MdtBody;
00020 typedef struct MdtContact        MdtContact;
00021 typedef struct MdtBSJoint        MdtBSJoint;
00022 typedef struct MdtHinge          MdtHinge;
00023 typedef struct MdtPrismatic      MdtPrismatic;
00024 typedef struct MdtCarWheel       MdtCarWheel;
00025 typedef struct MdtFixedPath      MdtFixedPath;
00026 typedef struct MdtFPFOJoint      MdtFPFOJoint;
00027 typedef struct MdtUniversal      MdtUniversal;
00028 typedef struct MdtLinear1        MdtLinear1;
00029 typedef struct MdtLinear2        MdtLinear2;
00030 typedef struct MdtBaseConstraint MdtBaseConstraint;
00031 
00032 typedef struct MdtCListNode      MdtCListNode;
00033 
00034 /** MdtWorld identifier */
00035 typedef MdtWorld                 *MdtWorldID;
00036 /** MdtBody identifier */
00037 typedef MdtBody                  *MdtBodyID;
00038 /** MdtContact identifier */
00039 typedef MdtContact               *MdtContactID;
00040 /** MdtBSJoint ball and socket joint identifier */
00041 typedef MdtBSJoint               *MdtBSJointID;
00042 /** MdtHinge identifier */
00043 typedef MdtHinge                 *MdtHingeID;
00044 /** MdtPrismatic identifier */
00045 typedef MdtPrismatic             *MdtPrismaticID;
00046 /** MdtCarWheel identifier */
00047 typedef MdtCarWheel              *MdtCarWheelID;
00048 /** MdtFixedPath identifier */
00049 typedef MdtFixedPath             *MdtFixedPathID;
00050 /** MdtFPFOJoint fixed path fixed orientation identifier */
00051 typedef MdtFPFOJoint             *MdtFPFOJointID;
00052 /** MdtUniversal identifier */
00053 typedef MdtUniversal             *MdtUniversalID;
00054 /** MdtLinear1 identifier */
00055 typedef MdtLinear1               *MdtLinear1ID;
00056 /** MdtLinear2 identifier */
00057 typedef MdtLinear2               *MdtLinear2ID;
00058 
00059 /**
00060  * Genereal MdtConstraint identifier.
00061  * Use appropriate 'Qua' function to convert a specific type of constraint
00062  * (eg. MdtContactID or MdtHingeID) to an MdtConstraintID.
00063  */
00064 typedef MdtBaseConstraint        *MdtConstraintID;
00065 
00066 /** MdtBclLimit joint limit identifier */
00067 typedef MdtBclLimit              *MdtLimitID;
00068 /** MdtBclSingleLimit joint stop identifier */
00069 typedef MdtBclSingleLimit        *MdtSingleLimitID;
00070 /** MdtBclContactParams contact parameters identifier */
00071 typedef MdtBclContactParams      *MdtContactParamsID;
00072 
00073 
00074 typedef union MdtConstraintUnion MdtConstraintUnion;
00075 
00076 /**
00077  * Dynamics Event Manager mode of operation.
00078  */
00079 
00080 typedef enum
00081 {
00082     /** Partition scene and AutoDisable objects. */
00083     MdtDEMModePartitionAutoDisable,
00084 
00085     /** Partition scene but dont AutoDisable objects. */
00086     MdtDEMModePartitionNoAutoDisable,
00087 
00088     /** 
00089      * Don't partition or AutoDisable objects. All bodies
00090      * are simulated regardless of whether they are enabled
00091      * or disabled. 
00092      */
00093     MdtDEMModeNoPartition       
00094 }
00095 MdtDEMMode;
00096 
00097 /**
00098  * Memory Pool Overflow Callback
00099  * If the memory pool is found to be too small when trying to solve
00100  * a system during MdtWorldStep, the user may specify a callback that
00101  * will be executed, allowing the user to change the size of the
00102  * pool. The first parameter is the current memory pool, the second is
00103  * the current pool size and the third is the size of the pool required
00104  * to solve the system. The callback should call MdtWorldSetMemoryPool
00105  * to change the memory pool to a sufficiantly large size, but should not
00106  * call any other Mdt functions.
00107  */
00108 typedef void
00109 (*MdtMemoryPoolOverflowCB)(MdtWorldID w, void *m, int current_size, int required_size);
00110 
00111 /*
00112    Data Structures
00113 */
00114 
00115 /**
00116  * Mdt Constraint Header.
00117  *
00118  * Contains data common to all constraints.
00119  */
00120 struct MdtConstraintHeader
00121 {
00122     /** The world the constraint is in. */
00123     MdtWorldID          world;
00124 
00125     /** Pointer to next constraint. */
00126     MdtBaseConstraint   *next;
00127     /** Address of the 'next' pointer in the previous constraint. */
00128     MdtBaseConstraint   **tome;
00129 
00130     /** User data. This will not be changed from with the toolkit*/
00131     void                *userData;
00132 
00133     /** The (up to) 4 constrained bodies. */
00134     MdtBody             *body[4];
00135 
00136     /**
00137      * Pointers to this constraints entries in its bodies
00138      * lists. This is kept so these references can be removed
00139      * when the constraint is Disabled.
00140      */
00141     MdtCListNode*        cNode[4];
00142 
00143     /** Set by the event manager during constraint graph traversal. */
00144     int                 flag;
00145 
00146     /*
00147       Output Applied Forces - READ ONLY!
00148     */
00149 
00150     /**
00151      * Force applied to each of the constraints bodies by this
00152      * constraint.
00153      */
00154     MeVector4           resultForce[3];
00155 
00156     /**
00157      * Torque applied to each of the constraints bodies by this constraint
00158      */
00159     MeVector4           resultTorque[3];
00160 };
00161 
00162 /**
00163  * World Struct contains simulation-wide parameters.
00164  *
00165  * vel_thresh, velrot_thresh, acc_thresh, accrot_thresh and alive_window
00166  * are used for determining when bodies are at rest. A body at rest is
00167  * not processed by the solver till reenabled by a force or collision
00168  * event. A body is disabled if it falls below all of the 4 threshhold
00169  * values.
00170 
00171  * force_thresh and torque_thresh are threshholds for waking up resting
00172  * bodies.  If the force on a body is more than the force that was
00173  * applied to it when it was disabled plus the force threshold, then the
00174  * body is awakened.
00175  */
00176 
00177 struct MdtWorld
00178 {
00179     /** Kea body list. */
00180     MdtBody             *bodyHead;
00181 
00182     /** Constraint list for all constraint types. */
00183     MdtBaseConstraint   *constraintHead;
00184 
00185     /** Kea memory - used during keaStep only. */
00186     void                *keaMemoryBase;
00187     /** Kea memory - above pointer shifted up to be quad-word aligned */
00188     void                *keaMemoryBaseAligned;
00189     /** Size of Kea memory. */
00190     int                 keaMemorySize;
00191     /** Size of aligned Kea memory. */
00192     int                 keaMemorySizeAligned;
00193     /** Optional callback in case Kea memory pool is too small */
00194     MdtMemoryPoolOverflowCB keaMemoryOverflowCallback;
00195 
00196     /**
00197      * Maximum amount of the kea memory pool used during simulation so
00198      * far.
00199      */
00200     int                 maxKeaMemoryUsed;
00201 
00202     /** Maximum number of bodies allowed in this world. */
00203     int                 maxBodies;
00204     /** Number of bodies in existence (enabled and disabled). */
00205     int                 nBodies;
00206     /** Total count of enabled bodies in the world*/
00207     int                 nEnabledBodies;
00208     /** Number of bodies simulated in the current partition. */
00209     int                 activeBodies;
00210 
00211     /** Pool of MdtBodies. */
00212     MdtBody             *bodyArray;
00213     /** Stack of pointers to free bodies. */
00214     MdtBody             **freeBodyStack;
00215     /** Indicates next pointer in stack. */
00216     int                 nextFreeBody;
00217     /** Contiguous array of keaBodies - passed into Kea. */
00218     MdtKeaBody          *keabodyArray;
00219     /** Contiguous array of keaTransformations - passed into Kea. */
00220     MdtKeaTransformation *keatmArray;
00221 
00222     /** Maximum number of constraints allowed in this world. */
00223     int                 maxConstraints;
00224     /** Total count of enabled constraints in the world. */
00225     int                 nEnabledConstraints;
00226 
00227     /** Pool of constraints. */
00228     MdtConstraintUnion  *constraintArray;
00229     /** Stack of pointers to free constraint structs. */
00230     MdtConstraintUnion  **freeConstraintStack;
00231     /** Integer indicating next pointer in stack. */
00232     int                 nextFreeConstraint;
00233 
00234     /** Pool of CListNodes, used for keeping a bodies list of constraints. */
00235     MdtCListNode         *cNodeArray;
00236     /** Stack of pointer to free CListNodes. */
00237     MdtCListNode         **freeCNodeStack;
00238     /** Indicates next pointer on stack. */
00239     int                  nextFreeCNode;
00240 
00241     /**
00242      * Structure filled in with low-level constraint information each
00243      * time step by MdtBcl functions and passed as input to Kea.
00244      * See MdtKea.h
00245      */
00246     MdtKeaConstraints   constraints;
00247 
00248     /*
00249       Partition Information.
00250 
00251       This is the outputted by the partitioner and used by the
00252       keaConstraint maker.
00253     */
00254 
00255     /**
00256      * Constraint pointers to be processed by Kea, grouped into
00257      * partitions.
00258      */
00259     MdtBaseConstraint   **partitionConstraints;
00260     /** Integers, the number of constraints in each partition. */
00261     int                 *partitionSizes;
00262     /** Number of partitions. */
00263     int                 nPartitions;
00264 
00265     /**
00266      * If set to 1 the data passed to Kea will be outputted using the
00267      * default handler for MeInfo.
00268      *
00269      * To log the output to disk redefine your own handler for MeInfo.
00270      */
00271     int                 logKeaSystem;
00272 
00273     /** Numerical tolerance used by matrix solver. */
00274     MeReal              epsilon;
00275     /** Relaxation rate. */
00276     MeReal              gamma;
00277 
00278     /** Gravity vector. */
00279     MeVector4           gravity;
00280 
00281     /** Dynamics Event Manager operation mode. */
00282     MdtDEMMode          demMode;
00283 
00284     /*
00285       Parameters for auto-disabling - disable body  it if it 
00286       falls below all of these.
00287     */
00288 
00289     /** Sum-squared velocity threshold. */
00290     MeReal              vel_thresh;
00291     /** Sum-squared rotational velocity threshold. */
00292     MeReal              velrot_thresh;
00293     /** Sum-squared acceleration threshold. */
00294     MeReal              acc_thresh;
00295     /** Sum-squared rotation acceleration threshold. */
00296     MeReal              accrot_thresh;
00297 
00298     /**
00299      * Minimum number of steps to keep an object alive for.
00300      *
00301      * This is needed to give an object enough time to gain
00302      * a minimum velocity after it has been awakened.
00303      */
00304     int                 alive_window;
00305 };
00306 
00307 
00308 /**
00309  * MdtBody represents a physical body in a world simulation.
00310  */
00311 struct MdtBody
00312 {
00313     /** Kea body data. */
00314     MdtKeaBody           keaBody;
00315 
00316     /** 4x4 transformation matrix */
00317     MdtKeaTransformation TM;
00318 
00319 
00320     /**
00321      * Linear Impulse accumulator.
00322      * Converted to force and added to force accumulator at step time
00323      */
00324     MeVector4 impulseLinear;
00325 
00326     /**
00327      * Angular Impulse accumulator.
00328      * Converted to torque and added to torque accumulator at step time
00329      */
00330     MeVector4 impulseAngular;
00331 
00332     /**
00333      * Flag to indicate an impulse has been added to this body this
00334      * time-step.
00335      */
00336     int impulseAdded;
00337 
00338     /** The world the body is in. */
00339     MdtWorldID          world;
00340 
00341     /** Next MdtBody. */
00342     MdtBody             *next;
00343     /** Address of the next pointer in the previous MdtBody. */
00344     MdtBody             **tome;
00345 
00346     /** User data. This will not be changed from within the toolkit */
00347     void                *userData;
00348     /** The user can optionally give the body a name. This is very useful
00349         when used in conjunction with the logging functions. */
00350     char                name[32];
00351 
00352     /** Index into the corresponding Kea body array. */
00353     int                 arrayId;
00354 
00355     /** Mass in kilogrammes. */
00356     MeReal              mass;
00357 
00358     /** Velocity damping: 0 for no damping. */
00359     MeReal              damping;
00360     /** Angular velocity damping: 0 for no damping. */
00361     MeReal              angularDamping;
00362 
00363     /** A body's constraints may include joints or contacts. */
00364     MdtCListNode        *constraintList;
00365 
00366     /**
00367      * Number of steps that a body has been enabled; -1 if object is
00368      * disabled.
00369      */
00370     int                 enabledTime;
00371 };
00372 
00373 /**
00374  * A 'null' empty constraint, containing only data common to all
00375  * constraints.
00376  */
00377 struct MdtBaseConstraint
00378 {
00379     /** common to all constraints */
00380     MdtConstraintHeader head;
00381 
00382     /** BCL constraint header. */
00383     MdtBclConstraintHeader bclH;
00384 };
00385 
00386 /**
00387  * Contact constraint.
00388  */
00389 struct MdtContact
00390 {
00391     /** common to all constraints */
00392     MdtConstraintHeader head;
00393 
00394     /** BCL contact structure. */
00395     MdtBclContact       bclContact;
00396 
00397     /**
00398      * Depending on the order that the bodies are set, the normal might
00399      * need to be inverted.
00400      */
00401     int                 switchNormal;
00402 
00403     /**
00404      * Used by collision to create a list of contacts associated with a
00405      * pair of bodies.
00406      */
00407     MdtContactID        nextContact;
00408 };
00409 
00410 /**
00411  * Ball and Socket joint constraint
00412  */
00413 struct MdtBSJoint
00414 {
00415     /** common to all constraints */
00416     MdtConstraintHeader head;
00417 
00418     /** BCL ball and socket structure. */
00419     MdtBclBSJoint       bclBSJoint;
00420 };
00421 
00422 /**
00423  * Hinge joint constraint.
00424  */
00425 struct MdtHinge
00426 {
00427     /** common to all constraints */
00428     MdtConstraintHeader head;
00429 
00430     /** BCL hinge structure. */
00431     MdtBclHinge         bclHinge;
00432 };
00433 
00434 /**
00435  * Prismatic joint constraint.
00436  */
00437 struct MdtPrismatic
00438 {
00439     /** common to all constraints */
00440     MdtConstraintHeader head;
00441 
00442     /** BCL prismatic structure. */
00443     MdtBclPrismatic     bclPrismatic;
00444 };
00445 
00446 /**
00447  * Wheel constraint.
00448  */
00449 struct MdtCarWheel
00450 {
00451     /** common to all constraints */
00452     MdtConstraintHeader head;
00453 
00454     /** BCL car wheel joint struct. */
00455     MdtBclCarWheel      bclCarWheel;
00456 };
00457 
00458 
00459 /**
00460  * Fixed Path Joint.
00461  */
00462 struct MdtFixedPath
00463 {
00464     /** common to all constraints */
00465     MdtConstraintHeader head;
00466 
00467     /** BCL fixed path joint structure. */
00468     MdtBclFixedPath     bclFixedPath;
00469 };
00470 
00471 /**
00472  * Fixed Path, Fixed Orientation Joint.
00473  */
00474 struct MdtFPFOJoint
00475 {
00476     /** common to all constraints */
00477     MdtConstraintHeader head;
00478 
00479     /** BCL fixed path fixed orientation structure. */
00480     MdtBclFPFOJoint     bclFPFOJoint;
00481 };
00482 
00483 /**
00484  * Universal Joint.
00485  */
00486 struct MdtUniversal
00487 {
00488     /** common to all constraints */
00489     MdtConstraintHeader head;
00490 
00491     /** BCL universal joint structure. */
00492     MdtBclUniversal     bclUniversal;
00493 };
00494 
00495 /**
00496  * Linear1 Joint.
00497  */
00498 struct MdtLinear1
00499 {
00500     /** common to all constraints */
00501     MdtConstraintHeader head;
00502 
00503     /** BCL linear 1 structure. */
00504     MdtBclLinear1       bclLinear1;
00505 };
00506 
00507 /**
00508  * Linear2 Joint.
00509  */
00510 struct MdtLinear2
00511 {
00512     /** common to all constraints */
00513     MdtConstraintHeader head;
00514 
00515     /** BCL linear 2 structure. */
00516     MdtBclLinear2       bclLinear2;
00517 };
00518 
00519 /**
00520  * An element used for keep each bodies linked list of constraints.
00521  */
00522 struct MdtCListNode
00523 {
00524     /** Pointer to specific constraint */
00525     MdtBaseConstraint   *constraint;
00526 
00527     /** Next CListNode  in linked list */
00528     MdtCListNode        *next;
00529 
00530     /** Pointer to the next pointer in the previous node */
00531     MdtCListNode        **tome;
00532 };
00533 
00534 /**
00535  * Union of all constraint types.
00536  * Used for determining maximum size of a constraint struct when
00537  * allocating pools on world creation.
00538  */
00539 union MdtConstraintUnion
00540 {
00541     MdtBaseConstraint   base;
00542     MdtContact          contact;
00543     MdtBSJoint          bsjoint;
00544     MdtHinge            hinge;
00545     MdtPrismatic        prism;
00546     MdtCarWheel         carwheel;
00547     MdtFixedPath        fpjoint;
00548     MdtFPFOJoint        fpfojoint;
00549     MdtUniversal        univjoint;
00550     MdtLinear1          linear1;
00551     MdtLinear2          linear2;
00552 };
00553 
00554 #endif

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

Copyright MathEngine PLC 2000, all rights reserved.