Go to the documentation of this file.00001 #ifndef BT_CONTACT_H_INCLUDED
00002 #define BT_CONTACT_H_INCLUDED
00003
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "LinearMath/btTransform.h"
00028 #include "LinearMath/btAlignedObjectArray.h"
00029 #include "btTriangleShapeEx.h"
00030
00031
00032
00036 #define NORMAL_CONTACT_AVERAGE 1
00037
00038 #define CONTACT_DIFF_EPSILON 0.00001f
00039
00042 class GIM_CONTACT
00043 {
00044 public:
00045 btVector3 m_point;
00046 btVector3 m_normal;
00047 btScalar m_depth;
00048 btScalar m_distance;
00049 int m_feature1;
00050 int m_feature2;
00051 public:
00052 GIM_CONTACT()
00053 {
00054 }
00055
00056 GIM_CONTACT(const GIM_CONTACT & contact):
00057 m_point(contact.m_point),
00058 m_normal(contact.m_normal),
00059 m_depth(contact.m_depth),
00060 m_feature1(contact.m_feature1),
00061 m_feature2(contact.m_feature2)
00062 {
00063 }
00064
00065 GIM_CONTACT(const btVector3 &point,const btVector3 & normal,
00066 btScalar depth, int feature1, int feature2):
00067 m_point(point),
00068 m_normal(normal),
00069 m_depth(depth),
00070 m_feature1(feature1),
00071 m_feature2(feature2)
00072 {
00073 }
00074
00076 SIMD_FORCE_INLINE unsigned int calc_key_contact() const
00077 {
00078 int _coords[] = {
00079 (int)(m_point[0]*1000.0f+1.0f),
00080 (int)(m_point[1]*1333.0f),
00081 (int)(m_point[2]*2133.0f+3.0f)};
00082 unsigned int _hash=0;
00083 unsigned int *_uitmp = (unsigned int *)(&_coords[0]);
00084 _hash = *_uitmp;
00085 _uitmp++;
00086 _hash += (*_uitmp)<<4;
00087 _uitmp++;
00088 _hash += (*_uitmp)<<8;
00089 return _hash;
00090 }
00091
00092 SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,int normal_count)
00093 {
00094 btVector3 vec_sum(m_normal);
00095 for(int i=0;i<normal_count;i++)
00096 {
00097 vec_sum += normals[i];
00098 }
00099
00100 btScalar vec_sum_len = vec_sum.length2();
00101 if(vec_sum_len <CONTACT_DIFF_EPSILON) return;
00102
00103
00104
00105 m_normal = vec_sum/btSqrt(vec_sum_len);
00106 }
00107
00108 };
00109
00110
00111 class btContactArray:public btAlignedObjectArray<GIM_CONTACT>
00112 {
00113 public:
00114 btContactArray()
00115 {
00116 reserve(64);
00117 }
00118
00119 SIMD_FORCE_INLINE void push_contact(
00120 const btVector3 &point,const btVector3 & normal,
00121 btScalar depth, int feature1, int feature2)
00122 {
00123 push_back( GIM_CONTACT(point,normal,depth,feature1,feature2) );
00124 }
00125
00126 SIMD_FORCE_INLINE void push_triangle_contacts(
00127 const GIM_TRIANGLE_CONTACT & tricontact,
00128 int feature1,int feature2)
00129 {
00130 for(int i = 0;i<tricontact.m_point_count ;i++ )
00131 {
00132 push_contact(
00133 tricontact.m_points[i],
00134 tricontact.m_separating_normal,
00135 tricontact.m_penetration_depth,feature1,feature2);
00136 }
00137 }
00138
00139 void merge_contacts(const btContactArray & contacts, bool normal_contact_average = true);
00140
00141 void merge_contacts_unique(const btContactArray & contacts);
00142 };
00143
00144
00145 #endif // GIM_CONTACT_H_INCLUDED