Bullet Collision Detection & Physics Library
btContactProcessingStructs.h
Go to the documentation of this file.
1 #ifndef BT_CONTACT_H_STRUCTS_INCLUDED
2 #define BT_CONTACT_H_STRUCTS_INCLUDED
3 
7 /*
8 This source file is part of GIMPACT Library.
9 
10 For the latest info, see http://gimpact.sourceforge.net/
11 
12 Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
13 email: projectileman@yahoo.com
14 
15 
16 This software is provided 'as-is', without any express or implied warranty.
17 In no event will the authors be held liable for any damages arising from the use of this software.
18 Permission is granted to anyone to use this software for any purpose,
19 including commercial applications, and to alter it and redistribute it freely,
20 subject to the following restrictions:
21 
22 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
23 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
24 3. This notice may not be removed or altered from any source distribution.
25 */
26 
27 #include "LinearMath/btTransform.h"
29 #include "btTriangleShapeEx.h"
30 
31 
35 #define NORMAL_CONTACT_AVERAGE 1
36 
37 #define CONTACT_DIFF_EPSILON 0.00001f
38 
42 {
43 public:
46  btScalar m_depth;//Positive value indicates interpenetration
47  btScalar m_distance;//Padding not for use
48  int m_feature1;//Face number
49  int m_feature2;//Face number
50 public:
52  {
53  }
54 
55  GIM_CONTACT(const GIM_CONTACT & contact):
56  m_point(contact.m_point),
57  m_normal(contact.m_normal),
58  m_depth(contact.m_depth),
59  m_feature1(contact.m_feature1),
60  m_feature2(contact.m_feature2)
61  {
62  }
63 
64  GIM_CONTACT(const btVector3 &point,const btVector3 & normal,
65  btScalar depth, int feature1, int feature2):
66  m_point(point),
67  m_normal(normal),
68  m_depth(depth),
69  m_feature1(feature1),
70  m_feature2(feature2)
71  {
72  }
73 
75  SIMD_FORCE_INLINE unsigned int calc_key_contact() const
76  {
77  int _coords[] = {
78  (int)(m_point[0]*1000.0f+1.0f),
79  (int)(m_point[1]*1333.0f),
80  (int)(m_point[2]*2133.0f+3.0f)};
81  unsigned int _hash=0;
82  unsigned int *_uitmp = (unsigned int *)(&_coords[0]);
83  _hash = *_uitmp;
84  _uitmp++;
85  _hash += (*_uitmp)<<4;
86  _uitmp++;
87  _hash += (*_uitmp)<<8;
88  return _hash;
89  }
90 
91  SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,int normal_count)
92  {
93  btVector3 vec_sum(m_normal);
94  for(int i=0;i<normal_count;i++)
95  {
96  vec_sum += normals[i];
97  }
98 
99  btScalar vec_sum_len = vec_sum.length2();
100  if(vec_sum_len <CONTACT_DIFF_EPSILON) return;
101 
102  //GIM_INV_SQRT(vec_sum_len,vec_sum_len); // 1/sqrt(vec_sum_len)
103 
104  m_normal = vec_sum/btSqrt(vec_sum_len);
105  }
106 
107 };
108 
109 #endif // BT_CONTACT_H_STRUCTS_INCLUDED
void interpolate_normals(btVector3 *normals, int normal_count)
btScalar btSqrt(btScalar y)
Definition: btScalar.h:444
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
unsigned int calc_key_contact() const
Calcs key for coord classification.
#define CONTACT_DIFF_EPSILON
GIM_CONTACT(const GIM_CONTACT &contact)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btScalar length2() const
Return the length of the vector squared.
Definition: btVector3.h:257
GIM_CONTACT(const btVector3 &point, const btVector3 &normal, btScalar depth, int feature1, int feature2)
The GIM_CONTACT is an internal GIMPACT structure, similar to btManifoldPoint.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292