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
25#ifndef GIMPACT_TRIANGLE_SHAPE_EX_H
26#define GIMPACT_TRIANGLE_SHAPE_EX_H
27
30#include "btBoxCollision.h"
31#include "btClipPolygon.h"
33
34
35#define MAX_TRI_CLIPPING 16
36
39{
44
46 {
50 int i = m_point_count;
51 while(i--)
52 {
53 m_points[i] = other.m_points[i];
54 }
55 }
56
58 {
59 }
60
62 {
63 copy_from(other);
64 }
65
67 void merge_points(const btVector4 & plane,
68 btScalar margin, const btVector3 * points, int point_count);
69
70};
71
72
73
75{
76public:
82 {
83
84 }
85
86
88 {
89 btVector3 normal = (m_vertices[1]-m_vertices[0]).cross(m_vertices[2]-m_vertices[0]);
90 normal.normalize();
91 m_plane.setValue(normal[0],normal[1],normal[2],m_vertices[0].dot(normal));
92 }
93
96
98
101 SIMD_FORCE_INLINE void get_edge_plane(int edge_index, btVector4 &plane) const
102 {
103 const btVector3 & e0 = m_vertices[edge_index];
104 const btVector3 & e1 = m_vertices[(edge_index+1)%3];
105 bt_edge_plane(e0,e1,m_plane,plane);
106 }
107
109 {
110 m_vertices[0] = t(m_vertices[0]);
111 m_vertices[1] = t(m_vertices[1]);
112 m_vertices[2] = t(m_vertices[2]);
113 }
114
116
120 int clip_triangle(btPrimitiveTriangle & other, btVector3 * clipped_points );
121
123
127};
128
129
130
132
136{
137public:
138
140 {
141 }
142
143 btTriangleShapeEx(const btVector3& p0,const btVector3& p1,const btVector3& p2): btTriangleShape(p0,p1,p2)
144 {
145 }
146
148 {
149 }
150
151 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax)const
152 {
153 btVector3 tv0 = t(m_vertices1[0]);
154 btVector3 tv1 = t(m_vertices1[1]);
155 btVector3 tv2 = t(m_vertices1[2]);
156
157 btAABB trianglebox(tv0,tv1,tv2,m_collisionMargin);
158 aabbMin = trianglebox.m_min;
159 aabbMax = trianglebox.m_max;
160 }
161
163 {
164 m_vertices1[0] = t(m_vertices1[0]);
165 m_vertices1[1] = t(m_vertices1[1]);
166 m_vertices1[2] = t(m_vertices1[2]);
167 }
168
170 {
171 btVector3 normal = (m_vertices1[1]-m_vertices1[0]).cross(m_vertices1[2]-m_vertices1[0]);
172 normal.normalize();
173 plane.setValue(normal[0],normal[1],normal[2],m_vertices1[0].dot(normal));
174 }
175
177};
178
179
180#endif //GIMPACT_TRIANGLE_MESH_SHAPE_H
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.
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
Definition: btQuaternion.h:878
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
#define MAX_TRI_CLIPPING
Axis aligned box.
btVector3 m_min
btVector3 m_max
bool find_triangle_collision_clip_method(btPrimitiveTriangle &other, GIM_TRIANGLE_CONTACT &contacts)
Find collision using the clipping method.
int clip_triangle(btPrimitiveTriangle &other, btVector3 *clipped_points)
Clips the triangle against this.
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.
bool overlap_test_conservative(const btPrimitiveTriangle &other)
Test if triangles could collide.
void applyTransform(const btTransform &t)
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
Helper class for colliding Bullet Triangle Shapes.
btTriangleShapeEx(const btVector3 &p0, const btVector3 &p1, const btVector3 &p2)
void applyTransform(const btTransform &t)
bool overlap_test_conservative(const btTriangleShapeEx &other)
class btTriangleShapeEx: public btTriangleShape
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...
void buildTriPlane(btVector4 &plane) const
btTriangleShapeEx(const btTriangleShapeEx &other)
btVector3 m_vertices1[3]
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:309
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z, const btScalar &_w)
Set x,y,z and zero w.
Definition: btVector3.h:1225
Structure for collision.
btVector3 m_points[MAX_TRI_CLIPPING]
void copy_from(const GIM_TRIANGLE_CONTACT &other)
GIM_TRIANGLE_CONTACT(const GIM_TRIANGLE_CONTACT &other)
void merge_points(const btVector4 &plane, btScalar margin, const btVector3 *points, int point_count)
classify points that are closer