2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 #ifndef BT_OBB_TRIANGLE_MINKOWSKI_H
17 #define BT_OBB_TRIANGLE_MINKOWSKI_H
19 #include "btConvexShape.h"
20 #include "btBoxShape.h"
22 ATTRIBUTE_ALIGNED16(class)
23 btTriangleShape : public btPolyhedralConvexShape
26 BT_DECLARE_ALIGNED_ALLOCATOR();
28 btVector3 m_vertices1[3];
30 virtual int getNumVertices() const
35 btVector3& getVertexPtr(int index)
37 return m_vertices1[index];
40 const btVector3& getVertexPtr(int index) const
42 return m_vertices1[index];
44 virtual void getVertex(int index, btVector3& vert) const
46 vert = m_vertices1[index];
49 virtual int getNumEdges() const
54 virtual void getEdge(int i, btVector3& pa, btVector3& pb) const
57 getVertex((i + 1) % 3, pb);
60 virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
63 getAabbSlow(t, aabbMin, aabbMax);
66 btVector3 localGetSupportingVertexWithoutMargin(const btVector3& dir) const
68 btVector3 dots = dir.dot3(m_vertices1[0], m_vertices1[1], m_vertices1[2]);
69 return m_vertices1[dots.maxAxis()];
72 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
74 for (int i = 0; i < numVectors; i++)
76 const btVector3& dir = vectors[i];
77 btVector3 dots = dir.dot3(m_vertices1[0], m_vertices1[1], m_vertices1[2]);
78 supportVerticesOut[i] = m_vertices1[dots.maxAxis()];
82 btTriangleShape() : btPolyhedralConvexShape()
84 m_shapeType = TRIANGLE_SHAPE_PROXYTYPE;
87 btTriangleShape(const btVector3& p0, const btVector3& p1, const btVector3& p2) : btPolyhedralConvexShape()
89 m_shapeType = TRIANGLE_SHAPE_PROXYTYPE;
95 virtual void getPlane(btVector3 & planeNormal, btVector3 & planeSupport, int i) const
97 getPlaneEquation(i, planeNormal, planeSupport);
100 virtual int getNumPlanes() const
105 void calcNormal(btVector3 & normal) const
107 normal = (m_vertices1[1] - m_vertices1[0]).cross(m_vertices1[2] - m_vertices1[0]);
111 virtual void getPlaneEquation(int i, btVector3& planeNormal, btVector3& planeSupport) const
114 calcNormal(planeNormal);
115 planeSupport = m_vertices1[0];
118 virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const
122 inertia.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
125 virtual bool isInside(const btVector3& pt, btScalar tolerance) const
130 btScalar dist = pt.dot(normal);
131 btScalar planeconst = m_vertices1[0].dot(normal);
133 if (dist >= -tolerance && dist <= tolerance)
135 //inside check on edge-planes
137 for (i = 0; i < 3; i++)
141 btVector3 edge = pb - pa;
142 btVector3 edgeNormal = edge.cross(normal);
143 edgeNormal.normalize();
144 btScalar dist = pt.dot(edgeNormal);
145 btScalar edgeConst = pa.dot(edgeNormal);
147 if (dist < -tolerance)
157 virtual const char* getName() const
162 virtual int getNumPreferredPenetrationDirections() const
167 virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
169 calcNormal(penetrationVector);
171 penetrationVector *= btScalar(-1.);
175 #endif //BT_OBB_TRIANGLE_MINKOWSKI_H