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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
18#include "LinearMath/btTransformUtil.h"
19
20btStaticPlaneShape::btStaticPlaneShape(const btVector3& planeNormal, btScalar planeConstant)
21 : btConcaveShape(), m_planeNormal(planeNormal.normalized()), m_planeConstant(planeConstant), m_localScaling(btScalar(1.), btScalar(1.), btScalar(1.))
22{
23 m_shapeType = STATIC_PLANE_PROXYTYPE;
24 // btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );
25}
26
27btStaticPlaneShape::~btStaticPlaneShape()
28{
29}
30
31 void 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
44 aabbMin.setValue(btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT));
45 aabbMax.setValue(btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT));
46}
47
48 void 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
77 void btStaticPlaneShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
78{
79 (void)mass;
80
81 //moving concave objects not supported
82
83 inertia.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
84}
85
86 void btStaticPlaneShape::setLocalScaling(const btVector3& scaling)
87{
88 m_localScaling = scaling;
89}
90 const btVector3& btStaticPlaneShape::getLocalScaling() const
91{
92 return m_localScaling;
93}
STATIC_PLANE_PROXYTYPE
@ STATIC_PLANE_PROXYTYPE
Definition: btBroadphaseProxy.h:66
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
BT_LARGE_FLOAT
#define BT_LARGE_FLOAT
Definition: btScalar.h:316
btStaticPlaneShape.h
btTransformUtil.h
btPlaneSpace1
void btPlaneSpace1(const T &n, T &p, T &q)
Definition: btVector3.h:1251
btCollisionShape::m_shapeType
int m_shapeType
Definition: btCollisionShape.h:30
btConcaveShape
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
Definition: btConcaveShape.h:39
btStaticPlaneShape::processAllTriangles
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btStaticPlaneShape.cpp:48
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:31
btStaticPlaneShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btStaticPlaneShape.cpp:86
btStaticPlaneShape::m_localScaling
btVector3 m_localScaling
Definition: btStaticPlaneShape.h:31
btStaticPlaneShape::~btStaticPlaneShape
virtual ~btStaticPlaneShape()
Definition: btStaticPlaneShape.cpp:27
btStaticPlaneShape::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btStaticPlaneShape.cpp:90
btStaticPlaneShape::calculateLocalInertia
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btStaticPlaneShape.cpp:77
btStaticPlaneShape::m_planeNormal
btVector3 m_planeNormal
Definition: btStaticPlaneShape.h:29
btStaticPlaneShape::btStaticPlaneShape
btStaticPlaneShape(const btVector3 &planeNormal, btScalar planeConstant)
Definition: btStaticPlaneShape.cpp:20
btStaticPlaneShape::m_planeConstant
btScalar m_planeConstant
Definition: btStaticPlaneShape.h:30
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition: btTriangleCallback.h:24
btTriangleCallback::processTriangle
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)=0
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btVector3::length
btScalar length() const
Return the length of the vector.
Definition: btVector3.h:257
btVector3::dot
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:229
btVector3::setValue
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:640