1 #ifndef GIM_TRI_COLLISION_H_INCLUDED 2 #define GIM_TRI_COLLISION_H_INCLUDED 39 #ifndef MAX_TRI_CLIPPING 40 #define MAX_TRI_CLIPPING 16 73 template <
typename DISTANCE_FUNC,
typename CLASS_PLANE>
78 m_penetration_depth = -1000.0f;
84 for (_k = 0; _k < point_count; _k++)
86 GREAL _dist = -distance_func(plane, points[_k]) + margin;
90 if (_dist > m_penetration_depth)
92 m_penetration_depth = _dist;
93 point_indices[0] = _k;
96 else if ((_dist +
G_EPSILON) >= m_penetration_depth)
106 m_points[_k] = points[point_indices[_k]];
114 m_separating_normal = plane;
132 return GIM_AABB(m_vertices[0], m_vertices[1], m_vertices[2], m_margin);
142 TRIANGLE_PLANE(m_vertices[0], m_vertices[1], m_vertices[2], plane);
148 m_vertices[0] = trans(m_vertices[0]);
149 m_vertices[1] = trans(m_vertices[1]);
150 m_vertices[2] = trans(m_vertices[2]);
155 const btVector3 &e0 = m_vertices[edge_index];
156 const btVector3 &e1 = m_vertices[(edge_index + 1) % 3];
175 btVector3 xaxis = m_vertices[1] - m_vertices[0];
180 xaxis = zaxis.
cross(xaxis);
183 triangle_transform.
setOrigin(m_vertices[0]);
191 bool collide_triangle_hard_test(
206 GIM_AABB boxu(m_vertices[0], m_vertices[1], m_vertices[2], m_margin);
211 return collide_triangle_hard_test(other, contact_data);
247 btVector3 _axe1 = m_vertices[1] - m_vertices[0];
248 btVector3 _axe2 = m_vertices[2] - m_vertices[0];
249 btVector3 _vecproj = point - m_vertices[0];
251 GUINT _i2 = (_i1 + 1) % 3;
254 u = (_vecproj[_i2] * _axe2[_i1] - _vecproj[_i1] * _axe2[_i2]) / (_axe1[_i2] * _axe2[_i1] - _axe1[_i1] * _axe2[_i2]);
255 v = (_vecproj[_i1] - u * _axe1[_i1]) / _axe2[_i1];
259 u = (_vecproj[_i1] * _axe2[_i2] - _vecproj[_i2] * _axe2[_i1]) / (_axe1[_i1] * _axe2[_i2] - _axe1[_i2] * _axe2[_i1]);
260 v = (_vecproj[_i2] - u * _axe1[_i2]) / _axe2[_i2];
295 this->get_edge_plane(0, tri_normal, edge_plane);
297 if (dist - m_margin > 0.0f)
return false;
299 this->get_edge_plane(1, tri_normal, edge_plane);
301 if (dist - m_margin > 0.0f)
return false;
303 this->get_edge_plane(2, tri_normal, edge_plane);
305 if (dist - m_margin > 0.0f)
return false;
317 btVector3 dif1 = m_vertices[1] - m_vertices[0];
318 btVector3 dif2 = m_vertices[2] - m_vertices[0];
320 faceplane[3] = m_vertices[0].
dot(faceplane);
324 if (res == 0)
return false;
325 if (!is_point_inside(pout, faceplane))
return false;
329 triangle_normal.
setValue(-faceplane[0], -faceplane[1], -faceplane[2]);
333 triangle_normal.
setValue(faceplane[0], faceplane[1], faceplane[2]);
349 btVector3 dif1 = m_vertices[1] - m_vertices[0];
350 btVector3 dif2 = m_vertices[2] - m_vertices[0];
352 faceplane[3] = m_vertices[0].
dot(faceplane);
356 if (res != 1)
return false;
358 if (!is_point_inside(pout, faceplane))
return false;
360 triangle_normal.
setValue(faceplane[0], faceplane[1], faceplane[2]);
368 #endif // GIM_TRI_COLLISION_H_INCLUDED
GUINT LINE_PLANE_COLLISION(const CLASS_PLANE &plane, const CLASS_POINT &vDir, const CLASS_POINT &vPoint, CLASS_POINT &pout, T &tparam, T tmin, T tmax)
line collision
#define TRIANGLE_PLANE(v1, v2, v3, plane)
plane is a vec4f
#define EDGE_PLANE(e1, e2, n, plane)
Calc a plane from an edge an a normal. plane is a vec4f.
bool is_point_inside(const btVector3 &point, const btVector3 &tri_normal) const
is point in triangle beam?
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
void apply_transform(const btTransform &trans)
bool ray_collision_front_side(const btVector3 &vPoint, const btVector3 &vDir, btVector3 &pout, btVector3 &triangle_normal, GREAL &tparam, GREAL tmax=G_REAL_INFINITY)
one direccion ray collision
#define SIMD_FORCE_INLINE
#define MAT_SET_X(mat, vec3)
Get the triple(3) col of a transform matrix.
bool get_uv_parameters(const btVector3 &point, const btVector3 &tri_plane, GREAL &u, GREAL &v) const
bool has_collision(const GIM_AABB &other) const
This function calcs the distance from a 3D plane.
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
btScalar dot(const btVector3 &v) const
Return the dot product.
Class for colliding triangles.
#define MAT_SET_Y(mat, vec3)
Get the triple(3) col of a transform matrix.
void get_plane(btVector4 &plane) const
btVector3 can be used to represent 3D points and vectors.
void get_edge_plane(GUINT edge_index, const btVector3 &triangle_normal, btVector4 &plane) const
bool collide_triangle(const GIM_TRIANGLE &other, GIM_TRIANGLE_CONTACT_DATA &contact_data) const
Test boxes before doing hard test.
#define DISTANCE_PLANE_POINT(plane, point)
void get_triangle_transform(btTransform &triangle_transform) const
Gets the relative transformation of this triangle.
#define VEC_CROSS(c, a, b)
Vector cross.
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
bool ray_collision(const btVector3 &vPoint, const btVector3 &vDir, btVector3 &pout, btVector3 &triangle_normal, GREAL &tparam, GREAL tmax=G_REAL_INFINITY)
Bidireccional ray collision.
#define MAT_SET_Z(mat, vec3)
Get the triple(3) col of a transform matrix.
#define TRIANGLE_NORMAL(v1, v2, v3, n)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
#define VEC_NORMALIZE(a)
Vector length.
void get_normal(btVector3 &normal) const
btScalar btFabs(btScalar x)