Go to the documentation of this file.00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef GIMPACT_TRIANGLE_SHAPE_EX_H
00026 #define GIMPACT_TRIANGLE_SHAPE_EX_H
00027
00028 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
00029 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
00030 #include "btBoxCollision.h"
00031 #include "btClipPolygon.h"
00032 #include "btGeometryOperations.h"
00033
00034
00035 #define MAX_TRI_CLIPPING 16
00036
00038 struct GIM_TRIANGLE_CONTACT
00039 {
00040 btScalar m_penetration_depth;
00041 int m_point_count;
00042 btVector4 m_separating_normal;
00043 btVector3 m_points[MAX_TRI_CLIPPING];
00044
00045 SIMD_FORCE_INLINE void copy_from(const GIM_TRIANGLE_CONTACT& other)
00046 {
00047 m_penetration_depth = other.m_penetration_depth;
00048 m_separating_normal = other.m_separating_normal;
00049 m_point_count = other.m_point_count;
00050 int i = m_point_count;
00051 while(i--)
00052 {
00053 m_points[i] = other.m_points[i];
00054 }
00055 }
00056
00057 GIM_TRIANGLE_CONTACT()
00058 {
00059 }
00060
00061 GIM_TRIANGLE_CONTACT(const GIM_TRIANGLE_CONTACT& other)
00062 {
00063 copy_from(other);
00064 }
00065
00067 void merge_points(const btVector4 & plane,
00068 btScalar margin, const btVector3 * points, int point_count);
00069
00070 };
00071
00072
00073
00074 class btPrimitiveTriangle
00075 {
00076 public:
00077 btVector3 m_vertices[3];
00078 btVector4 m_plane;
00079 btScalar m_margin;
00080 btScalar m_dummy;
00081 btPrimitiveTriangle():m_margin(0.01f)
00082 {
00083
00084 }
00085
00086
00087 SIMD_FORCE_INLINE void buildTriPlane()
00088 {
00089 btVector3 normal = (m_vertices[1]-m_vertices[0]).cross(m_vertices[2]-m_vertices[0]);
00090 normal.normalize();
00091 m_plane.setValue(normal[0],normal[1],normal[2],m_vertices[0].dot(normal));
00092 }
00093
00095 bool overlap_test_conservative(const btPrimitiveTriangle& other);
00096
00098
00101 SIMD_FORCE_INLINE void get_edge_plane(int edge_index, btVector4 &plane) const
00102 {
00103 const btVector3 & e0 = m_vertices[edge_index];
00104 const btVector3 & e1 = m_vertices[(edge_index+1)%3];
00105 bt_edge_plane(e0,e1,m_plane,plane);
00106 }
00107
00108 void applyTransform(const btTransform& t)
00109 {
00110 m_vertices[0] = t(m_vertices[0]);
00111 m_vertices[1] = t(m_vertices[1]);
00112 m_vertices[2] = t(m_vertices[2]);
00113 }
00114
00116
00120 int clip_triangle(btPrimitiveTriangle & other, btVector3 * clipped_points );
00121
00123
00126 bool find_triangle_collision_clip_method(btPrimitiveTriangle & other, GIM_TRIANGLE_CONTACT & contacts);
00127 };
00128
00129
00130
00132
00135 class btTriangleShapeEx: public btTriangleShape
00136 {
00137 public:
00138
00139 btTriangleShapeEx():btTriangleShape(btVector3(0,0,0),btVector3(0,0,0),btVector3(0,0,0))
00140 {
00141 }
00142
00143 btTriangleShapeEx(const btVector3& p0,const btVector3& p1,const btVector3& p2): btTriangleShape(p0,p1,p2)
00144 {
00145 }
00146
00147 btTriangleShapeEx(const btTriangleShapeEx & other): btTriangleShape(other.m_vertices1[0],other.m_vertices1[1],other.m_vertices1[2])
00148 {
00149 }
00150
00151 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax)const
00152 {
00153 btVector3 tv0 = t(m_vertices1[0]);
00154 btVector3 tv1 = t(m_vertices1[1]);
00155 btVector3 tv2 = t(m_vertices1[2]);
00156
00157 btAABB trianglebox(tv0,tv1,tv2,m_collisionMargin);
00158 aabbMin = trianglebox.m_min;
00159 aabbMax = trianglebox.m_max;
00160 }
00161
00162 void applyTransform(const btTransform& t)
00163 {
00164 m_vertices1[0] = t(m_vertices1[0]);
00165 m_vertices1[1] = t(m_vertices1[1]);
00166 m_vertices1[2] = t(m_vertices1[2]);
00167 }
00168
00169 SIMD_FORCE_INLINE void buildTriPlane(btVector4 & plane) const
00170 {
00171 btVector3 normal = (m_vertices1[1]-m_vertices1[0]).cross(m_vertices1[2]-m_vertices1[0]);
00172 normal.normalize();
00173 plane.setValue(normal[0],normal[1],normal[2],m_vertices1[0].dot(normal));
00174 }
00175
00176 bool overlap_test_conservative(const btTriangleShapeEx& other);
00177 };
00178
00179
00180 #endif //GIMPACT_TRIANGLE_MESH_SHAPE_H