Bullet Collision Detection & Physics Library: btStaticPlaneShape.cpp Source File

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
18 #include "LinearMath/btTransformUtil.h"
19
20
21 btStaticPlaneShape::btStaticPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
22 : btConcaveShape (), m_planeNormal(planeNormal.normalized()),
23 m_planeConstant(planeConstant),
24 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
25 {
26 m_shapeType = STATIC_PLANE_PROXYTYPE;
27 // btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );
28 }
29
30
31 btStaticPlaneShape::~btStaticPlaneShape()
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
50 aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
51 aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
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 supVertex0,supVertex1;
73
74 btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal;
75
76 btVector3 triangle[3];
77 triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
78 triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius;
79 triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
80
81 callback->processTriangle(triangle,0,0);
82
83 triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
84 triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
85 triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
86
87 callback->processTriangle(triangle,0,1);
88
89 }
90
91 void btStaticPlaneShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
92 {
93 (void)mass;
94
95 //moving concave objects not supported
96
97 inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
98 }
99
100 void btStaticPlaneShape::setLocalScaling(const btVector3& scaling)
101 {
102 m_localScaling = scaling;
103 }
104 const btVector3& btStaticPlaneShape::getLocalScaling() const
105 {
106 return m_localScaling;
107 }
btStaticPlaneShape::processAllTriangles
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btStaticPlaneShape.cpp:58
btTransformUtil.h
btStaticPlaneShape::m_planeConstant
btScalar m_planeConstant
Definition: btStaticPlaneShape.h:30
BT_LARGE_FLOAT
#define BT_LARGE_FLOAT
Definition: btScalar.h:281
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:650
btPlaneSpace1
void btPlaneSpace1(const T &n, T &p, T &q)
Definition: btVector3.h:1282
btTriangleCallback::processTriangle
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)=0
btStaticPlaneShape::m_planeNormal
btVector3 m_planeNormal
Definition: btStaticPlaneShape.h:29
btStaticPlaneShape.h
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition: btTriangleCallback.h:24
btVector3::dot
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:235
btStaticPlaneShape::btStaticPlaneShape
btStaticPlaneShape(const btVector3 &planeNormal, btScalar planeConstant)
Definition: btStaticPlaneShape.cpp:21
btStaticPlaneShape::getAabb
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...
Definition: btStaticPlaneShape.cpp:37
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btConcaveShape
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
Definition: btConcaveShape.h:36
btStaticPlaneShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btStaticPlaneShape.cpp:100
btStaticPlaneShape::calculateLocalInertia
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btStaticPlaneShape.cpp:91
btStaticPlaneShape::m_localScaling
btVector3 m_localScaling
Definition: btStaticPlaneShape.h:31
btCollisionShape::m_shapeType
int m_shapeType
Definition: btCollisionShape.h:30
btStaticPlaneShape::~btStaticPlaneShape
virtual ~btStaticPlaneShape()
Definition: btStaticPlaneShape.cpp:31
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279
btStaticPlaneShape::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btStaticPlaneShape.cpp:104
btVector3::length
btScalar length() const
Return the length of the vector.
Definition: btVector3.h:263
STATIC_PLANE_PROXYTYPE
Definition: btBroadphaseProxy.h:67