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

Bullet Collision Detection & Physics Library

gim_contact.h
Go to the documentation of this file.
1 #ifndef GIM_CONTACT_H_INCLUDED
2 #define GIM_CONTACT_H_INCLUDED
3
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 Najera. 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 (3) The zlib/libpng license that is included with this library in
26 the file GIMPACT-LICENSE-ZLIB.TXT.
27
28 This library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
31 GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
32
33 -----------------------------------------------------------------------------
34 */
35 #include "gim_geometry.h"
36 #include "gim_radixsort.h"
37 #include "gim_array.h"
38
39
43 #ifndef NORMAL_CONTACT_AVERAGE
44 #define NORMAL_CONTACT_AVERAGE 1
45 #endif
46
47 #ifndef CONTACT_DIFF_EPSILON
48 #define CONTACT_DIFF_EPSILON 0.00001f
49 #endif
50
51 #ifndef BT_CONTACT_H_STRUCTS_INCLUDED
52
58 class GIM_CONTACT
59 {
60 public:
61 btVector3 m_point;
62 btVector3 m_normal;
63 GREAL m_depth;//Positive value indicates interpenetration
64 GREAL m_distance;//Padding not for use
65 GUINT m_feature1;//Face number
66 GUINT m_feature2;//Face number
67 public:
68 GIM_CONTACT()
69 {
70 }
71
72 GIM_CONTACT(const GIM_CONTACT & contact):
73 m_point(contact.m_point),
74 m_normal(contact.m_normal),
75 m_depth(contact.m_depth),
76 m_feature1(contact.m_feature1),
77 m_feature2(contact.m_feature2)
78 {
79 m_point = contact.m_point;
80 m_normal = contact.m_normal;
81 m_depth = contact.m_depth;
82 m_feature1 = contact.m_feature1;
83 m_feature2 = contact.m_feature2;
84 }
85
86 GIM_CONTACT(const btVector3 &point,const btVector3 & normal,
87 GREAL depth, GUINT feature1, GUINT feature2):
88 m_point(point),
89 m_normal(normal),
90 m_depth(depth),
91 m_feature1(feature1),
92 m_feature2(feature2)
93 {
94 }
95
97 SIMD_FORCE_INLINE GUINT calc_key_contact() const
98 {
99 GINT _coords[] = {
100 (GINT)(m_point[0]*1000.0f+1.0f),
101 (GINT)(m_point[1]*1333.0f),
102 (GINT)(m_point[2]*2133.0f+3.0f)};
103 GUINT _hash=0;
104 GUINT *_uitmp = (GUINT *)(&_coords[0]);
105 _hash = *_uitmp;
106 _uitmp++;
107 _hash += (*_uitmp)<<4;
108 _uitmp++;
109 _hash += (*_uitmp)<<8;
110 return _hash;
111 }
112
113 SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,GUINT normal_count)
114 {
115 btVector3 vec_sum(m_normal);
116 for(GUINT i=0;i<normal_count;i++)
117 {
118 vec_sum += normals[i];
119 }
120
121 GREAL vec_sum_len = vec_sum.length2();
122 if(vec_sum_len <CONTACT_DIFF_EPSILON) return;
123
124 GIM_INV_SQRT(vec_sum_len,vec_sum_len); // 1/sqrt(vec_sum_len)
125
126 m_normal = vec_sum*vec_sum_len;
127 }
128
129 };
130
131 #endif
132
133 class gim_contact_array:public gim_array<GIM_CONTACT>
134 {
135 public:
136 gim_contact_array():gim_array<GIM_CONTACT>(64)
137 {
138 }
139
140 SIMD_FORCE_INLINE void push_contact(const btVector3 &point,const btVector3 & normal,
141 GREAL depth, GUINT feature1, GUINT feature2)
142 {
143 push_back_mem();
144 GIM_CONTACT & newele = back();
145 newele.m_point = point;
146 newele.m_normal = normal;
147 newele.m_depth = depth;
148 newele.m_feature1 = feature1;
149 newele.m_feature2 = feature2;
150 }
151
152 SIMD_FORCE_INLINE void push_triangle_contacts(
153 const GIM_TRIANGLE_CONTACT_DATA & tricontact,
154 GUINT feature1,GUINT feature2)
155 {
156 for(GUINT i = 0;i<tricontact.m_point_count ;i++ )
157 {
158 push_back_mem();
159 GIM_CONTACT & newele = back();
160 newele.m_point = tricontact.m_points[i];
161 newele.m_normal = tricontact.m_separating_normal;
162 newele.m_depth = tricontact.m_penetration_depth;
163 newele.m_feature1 = feature1;
164 newele.m_feature2 = feature2;
165 }
166 }
167
168 void merge_contacts(const gim_contact_array & contacts, bool normal_contact_average = true);
169 void merge_contacts_unique(const gim_contact_array & contacts);
170 };
171
172 #endif // GIM_CONTACT_H_INCLUDED
GIM_CONTACT::calc_key_contact
GUINT calc_key_contact() const
Calcs key for coord classification.
Definition: gim_contact.h:97
GIM_TRIANGLE_CONTACT_DATA::m_points
btVector3 m_points[MAX_TRI_CLIPPING]
Definition: gim_tri_collision.h:51
gim_geometry.h
GIM_CONTACT::m_normal
btVector3 m_normal
Definition: btContactProcessingStructs.h:45
GIM_CONTACT::m_depth
GREAL m_depth
Definition: gim_contact.h:63
GIM_INV_SQRT
#define GIM_INV_SQRT(va, isva)
Definition: gim_math.h:119
gim_array< GIM_CONTACT >::push_back_mem
void push_back_mem()
Simply increase the m_size, doesn&#39;t call the new element constructor.
Definition: gim_array.h:222
CONTACT_DIFF_EPSILON
#define CONTACT_DIFF_EPSILON
Definition: gim_contact.h:48
gim_contact_array::gim_contact_array
gim_contact_array()
Definition: gim_contact.h:136
btVector3::length2
btScalar length2() const
Return the length of the vector squared.
Definition: btVector3.h:257
gim_array< GIM_CONTACT >::back
GIM_CONTACT & back()
Definition: gim_array.h:198
gim_contact_array::push_contact
void push_contact(const btVector3 &point, const btVector3 &normal, GREAL depth, GUINT feature1, GUINT feature2)
Definition: gim_contact.h:140
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
gim_radixsort.h
GIM_CONTACT::m_depth
btScalar m_depth
Definition: btContactProcessingStructs.h:46
gim_contact_array::merge_contacts_unique
void merge_contacts_unique(const gim_contact_array &contacts)
Definition: gim_contact.cpp:116
GIM_CONTACT::interpolate_normals
void interpolate_normals(btVector3 *normals, GUINT normal_count)
Definition: gim_contact.h:113
GIM_CONTACT::GIM_CONTACT
GIM_CONTACT(const GIM_CONTACT &contact)
Definition: gim_contact.h:72
GREAL
#define GREAL
Definition: gim_math.h:39
GIM_CONTACT::m_feature2
int m_feature2
Definition: btContactProcessingStructs.h:49
GIM_TRIANGLE_CONTACT_DATA::m_point_count
GUINT m_point_count
Definition: gim_tri_collision.h:49
GIM_CONTACT::m_feature2
GUINT m_feature2
Definition: gim_contact.h:66
gim_contact_array::merge_contacts
void merge_contacts(const gim_contact_array &contacts, bool normal_contact_average=true)
Definition: gim_contact.cpp:35
GINT
#define GINT
Definition: gim_math.h:41
GIM_TRIANGLE_CONTACT_DATA::m_penetration_depth
GREAL m_penetration_depth
Definition: gim_tri_collision.h:48
gim_array
Very simple array container with fast access and simd memory.
Definition: gim_array.h:43
GIM_CONTACT::GIM_CONTACT
GIM_CONTACT()
Definition: gim_contact.h:68
gim_array.h
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
GIM_TRIANGLE_CONTACT_DATA
Structure for collision.
Definition: gim_tri_collision.h:46
GIM_CONTACT::m_distance
GREAL m_distance
Definition: gim_contact.h:64
GIM_CONTACT::m_point
btVector3 m_point
Definition: btContactProcessingStructs.h:44
gim_contact_array
Definition: gim_contact.h:133
GIM_CONTACT::m_feature1
GUINT m_feature1
Definition: gim_contact.h:65
GIM_CONTACT::GIM_CONTACT
GIM_CONTACT(const btVector3 &point, const btVector3 &normal, GREAL depth, GUINT feature1, GUINT feature2)
Definition: gim_contact.h:86
GUINT
#define GUINT
Definition: gim_math.h:42
GIM_TRIANGLE_CONTACT_DATA::m_separating_normal
btVector4 m_separating_normal
Definition: gim_tri_collision.h:50
GIM_CONTACT::m_feature1
int m_feature1
Definition: btContactProcessingStructs.h:48
GIM_CONTACT
The GIM_CONTACT is an internal GIMPACT structure, similar to btManifoldPoint.
Definition: btContactProcessingStructs.h:41
gim_contact_array::push_triangle_contacts
void push_triangle_contacts(const GIM_TRIANGLE_CONTACT_DATA &tricontact, GUINT feature1, GUINT feature2)
Definition: gim_contact.h:152