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

Bullet Collision Detection & Physics Library

btTriangleShapeEx.h
Go to the documentation of this file.
1
4/*
5This source file is part of GIMPACT Library.
6
7For the latest info, see http://gimpact.sourceforge.net/
8
9Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
10email: projectileman@yahoo.com
11
12
13This software is provided 'as-is', without any express or implied warranty.
14In no event will the authors be held liable for any damages arising from the use of this software.
15Permission is granted to anyone to use this software for any purpose,
16including commercial applications, and to alter it and redistribute it freely,
17subject to the following restrictions:
18
191. 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.
202. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
213. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef GIMPACT_TRIANGLE_SHAPE_EX_H
25#define GIMPACT_TRIANGLE_SHAPE_EX_H
26
27#include "BulletCollision/CollisionShapes/btCollisionShape.h"
28#include "BulletCollision/CollisionShapes/btTriangleShape.h"
29#include "btBoxCollision.h"
30#include "btClipPolygon.h"
31#include "btGeometryOperations.h"
32
33#define MAX_TRI_CLIPPING 16
34
36 struct GIM_TRIANGLE_CONTACT
37{
38 btScalar m_penetration_depth;
39 int m_point_count;
40 btVector4 m_separating_normal;
41 btVector3 m_points[MAX_TRI_CLIPPING];
42
43 SIMD_FORCE_INLINE void copy_from(const GIM_TRIANGLE_CONTACT& other)
44 {
45 m_penetration_depth = other.m_penetration_depth;
46 m_separating_normal = other.m_separating_normal;
47 m_point_count = other.m_point_count;
48 int i = m_point_count;
49 while (i--)
50 {
51 m_points[i] = other.m_points[i];
52 }
53 }
54
55 GIM_TRIANGLE_CONTACT()
56 {
57 }
58
59 GIM_TRIANGLE_CONTACT(const GIM_TRIANGLE_CONTACT& other)
60 {
61 copy_from(other);
62 }
63
65 void merge_points(const btVector4& plane,
66 btScalar margin, const btVector3* points, int point_count);
67};
68
69 class btPrimitiveTriangle
70{
71public:
72 btVector3 m_vertices[3];
73 btVector4 m_plane;
74 btScalar m_margin;
75 btScalar m_dummy;
76 btPrimitiveTriangle() : m_margin(0.01f)
77 {
78 }
79
80 SIMD_FORCE_INLINE void buildTriPlane()
81 {
82 btVector3 normal = (m_vertices[1] - m_vertices[0]).cross(m_vertices[2] - m_vertices[0]);
83 normal.normalize();
84 m_plane.setValue(normal[0], normal[1], normal[2], m_vertices[0].dot(normal));
85 }
86
88 bool overlap_test_conservative(const btPrimitiveTriangle& other);
89
91
94 SIMD_FORCE_INLINE void get_edge_plane(int edge_index, btVector4& plane) const
95 {
96 const btVector3& e0 = m_vertices[edge_index];
97 const btVector3& e1 = m_vertices[(edge_index + 1) % 3];
98 bt_edge_plane(e0, e1, m_plane, plane);
99 }
100
101 void applyTransform(const btTransform& t)
102 {
103 m_vertices[0] = t(m_vertices[0]);
104 m_vertices[1] = t(m_vertices[1]);
105 m_vertices[2] = t(m_vertices[2]);
106 }
107
109
113 int clip_triangle(btPrimitiveTriangle& other, btVector3* clipped_points);
114
116
119 bool find_triangle_collision_clip_method(btPrimitiveTriangle& other, GIM_TRIANGLE_CONTACT& contacts);
120};
121
123
126 class btTriangleShapeEx : public btTriangleShape
127{
128public:
129 btTriangleShapeEx() : btTriangleShape(btVector3(0, 0, 0), btVector3(0, 0, 0), btVector3(0, 0, 0))
130 {
131 }
132
133 btTriangleShapeEx(const btVector3& p0, const btVector3& p1, const btVector3& p2) : btTriangleShape(p0, p1, p2)
134 {
135 }
136
137 btTriangleShapeEx(const btTriangleShapeEx& other) : btTriangleShape(other.m_vertices1[0], other.m_vertices1[1], other.m_vertices1[2])
138 {
139 }
140
141 virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
142 {
143 btVector3 tv0 = t(m_vertices1[0]);
144 btVector3 tv1 = t(m_vertices1[1]);
145 btVector3 tv2 = t(m_vertices1[2]);
146
147 btAABB trianglebox(tv0, tv1, tv2, m_collisionMargin);
148 aabbMin = trianglebox.m_min;
149 aabbMax = trianglebox.m_max;
150 }
151
152 void applyTransform(const btTransform& t)
153 {
154 m_vertices1[0] = t(m_vertices1[0]);
155 m_vertices1[1] = t(m_vertices1[1]);
156 m_vertices1[2] = t(m_vertices1[2]);
157 }
158
159 SIMD_FORCE_INLINE void buildTriPlane(btVector4& plane) const
160 {
161 btVector3 normal = (m_vertices1[1] - m_vertices1[0]).cross(m_vertices1[2] - m_vertices1[0]);
162 normal.normalize();
163 plane.setValue(normal[0], normal[1], normal[2], m_vertices1[0].dot(normal));
164 }
165
166 bool overlap_test_conservative(const btTriangleShapeEx& other);
167};
168
169#endif //GIMPACT_TRIANGLE_MESH_SHAPE_H
btBoxCollision.h
btClipPolygon.h
btCollisionShape.h
btGeometryOperations.h
bt_edge_plane
void bt_edge_plane(const btVector3 &e1, const btVector3 &e2, const btVector3 &normal, btVector4 &plane)
Calc a plane from a triangle edge an a normal. plane is a vec4f.
Definition btGeometryOperations.h:36
dot
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
Definition btQuaternion.h:888
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
MAX_TRI_CLIPPING
#define MAX_TRI_CLIPPING
Definition btTriangleShapeEx.h:33
btTriangleShape.h
btAABB
Axis aligned box.
Definition btBoxCollision.h:216
btAABB::m_min
btVector3 m_min
Definition btBoxCollision.h:218
btAABB::m_max
btVector3 m_max
Definition btBoxCollision.h:219
btConvexInternalShape::m_collisionMargin
btScalar m_collisionMargin
Definition btConvexInternalShape.h:37
btPrimitiveTriangle
Definition btTriangleShapeEx.h:70
btPrimitiveTriangle::find_triangle_collision_clip_method
bool find_triangle_collision_clip_method(btPrimitiveTriangle &other, GIM_TRIANGLE_CONTACT &contacts)
Find collision using the clipping method.
Definition btTriangleShapeEx.cpp:120
btPrimitiveTriangle::m_vertices
btVector3 m_vertices[3]
Definition btTriangleShapeEx.h:72
btPrimitiveTriangle::btPrimitiveTriangle
btPrimitiveTriangle()
Definition btTriangleShapeEx.h:76
btPrimitiveTriangle::m_dummy
btScalar m_dummy
Definition btTriangleShapeEx.h:75
btPrimitiveTriangle::clip_triangle
int clip_triangle(btPrimitiveTriangle &other, btVector3 *clipped_points)
Clips the triangle against this.
Definition btTriangleShapeEx.cpp:87
btPrimitiveTriangle::buildTriPlane
void buildTriPlane()
Definition btTriangleShapeEx.h:80
btPrimitiveTriangle::get_edge_plane
void get_edge_plane(int edge_index, btVector4 &plane) const
Calcs the plane which is paralele to the edge and perpendicular to the triangle plane.
Definition btTriangleShapeEx.h:94
btPrimitiveTriangle::m_margin
btScalar m_margin
Definition btTriangleShapeEx.h:74
btPrimitiveTriangle::overlap_test_conservative
bool overlap_test_conservative(const btPrimitiveTriangle &other)
Test if triangles could collide.
Definition btTriangleShapeEx.cpp:63
btPrimitiveTriangle::applyTransform
void applyTransform(const btTransform &t)
Definition btTriangleShapeEx.h:101
btPrimitiveTriangle::m_plane
btVector4 m_plane
Definition btTriangleShapeEx.h:73
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
btTriangleShapeEx
Helper class for colliding Bullet Triangle Shapes.
Definition btTriangleShapeEx.h:127
btTriangleShapeEx::btTriangleShapeEx
btTriangleShapeEx()
Definition btTriangleShapeEx.h:129
btTriangleShapeEx::btTriangleShapeEx
btTriangleShapeEx(const btVector3 &p0, const btVector3 &p1, const btVector3 &p2)
Definition btTriangleShapeEx.h:133
btTriangleShapeEx::applyTransform
void applyTransform(const btTransform &t)
Definition btTriangleShapeEx.h:152
btTriangleShapeEx::overlap_test_conservative
bool overlap_test_conservative(const btTriangleShapeEx &other)
class btTriangleShapeEx: public btTriangleShape
Definition btTriangleShapeEx.cpp:175
btTriangleShapeEx::getAabb
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb's default implementation is brute force, expected derived classes to implement a fast dedicat...
Definition btTriangleShapeEx.h:141
btTriangleShapeEx::buildTriPlane
void buildTriPlane(btVector4 &plane) const
Definition btTriangleShapeEx.h:159
btTriangleShapeEx::btTriangleShapeEx
btTriangleShapeEx(const btTriangleShapeEx &other)
Definition btTriangleShapeEx.h:137
btTriangleShape::btTriangleShape
btTriangleShape()
Definition btTriangleShape.h:82
btTriangleShape::m_vertices1
btVector3 m_vertices1[3]
Definition btTriangleShape.h:28
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btVector3::normalize
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303
btVector4
Definition btVector3.h:1074
btVector4::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z, const btScalar &_w)
Set x,y,z and zero w.
Definition btVector3.h:1198
GIM_TRIANGLE_CONTACT
Structure for collision.
Definition btTriangleShapeEx.h:37
GIM_TRIANGLE_CONTACT::m_points
btVector3 m_points[MAX_TRI_CLIPPING]
Definition btTriangleShapeEx.h:41
GIM_TRIANGLE_CONTACT::m_penetration_depth
btScalar m_penetration_depth
Definition btTriangleShapeEx.h:38
GIM_TRIANGLE_CONTACT::copy_from
void copy_from(const GIM_TRIANGLE_CONTACT &other)
Definition btTriangleShapeEx.h:43
GIM_TRIANGLE_CONTACT::m_separating_normal
btVector4 m_separating_normal
Definition btTriangleShapeEx.h:40
GIM_TRIANGLE_CONTACT::GIM_TRIANGLE_CONTACT
GIM_TRIANGLE_CONTACT(const GIM_TRIANGLE_CONTACT &other)
Definition btTriangleShapeEx.h:59
GIM_TRIANGLE_CONTACT::merge_points
void merge_points(const btVector4 &plane, btScalar margin, const btVector3 *points, int point_count)
classify points that are closer
Definition btTriangleShapeEx.cpp:26
GIM_TRIANGLE_CONTACT::m_point_count
int m_point_count
Definition btTriangleShapeEx.h:39
GIM_TRIANGLE_CONTACT::GIM_TRIANGLE_CONTACT
GIM_TRIANGLE_CONTACT()
Definition btTriangleShapeEx.h:55