[216] | 1 | #ifndef GIM_CONTACT_H_INCLUDED |
---|
| 2 | #define GIM_CONTACT_H_INCLUDED |
---|
| 3 | |
---|
| 4 | /*! \file gim_contact.h |
---|
| 5 | \author Francisco León |
---|
| 6 | */ |
---|
| 7 | /* |
---|
| 8 | ----------------------------------------------------------------------------- |
---|
| 9 | This source file is part of GIMPACT Library. |
---|
| 10 | |
---|
| 11 | For the latest info, see http://gimpact.sourceforge.net/ |
---|
| 12 | |
---|
| 13 | Copyright (c) 2006 Francisco Leon. C.C. 80087371. |
---|
| 14 | email: projectileman@yahoo.com |
---|
| 15 | |
---|
| 16 | This library is free software; you can redistribute it and/or |
---|
| 17 | modify it under the terms of EITHER: |
---|
| 18 | (1) The GNU Lesser General Public License as published by the Free |
---|
| 19 | Software Foundation; either version 2.1 of the License, or (at |
---|
| 20 | your option) any later version. The text of the GNU Lesser |
---|
| 21 | General Public License is included with this library in the |
---|
| 22 | file GIMPACT-LICENSE-LGPL.TXT. |
---|
| 23 | (2) The BSD-style license that is included with this library in |
---|
| 24 | the file GIMPACT-LICENSE-BSD.TXT. |
---|
| 25 | |
---|
| 26 | This library is distributed in the hope that it will be useful, |
---|
| 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files |
---|
| 29 | GIMPACT-LICENSE-LGPL.TXT and GIMPACT-LICENSE-BSD.TXT for more details. |
---|
| 30 | |
---|
| 31 | ----------------------------------------------------------------------------- |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | #include "GIMPACT/gim_geometry.h" |
---|
| 36 | #include "GIMPACT/gim_radixsort.h" |
---|
| 37 | |
---|
| 38 | /*! \defgroup CONTACTS |
---|
| 39 | \brief |
---|
| 40 | Functions for managing and sorting contacts resulting from a collision query. |
---|
| 41 | <ul> |
---|
| 42 | <li> Contact lists must be create by calling \ref GIM_CREATE_CONTACT_LIST |
---|
| 43 | <li> After querys, contact lists must be destroy by calling \ref GIM_DYNARRAY_DESTROY |
---|
| 44 | <li> Contacts can be merge for avoid duplicate results by calling \ref gim_merge_contacts |
---|
| 45 | </ul> |
---|
| 46 | |
---|
| 47 | */ |
---|
| 48 | //! @{ |
---|
| 49 | /// Structure for collision results |
---|
| 50 | struct GIM_CONTACT |
---|
| 51 | { |
---|
| 52 | vec3f m_point; |
---|
| 53 | vec3f m_normal; |
---|
| 54 | GREAL m_depth;//Positive value indicates interpenetration |
---|
| 55 | void * m_handle1; |
---|
| 56 | void * m_handle2; |
---|
| 57 | GUINT m_feature1;//Face number |
---|
| 58 | GUINT m_feature2;//Face number |
---|
| 59 | }; |
---|
| 60 | //typedef struct _GIM_CONTACT GIM_CONTACT; |
---|
| 61 | |
---|
| 62 | #define CONTACT_DIFF_EPSILON 0.00001f |
---|
| 63 | |
---|
| 64 | #define GIM_CALC_KEY_CONTACT(pos,hash)\ |
---|
| 65 | {\ |
---|
| 66 | GINT _coords[] = {(GINT)(pos[0]*1000.0f+1.0f),(GINT)(pos[1]*1333.0f),(GINT)(pos[2]*2133.0f+3.0f)};\ |
---|
| 67 | GUINT _hash=0;\ |
---|
| 68 | GUINT *_uitmp = (GUINT *)(&_coords[0]);\ |
---|
| 69 | _hash = *_uitmp;\ |
---|
| 70 | _uitmp++;\ |
---|
| 71 | _hash += (*_uitmp)<<4;\ |
---|
| 72 | _uitmp++;\ |
---|
| 73 | _hash += (*_uitmp)<<8;\ |
---|
| 74 | hash = _hash;\ |
---|
| 75 | }\ |
---|
| 76 | |
---|
| 77 | ///Creates a contact list for queries |
---|
| 78 | #define GIM_CREATE_CONTACT_LIST(contact_array) GIM_DYNARRAY_CREATE(GIM_CONTACT,contact_array,100) |
---|
| 79 | |
---|
| 80 | #define GIM_PUSH_CONTACT(contact_array, point, normal, deep,handle1, handle2, feat1, feat2)\ |
---|
| 81 | {\ |
---|
| 82 | GIM_DYNARRAY_PUSH_EMPTY(GIM_CONTACT,contact_array);\ |
---|
| 83 | GIM_CONTACT * _last = GIM_DYNARRAY_POINTER_LAST(GIM_CONTACT,contact_array);\ |
---|
| 84 | VEC_COPY(_last->m_point,point);\ |
---|
| 85 | VEC_COPY(_last->m_normal,normal);\ |
---|
| 86 | _last->m_depth = deep;\ |
---|
| 87 | _last->m_handle1 = handle1;\ |
---|
| 88 | _last->m_handle2 = handle2;\ |
---|
| 89 | _last->m_feature1 = feat1;\ |
---|
| 90 | _last->m_feature2 = feat2;\ |
---|
| 91 | }\ |
---|
| 92 | |
---|
| 93 | ///Receive pointer to contacts |
---|
| 94 | #define GIM_COPY_CONTACTS(dest_contact, source_contact)\ |
---|
| 95 | {\ |
---|
| 96 | VEC_COPY(dest_contact->m_point,source_contact->m_point);\ |
---|
| 97 | VEC_COPY(dest_contact->m_normal,source_contact->m_normal);\ |
---|
| 98 | dest_contact->m_depth = source_contact->m_depth;\ |
---|
| 99 | dest_contact->m_handle1 = source_contact->m_handle1;\ |
---|
| 100 | dest_contact->m_handle2 = source_contact->m_handle2;\ |
---|
| 101 | dest_contact->m_feature1 = source_contact->m_feature1;\ |
---|
| 102 | dest_contact->m_feature2 = source_contact->m_feature2;\ |
---|
| 103 | }\ |
---|
| 104 | |
---|
| 105 | //! Merges duplicate contacts with minimum depth criterion |
---|
| 106 | void gim_merge_contacts(GDYNAMIC_ARRAY * source_contacts, |
---|
| 107 | GDYNAMIC_ARRAY * dest_contacts); |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | //! Merges to an unique contact |
---|
| 111 | void gim_merge_contacts_unique(GDYNAMIC_ARRAY * source_contacts, |
---|
| 112 | GDYNAMIC_ARRAY * dest_contacts); |
---|
| 113 | |
---|
| 114 | //! @} |
---|
| 115 | #endif // GIM_CONTACT_H_INCLUDED |
---|