Bullet Collision Detection & Physics Library: btContactProcessing.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btContactProcessing.h
Go to the documentation of this file.
1 #ifndef BT_CONTACT_H_INCLUDED
2 #define BT_CONTACT_H_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"
28 #include "LinearMath/btAlignedObjectArray.h"
29 #include "btTriangleShapeEx.h"
30
31
32
36 #define NORMAL_CONTACT_AVERAGE 1
37
38 #define CONTACT_DIFF_EPSILON 0.00001f
39
42 class GIM_CONTACT
43 {
44 public:
45 btVector3 m_point;
46 btVector3 m_normal;
47 btScalar m_depth;//Positive value indicates interpenetration
48 btScalar m_distance;//Padding not for use
49 int m_feature1;//Face number
50 int m_feature2;//Face number
51 public:
52 GIM_CONTACT()
53 {
54 }
55
56 GIM_CONTACT(const GIM_CONTACT & contact):
57 m_point(contact.m_point),
58 m_normal(contact.m_normal),
59 m_depth(contact.m_depth),
60 m_feature1(contact.m_feature1),
61 m_feature2(contact.m_feature2)
62 {
63 }
64
65 GIM_CONTACT(const btVector3 &point,const btVector3 & normal,
66 btScalar depth, int feature1, int feature2):
67 m_point(point),
68 m_normal(normal),
69 m_depth(depth),
70 m_feature1(feature1),
71 m_feature2(feature2)
72 {
73 }
74
76 SIMD_FORCE_INLINE unsigned int calc_key_contact() const
77 {
78 int _coords[] = {
79 (int)(m_point[0]*1000.0f+1.0f),
80 (int)(m_point[1]*1333.0f),
81 (int)(m_point[2]*2133.0f+3.0f)};
82 unsigned int _hash=0;
83 unsigned int *_uitmp = (unsigned int *)(&_coords[0]);
84 _hash = *_uitmp;
85 _uitmp++;
86 _hash += (*_uitmp)<<4;
87 _uitmp++;
88 _hash += (*_uitmp)<<8;
89 return _hash;
90 }
91
92 SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,int normal_count)
93 {
94 btVector3 vec_sum(m_normal);
95 for(int i=0;i<normal_count;i++)
96 {
97 vec_sum += normals[i];
98 }
99
100 btScalar vec_sum_len = vec_sum.length2();
101 if(vec_sum_len <CONTACT_DIFF_EPSILON) return;
102
103 //GIM_INV_SQRT(vec_sum_len,vec_sum_len); // 1/sqrt(vec_sum_len)
104
105 m_normal = vec_sum/btSqrt(vec_sum_len);
106 }
107
108 };
109
110
111 class btContactArray:public btAlignedObjectArray<GIM_CONTACT>
112 {
113 public:
114 btContactArray()
115 {
116 reserve(64);
117 }
118
119 SIMD_FORCE_INLINE void push_contact(
120 const btVector3 &point,const btVector3 & normal,
121 btScalar depth, int feature1, int feature2)
122 {
123 push_back( GIM_CONTACT(point,normal,depth,feature1,feature2) );
124 }
125
126 SIMD_FORCE_INLINE void push_triangle_contacts(
127 const GIM_TRIANGLE_CONTACT & tricontact,
128 int feature1,int feature2)
129 {
130 for(int i = 0;i<tricontact.m_point_count ;i++ )
131 {
132 push_contact(
133 tricontact.m_points[i],
134 tricontact.m_separating_normal,
135 tricontact.m_penetration_depth,feature1,feature2);
136 }
137 }
138
139 void merge_contacts(const btContactArray & contacts, bool normal_contact_average = true);
140
141 void merge_contacts_unique(const btContactArray & contacts);
142 };
143
144
145 #endif // GIM_CONTACT_H_INCLUDED
GIM_CONTACT::interpolate_normals
void interpolate_normals(btVector3 *normals, int normal_count)
Definition: btContactProcessing.h:92
GIM_TRIANGLE_CONTACT::m_point_count
int m_point_count
Definition: btTriangleShapeEx.h:41
btContactArray
Definition: btContactProcessing.h:111
GIM_CONTACT::m_normal
btVector3 m_normal
Definition: btContactProcessing.h:46
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:53
btTriangleShapeEx.h
btContactArray::btContactArray
btContactArray()
Definition: btContactProcessing.h:114
btSqrt
btScalar btSqrt(btScalar y)
Definition: btScalar.h:418
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:63
GIM_CONTACT::calc_key_contact
unsigned int calc_key_contact() const
Calcs key for coord classification.
Definition: btContactProcessing.h:76
GIM_CONTACT::m_depth
btScalar m_depth
Definition: btContactProcessing.h:47
btTransform.h
GIM_CONTACT::m_distance
btScalar m_distance
Definition: btContactProcessing.h:48
GIM_CONTACT::GIM_CONTACT
GIM_CONTACT(const GIM_CONTACT &contact)
Definition: btContactProcessing.h:56
GIM_TRIANGLE_CONTACT::m_points
btVector3 m_points[MAX_TRI_CLIPPING]
Definition: btTriangleShapeEx.h:43
GIM_CONTACT::m_feature2
int m_feature2
Definition: btContactProcessing.h:50
btContactArray::push_triangle_contacts
void push_triangle_contacts(const GIM_TRIANGLE_CONTACT &tricontact, int feature1, int feature2)
Definition: btContactProcessing.h:126
btContactArray::push_contact
void push_contact(const btVector3 &point, const btVector3 &normal, btScalar depth, int feature1, int feature2)
Definition: btContactProcessing.h:119
GIM_CONTACT::GIM_CONTACT
GIM_CONTACT()
Definition: btContactProcessing.h:52
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btVector3::length2
btScalar length2() const
Return the length of the vector squared.
Definition: btVector3.h:257
CONTACT_DIFF_EPSILON
#define CONTACT_DIFF_EPSILON
Definition: btContactProcessing.h:38
GIM_CONTACT::m_point
btVector3 m_point
Definition: btContactProcessing.h:45
GIM_TRIANGLE_CONTACT
Structure for collision.
Definition: btTriangleShapeEx.h:38
GIM_CONTACT::GIM_CONTACT
GIM_CONTACT(const btVector3 &point, const btVector3 &normal, btScalar depth, int feature1, int feature2)
Definition: btContactProcessing.h:65
btAlignedObjectArray.h
GIM_CONTACT::m_feature1
int m_feature1
Definition: btContactProcessing.h:49
GIM_CONTACT
The GIM_CONTACT is an internal GIMPACT structure, similar to btManifoldPoint.
Definition: btContactProcessing.h:42
GIM_TRIANGLE_CONTACT::m_penetration_depth
btScalar m_penetration_depth
Definition: btTriangleShapeEx.h:40
GIM_TRIANGLE_CONTACT::m_separating_normal
btVector4 m_separating_normal
Definition: btTriangleShapeEx.h:42
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278