1#ifndef BT_BOX_COLLISION_H_INCLUDED
2#define BT_BOX_COLLISION_H_INCLUDED
30#define BT_SWAP_NUMBERS(a, b) \
37#define BT_MAX(a, b) (a < b ? b : a)
38#define BT_MIN(a, b) (a > b ? b : a)
40#define BT_GREATER(x, y) btFabs(x) > (y)
42#define BT_MAX3(a, b, c) BT_MAX(a, BT_MAX(b, c))
43#define BT_MIN3(a, b, c) BT_MIN(a, BT_MIN(b, c))
112#define TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, i_dir_0, i_dir_1, i_comp_0, i_comp_1) \
114 const btScalar dir0 = -edge[i_dir_0]; \
115 const btScalar dir1 = edge[i_dir_1]; \
116 btScalar pmin = pointa[i_comp_0] * dir0 + pointa[i_comp_1] * dir1; \
117 btScalar pmax = pointb[i_comp_0] * dir0 + pointb[i_comp_1] * dir1; \
120 BT_SWAP_NUMBERS(pmin, pmax); \
122 const btScalar abs_dir0 = absolute_edge[i_dir_0]; \
123 const btScalar abs_dir1 = absolute_edge[i_dir_1]; \
124 const btScalar rad = _extend[i_comp_0] * abs_dir0 + _extend[i_comp_1] * abs_dir1; \
125 if (pmin > rad || -rad > pmax) return false; \
128#define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend) \
130 TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, 2, 1, 1, 2); \
133#define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend) \
135 TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, 0, 2, 2, 0); \
138#define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend) \
140 TEST_CROSS_EDGE_BOX_MCR(edge, absolute_edge, pointa, pointb, _extend, 1, 0, 0, 1); \
168 for (i = 0; i < 3; i++)
170 for (
j = 0;
j < 3;
j++)
172 m_AR[i][
j] = 1e-6f +
btFabs(m_R1to0[i][
j]);
190 calc_absolute_matrix();
197 m_T1to0 = m_R1to0 * (-
trans0.getOrigin());
199 m_T1to0 += m_R1to0 *
trans1.getOrigin();
200 m_R1to0 *=
trans1.getBasis();
202 calc_absolute_matrix();
207 return point.
dot3(m_R1to0[0], m_R1to0[1], m_R1to0[2]) + m_T1to0;
211#define BOX_PLANE_EPSILON 0.000001f
295 m_min[0] = other.
m_min[0] - margin;
296 m_min[1] = other.
m_min[1] - margin;
297 m_min[2] = other.
m_min[2] - margin;
299 m_max[0] = other.
m_max[0] + margin;
300 m_max[1] = other.
m_max[1] + margin;
301 m_max[2] = other.
m_max[2] + margin;
304 template <
typename CLASS_POINT>
319 template <
typename CLASS_POINT>
344 btVector3 center = (m_max + m_min) * 0.5f;
347 center =
trans(center);
350 trans.getBasis().getRow(1).absolute(),
351 trans.getBasis().getRow(2).absolute());
360 btVector3 center = (m_max + m_min) * 0.5f;
363 center =
trans.transform(center);
366 trans.m_R1to0.getRow(1).absolute(),
367 trans.m_R1to0.getRow(2).absolute());
376 m_min[0] =
BT_MIN(m_min[0],
box.m_min[0]);
377 m_min[1] =
BT_MIN(m_min[1],
box.m_min[1]);
378 m_min[2] =
BT_MIN(m_min[2],
box.m_min[2]);
380 m_max[0] =
BT_MAX(m_max[0],
box.m_max[0]);
381 m_max[1] =
BT_MAX(m_max[1],
box.m_max[1]);
382 m_max[2] =
BT_MAX(m_max[2],
box.m_max[2]);
386 template <
typename CLASS_POINT>
389 m_min[0] =
BT_MIN(m_min[0], point[0]);
390 m_min[1] =
BT_MIN(m_min[1], point[1]);
391 m_min[2] =
BT_MIN(m_min[2], point[2]);
393 m_max[0] =
BT_MAX(m_max[0], point[0]);
394 m_max[1] =
BT_MAX(m_max[1], point[1]);
395 m_max[2] =
BT_MAX(m_max[2], point[2]);
401 center = (m_max + m_min) * 0.5f;
419 if (m_min[0] > other.
m_max[0] ||
420 m_max[0] < other.
m_min[0] ||
421 m_min[1] > other.
m_max[1] ||
422 m_max[1] < other.
m_min[1] ||
423 m_min[2] > other.
m_max[2] ||
424 m_max[2] < other.
m_min[2])
439 this->get_center_extend(center,
extents);
460 btVector3 center = (m_max + m_min) * 0.5f;
490 return has_collision(
tbox);
498 return has_collision(
tbox);
508 get_center_extend(
ca, ea);
516 for (i = 0; i < 3; i++)
523 for (i = 0; i < 3; i++)
532 int j,
m, n,
o, p,
q, r;
533 for (i = 0; i < 3; i++)
539 for (
j = 0;
j < 3;
j++)
571 this->get_center_extend(center,
extends);
#define TEST_CROSS_EDGE_BOX_X_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
#define TEST_CROSS_EDGE_BOX_Y_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
eBT_PLANE_INTERSECTION_TYPE
#define TEST_CROSS_EDGE_BOX_Z_AXIS_MCR(edge, absolute_edge, pointa, pointb, _extend)
btScalar bt_mat3_dot_col(const btMatrix3x3 &mat, const btVector3 &vec3, int colindex)
Returns the dot product between a vec3f and the col of a matrix.
bool btCompareTransformsEqual(const btTransform &t1, const btTransform &t2)
Compairison of transformation objects.
#define BOX_PLANE_EPSILON
const T & btMax(const T &a, const T &b)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
#define ATTRIBUTE_ALIGNED16(a)
btScalar btFabs(btScalar x)
#define SIMD_FORCE_INLINE
bool overlapping_trans_cache(const btAABB &box, const BT_BOX_BOX_TRANSFORM_CACHE &transcache, bool fulltest) const
transcache is the transformation cache from box to this AABB
bool overlapping_trans_conservative(const btAABB &box, btTransform &trans1_to_0) const
void find_intersection(const btAABB &other, btAABB &intersection) const
Finds the intersecting box between this box and the other.
void copy_with_margin(const btAABB &other, btScalar margin)
eBT_PLANE_INTERSECTION_TYPE plane_classify(const btVector4 &plane) const
void increment_margin(btScalar margin)
bool collide_ray(const btVector3 &vorigin, const btVector3 &vdir) const
Finds the Ray intersection parameter.
void merge(const btAABB &box)
Merges a Box.
bool overlapping_trans_conservative2(const btAABB &box, const BT_BOX_BOX_TRANSFORM_CACHE &trans1_to_0) const
void projection_interval(const btVector3 &direction, btScalar &vmin, btScalar &vmax) const
void merge_point(const CLASS_POINT &point)
Merges a point.
void appy_transform_trans_cache(const BT_BOX_BOX_TRANSFORM_CACHE &trans)
Apply a transform to an AABB.
bool collide_triangle_exact(const btVector3 &p1, const btVector3 &p2, const btVector3 &p3, const btVector4 &triangle_plane) const
test for a triangle, with edges
void calc_from_triangle(const CLASS_POINT &V1, const CLASS_POINT &V2, const CLASS_POINT &V3)
btAABB(const btAABB &other)
bool has_collision(const btAABB &other) const
void calc_from_triangle_margin(const CLASS_POINT &V1, const CLASS_POINT &V2, const CLASS_POINT &V3, btScalar margin)
void get_center_extend(btVector3 ¢er, btVector3 &extend) const
Gets the extend and center.
btAABB(const btAABB &other, btScalar margin)
void appy_transform(const btTransform &trans)
Apply a transform to an AABB.
btAABB(const btVector3 &V1, const btVector3 &V2, const btVector3 &V3)
btAABB(const btVector3 &V1, const btVector3 &V2, const btVector3 &V3, btScalar margin)
bool collide_plane(const btVector4 &plane) const
Simple test for planes.
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
btMatrix3x3 inverse() const
Return the inverse of the matrix.
const btVector3 & getRow(int i) const
Get a row of the matrix as a vector.
btVector3 can be used to represent 3D points and vectors.
btScalar dot(const btVector3 &v) const
Return the dot product.
btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const
btVector3 absolute() const
Return a vector with the absolute values of each element.