Bullet Collision Detection & Physics Library
btStaticPlaneShape.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#include "btStaticPlaneShape.h"
17
19
21 : btConcaveShape(), m_planeNormal(planeNormal.normalized()), m_planeConstant(planeConstant), m_localScaling(btScalar(1.), btScalar(1.), btScalar(1.))
22{
24 // btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );
25}
26
28{
29}
30
31void btStaticPlaneShape::getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
32{
33 (void)t;
34 /*
35 btVector3 infvec (btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
36
37 btVector3 center = m_planeNormal*m_planeConstant;
38 aabbMin = center + infvec*m_planeNormal;
39 aabbMax = aabbMin;
40 aabbMin.setMin(center - infvec*m_planeNormal);
41 aabbMax.setMax(center - infvec*m_planeNormal);
42 */
43
46}
47
48void btStaticPlaneShape::processAllTriangles(btTriangleCallback* callback, const btVector3& aabbMin, const btVector3& aabbMax) const
49{
50 btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
51 btScalar radius = halfExtents.length();
52 btVector3 center = (aabbMax + aabbMin) * btScalar(0.5);
53
54 //this is where the triangles are generated, given AABB and plane equation (normal/constant)
55
56 btVector3 tangentDir0, tangentDir1;
57
58 //tangentDir0/tangentDir1 can be precalculated
59 btPlaneSpace1(m_planeNormal, tangentDir0, tangentDir1);
60
61 btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant) * m_planeNormal;
62
63 btVector3 triangle[3];
64 triangle[0] = projectedCenter + tangentDir0 * radius + tangentDir1 * radius;
65 triangle[1] = projectedCenter + tangentDir0 * radius - tangentDir1 * radius;
66 triangle[2] = projectedCenter - tangentDir0 * radius - tangentDir1 * radius;
67
68 callback->processTriangle(triangle, 0, 0);
69
70 triangle[0] = projectedCenter - tangentDir0 * radius - tangentDir1 * radius;
71 triangle[1] = projectedCenter - tangentDir0 * radius + tangentDir1 * radius;
72 triangle[2] = projectedCenter + tangentDir0 * radius + tangentDir1 * radius;
73
74 callback->processTriangle(triangle, 0, 1);
75}
76
78{
79 (void)mass;
80
81 //moving concave objects not supported
82
83 inertia.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
84}
85
87{
88 m_localScaling = scaling;
89}
91{
92 return m_localScaling;
93}
@ STATIC_PLANE_PROXYTYPE
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define BT_LARGE_FLOAT
Definition: btScalar.h:316
void btPlaneSpace1(const T &n, T &p, T &q)
Definition: btVector3.h:1251
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
virtual void setLocalScaling(const btVector3 &scaling)
virtual const btVector3 & getLocalScaling() const
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
btStaticPlaneShape(const btVector3 &planeNormal, btScalar planeConstant)
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)=0
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btScalar length() const
Return the length of the vector.
Definition: btVector3.h:257
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:229
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:640