Blender V2.61 - r43446

btTriangleShapeEx.h

Go to the documentation of this file.
00001 
00004 /*
00005 This source file is part of GIMPACT Library.
00006 
00007 For the latest info, see http://gimpact.sourceforge.net/
00008 
00009 Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
00010 email: projectileman@yahoo.com
00011 
00012 
00013 This software is provided 'as-is', without any express or implied warranty.
00014 In no event will the authors be held liable for any damages arising from the use of this software.
00015 Permission is granted to anyone to use this software for any purpose,
00016 including commercial applications, and to alter it and redistribute it freely,
00017 subject to the following restrictions:
00018 
00019 1. 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.
00020 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00021 3. This notice may not be removed or altered from any source distribution.
00022 */
00023 
00024 
00025 #ifndef TRIANGLE_SHAPE_EX_H
00026 #define 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 //TRIANGLE_MESH_SHAPE_H