Blender V4.3
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
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
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
77void 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
86void btStaticPlaneShape::setLocalScaling(const btVector3& scaling)
87{
88 m_localScaling = scaling;
89}
90const btVector3& btStaticPlaneShape::getLocalScaling() const
91{
92 return m_localScaling;
93}
@ STATIC_PLANE_PROXYTYPE
btVector3 m_localScaling
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
btVector3 m_planeNormal
btScalar m_planeConstant
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
SIMD_FORCE_INLINE void btPlaneSpace1(const T &n, T &p, T &q)
Definition btVector3.h:1251
SIMD_FORCE_INLINE btVector3 normalized() const
Return a normalized version of this vector.
DEGForeachIDComponentCallback callback