Bullet Collision Detection & Physics Library
btStaticPlaneShape.cpp
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4 
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:
10 
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.
14 */
15 
16 #include "btStaticPlaneShape.h"
17 
19 
20 
22 : btConcaveShape (), m_planeNormal(planeNormal.normalized()),
23 m_planeConstant(planeConstant),
24 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
25 {
27  // btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );
28 }
29 
30 
32 {
33 }
34 
35 
36 
37 void btStaticPlaneShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
38 {
39  (void)t;
40  /*
41  btVector3 infvec (btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
42 
43  btVector3 center = m_planeNormal*m_planeConstant;
44  aabbMin = center + infvec*m_planeNormal;
45  aabbMax = aabbMin;
46  aabbMin.setMin(center - infvec*m_planeNormal);
47  aabbMax.setMax(center - infvec*m_planeNormal);
48  */
49 
52 
53 }
54 
55 
56 
57 
58 void btStaticPlaneShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
59 {
60 
61  btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
62  btScalar radius = halfExtents.length();
63  btVector3 center = (aabbMax + aabbMin) * btScalar(0.5);
64 
65  //this is where the triangles are generated, given AABB and plane equation (normal/constant)
66 
67  btVector3 tangentDir0,tangentDir1;
68 
69  //tangentDir0/tangentDir1 can be precalculated
70  btPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1);
71 
72  btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal;
73 
74  btVector3 triangle[3];
75  triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
76  triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius;
77  triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
78 
79  callback->processTriangle(triangle,0,0);
80 
81  triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
82  triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
83  triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
84 
85  callback->processTriangle(triangle,0,1);
86 
87 }
88 
90 {
91  (void)mass;
92 
93  //moving concave objects not supported
94 
95  inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
96 }
97 
99 {
100  m_localScaling = scaling;
101 }
103 {
104  return m_localScaling;
105 }
#define BT_LARGE_FLOAT
Definition: btScalar.h:294
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
void btPlaneSpace1(const T &n, T &p, T &q)
Definition: btVector3.h:1284
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)=0
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:235
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
btStaticPlaneShape(const btVector3 &planeNormal, btScalar planeConstant)
btScalar length() const
Return the length of the vector.
Definition: btVector3.h:263
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
virtual const btVector3 & getLocalScaling() const
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
virtual void setLocalScaling(const btVector3 &scaling)
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
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...