#ifndef COLLDETECTH #define COLLDETECTH #include #include #include #include #include #define STRLEN 20 /* max length for strings */ #define ORDER 512 /* 2^M where M is the order of an object's matrix */ #define M 9 /* M the order of an object's SEADS matrix */ #define ETA 0.00001 /* floating point error tolerance */ #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) #define SQR(a) ((a) * (a)) typedef double Real; /* specify precision here - float or double */ typedef enum {False, True} Boolean; typedef enum {Cpoint, Cline, Carea} ContactType; typedef enum {Polygonal} ObjectType; /* in future may support other types */ typedef enum {Intersection, Contact, Nothing} Status; typedef unsigned long Ulong; typedef Boolean (*ChangeTrans)(Real, void *); /* pointer to function that */ /* is used to update */ /* Transforms */ typedef struct { /* collision interest matrix definition */ Ulong numObjs; Ulong rowStep; int bitsPerLong; Ulong *matrix; } CollIntMat; typedef struct { Real i, j, k; } Tupple; typedef struct { int total; Tupple *v; } TuppleArray; typedef struct { Tupple dir; Tupple origin; } Ray; typedef struct pnode { int *vertices; /* array of indices into vertex list of object */ int *vertNorms; /* array of indices into vertex normal list of object */ int numVertices; /* number of vertices */ Real d; /* ax + by + cz = d */ Tupple normal; /* nominal normal of plane containing polygon */ int i1, i2; /* ray intersect stuff */ } PolyNode; typedef struct { int total; PolyNode *p; } PolyNodeArray; /* Have used the name from ARTS paper */ typedef struct { /* for lack of a better name */ int dimi, dimj, dimk; /* the dimensions of the SEADS matrix */ Tupple voxSizes; /* the side lengths of a voxel */ struct { int total; /* number of polygons */ int *a; /* array of polygon numbers */ } matrix[ORDER]; /* the 3D matrix */ } SEADS; typedef struct { /* transforms are 4 x 4 matrices, the last row */ Real m[3][4]; /* is implicit [ 0 0 0 1 ] */ } Transform; typedef struct onode { char name[STRLEN]; /* name of object (optional) */ ObjectType type; /* type of object */ unsigned long id; /* unique id of object */ Boolean valid; /* some objects need to be ignored */ TuppleArray va; /* array of vertices */ TuppleArray vn; /* array of vertex normals */ PolyNodeArray polys; /* array of polygons */ Tupple min, max; /* minimum and maximum co-ords of object */ Tupple gmin, gmax; /* bounding box in global frame, changes with t */ SEADS *seads; /* pointer to the object's SEADS */ Transform *loc2glob; /* matrix to transform from local frame to global */ Transform *glob2loc; /* matrix to transform from global to local frame */ ChangeTrans ctrans; /* pointer to function that is used to find the * loc2glob transform at a given time */ void *info; /* pointer to info that gets passed to ctrans */ struct onode *next; /* pointer to next ObjNode */ } ObjNode; typedef struct { ObjNode *objects; /* list of objects */ CollIntMat *cim; /* collision interest matrix */ void *ptr; /* unused pointer */ } ObjDB; typedef struct cnode { unsigned long objs[2]; /* IDs of the two objects involved */ int polys[2]; /* polygons (1 from each object) involved */ Status statusType; /* Intersection or Contact */ ContactType type; /* Point, Line, or Area */ union { Tupple point; /* Value of point/line/area */ Tupple line[2]; TuppleArray area; } data; struct cnode *next; } ConNode; ConNode *collisionDetect(ObjDB, Status *, Real *); #endif