1 #ifndef GIM_TRI_COLLISION_H_INCLUDED
2 #define GIM_TRI_COLLISION_H_INCLUDED
42 #define MAX_TRI_CLIPPING 16
77 template<
typename DISTANCE_FUNC,
typename CLASS_PLANE>
88 for(_k=0;_k<point_count;_k++)
90 GREAL _dist = -distance_func(plane,points[_k]) + margin;
97 point_indices[0] = _k;
110 m_points[_k] = points[point_indices[_k]];
184 xaxis = zaxis.
cross(xaxis);
187 triangle_transform.
setOrigin(m_vertices[0]);
253 btVector3 _axe2 = m_vertices[2]-m_vertices[0];
254 btVector3 _vecproj = point - m_vertices[0];
256 GUINT _i2 = (_i1+1)%3;
259 u = (_vecproj[_i2]*_axe2[_i1] - _vecproj[_i1]*_axe2[_i2]) /(_axe1[_i2]*_axe2[_i1] - _axe1[_i1]*_axe2[_i2]);
260 v = (_vecproj[_i1] - u*_axe1[_i1])/_axe2[_i1];
264 u = (_vecproj[_i1]*_axe2[_i2] - _vecproj[_i2]*_axe2[_i1]) /(_axe1[_i1]*_axe2[_i2] - _axe1[_i2]*_axe2[_i1]);
265 v = (_vecproj[_i2] - u*_axe1[_i2])/_axe2[_i2];
302 if(dist-
m_margin>0.0f)
return false;
306 if(dist-
m_margin>0.0f)
return false;
310 if(dist-
m_margin>0.0f)
return false;
324 btVector3 dif2 = m_vertices[2] - m_vertices[0];
326 faceplane[3] = m_vertices[0].
dot(faceplane);
330 if(res == 0)
return false;
335 triangle_normal.
setValue(-faceplane[0],-faceplane[1],-faceplane[2]);
339 triangle_normal.
setValue(faceplane[0],faceplane[1],faceplane[2]);
357 btVector3 dif2 = m_vertices[2] - m_vertices[0];
359 faceplane[3] = m_vertices[0].
dot(faceplane);
363 if(res != 1)
return false;
367 triangle_normal.
setValue(faceplane[0],faceplane[1],faceplane[2]);
379 #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.
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
float dist(const Point3 &pnt0, const Point3 &pnt1)
void apply_transform(const btTransform &trans)
bool collide_triangle_hard_test(const GIM_TRIANGLE &other, GIM_TRIANGLE_CONTACT_DATA &contact_data) const
Test triangles by finding separating axis.
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
bool has_collision(const GIM_AABB &other) const
#define SIMD_FORCE_INLINE
#define MAT_SET_X(mat, vec3)
Get the triple(3) col of a transform matrix.
void get_edge_plane(GUINT edge_index, const btVector3 &triangle_normal, btVector4 &plane) const
btScalar dot(const btVector3 &v) const
Return the dot product.
void get_plane(btVector4 &plane) const
This function calcs the distance from a 3D plane.
void get_normal(btVector3 &normal) const
bool is_point_inside(const btVector3 &point, const btVector3 &tri_normal) const
is point in triangle beam?
bool collide_triangle(const GIM_TRIANGLE &other, GIM_TRIANGLE_CONTACT_DATA &contact_data) const
Test boxes before doing hard test.
Class for colliding triangles.
#define MAT_SET_Y(mat, vec3)
Get the triple(3) col of a transform matrix.
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
btVector3 can be used to represent 3D points and vectors.
#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.
bool get_uv_parameters(const btVector3 &point, const btVector3 &tri_plane, GREAL &u, GREAL &v) const
#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.
btScalar btFabs(btScalar x)