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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btScaledBvhTriangleMeshShape.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
17 #include "btScaledBvhTriangleMeshShape.h"
18
19 btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,const btVector3& localScaling)
20 :m_localScaling(localScaling),m_bvhTriMeshShape(childShape)
21 {
22 m_shapeType = SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE;
23 }
24
25 btScaledBvhTriangleMeshShape::~btScaledBvhTriangleMeshShape()
26 {
27 }
28
29
30 class btScaledTriangleCallback : public btTriangleCallback
31 {
32 btTriangleCallback* m_originalCallback;
33
34 btVector3 m_localScaling;
35
36 public:
37
38 btScaledTriangleCallback(btTriangleCallback* originalCallback,const btVector3& localScaling)
39 :m_originalCallback(originalCallback),
40 m_localScaling(localScaling)
41 {
42 }
43
44 virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
45 {
46 btVector3 newTriangle[3];
47 newTriangle[0] = triangle[0]*m_localScaling;
48 newTriangle[1] = triangle[1]*m_localScaling;
49 newTriangle[2] = triangle[2]*m_localScaling;
50 m_originalCallback->processTriangle(&newTriangle[0],partId,triangleIndex);
51 }
52 };
53
54 void btScaledBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
55 {
56 btScaledTriangleCallback scaledCallback(callback,m_localScaling);
57
58 btVector3 invLocalScaling(1.f/m_localScaling.getX(),1.f/m_localScaling.getY(),1.f/m_localScaling.getZ());
59 btVector3 scaledAabbMin,scaledAabbMax;
60
62 scaledAabbMin[0] = m_localScaling.getX() >= 0. ? aabbMin[0] * invLocalScaling[0] : aabbMax[0] * invLocalScaling[0];
63 scaledAabbMin[1] = m_localScaling.getY() >= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
64 scaledAabbMin[2] = m_localScaling.getZ() >= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
65 scaledAabbMin[3] = 0.f;
66
67 scaledAabbMax[0] = m_localScaling.getX() <= 0. ? aabbMin[0] * invLocalScaling[0] : aabbMax[0] * invLocalScaling[0];
68 scaledAabbMax[1] = m_localScaling.getY() <= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
69 scaledAabbMax[2] = m_localScaling.getZ() <= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
70 scaledAabbMax[3] = 0.f;
71
72
73 m_bvhTriMeshShape->processAllTriangles(&scaledCallback,scaledAabbMin,scaledAabbMax);
74 }
75
76
77 void btScaledBvhTriangleMeshShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
78 {
79 btVector3 localAabbMin = m_bvhTriMeshShape->getLocalAabbMin();
80 btVector3 localAabbMax = m_bvhTriMeshShape->getLocalAabbMax();
81
82 btVector3 tmpLocalAabbMin = localAabbMin * m_localScaling;
83 btVector3 tmpLocalAabbMax = localAabbMax * m_localScaling;
84
85 localAabbMin[0] = (m_localScaling.getX() >= 0.) ? tmpLocalAabbMin[0] : tmpLocalAabbMax[0];
86 localAabbMin[1] = (m_localScaling.getY() >= 0.) ? tmpLocalAabbMin[1] : tmpLocalAabbMax[1];
87 localAabbMin[2] = (m_localScaling.getZ() >= 0.) ? tmpLocalAabbMin[2] : tmpLocalAabbMax[2];
88 localAabbMax[0] = (m_localScaling.getX() <= 0.) ? tmpLocalAabbMin[0] : tmpLocalAabbMax[0];
89 localAabbMax[1] = (m_localScaling.getY() <= 0.) ? tmpLocalAabbMin[1] : tmpLocalAabbMax[1];
90 localAabbMax[2] = (m_localScaling.getZ() <= 0.) ? tmpLocalAabbMin[2] : tmpLocalAabbMax[2];
91
92 btVector3 localHalfExtents = btScalar(0.5)*(localAabbMax-localAabbMin);
93 btScalar margin = m_bvhTriMeshShape->getMargin();
94 localHalfExtents += btVector3(margin,margin,margin);
95 btVector3 localCenter = btScalar(0.5)*(localAabbMax+localAabbMin);
96
97 btMatrix3x3 abs_b = trans.getBasis().absolute();
98
99 btVector3 center = trans(localCenter);
100
101 btVector3 extent = localHalfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
102 aabbMin = center - extent;
103 aabbMax = center + extent;
104
105 }
106
107 void btScaledBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
108 {
109 m_localScaling = scaling;
110 }
111
112 const btVector3& btScaledBvhTriangleMeshShape::getLocalScaling() const
113 {
114 return m_localScaling;
115 }
116
117 void btScaledBvhTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
118 {
120 // btAssert(0);
121 }
btScaledBvhTriangleMeshShape::getLocalScaling
virtual const btVector3 & getLocalScaling() const
Definition: btScaledBvhTriangleMeshShape.cpp:112
SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE
Definition: btBroadphaseProxy.h:56
btScaledBvhTriangleMeshShape::~btScaledBvhTriangleMeshShape
virtual ~btScaledBvhTriangleMeshShape()
Definition: btScaledBvhTriangleMeshShape.cpp:25
btBvhTriangleMeshShape::processAllTriangles
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btBvhTriangleMeshShape.cpp:232
btTriangleCallback::processTriangle
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)=0
btScaledBvhTriangleMeshShape::processAllTriangles
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btScaledBvhTriangleMeshShape.cpp:54
btScaledTriangleCallback::m_originalCallback
btTriangleCallback * m_originalCallback
Definition: btScaledBvhTriangleMeshShape.cpp:32
btScaledBvhTriangleMeshShape.h
btVector3::getZ
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:565
btScaledBvhTriangleMeshShape::calculateLocalInertia
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btScaledBvhTriangleMeshShape.cpp:117
btTriangleMeshShape::getLocalAabbMin
const btVector3 & getLocalAabbMin() const
Definition: btTriangleMeshShape.h:69
btBvhTriangleMeshShape
The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving ...
Definition: btBvhTriangleMeshShape.h:34
btMatrix3x3::absolute
btMatrix3x3 absolute() const
Return the matrix with all values non negative.
Definition: btMatrix3x3.h:980
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition: btTriangleCallback.h:24
btScaledBvhTriangleMeshShape::setLocalScaling
virtual void setLocalScaling(const btVector3 &scaling)
Definition: btScaledBvhTriangleMeshShape.cpp:107
btScaledTriangleCallback::btScaledTriangleCallback
btScaledTriangleCallback(btTriangleCallback *originalCallback, const btVector3 &localScaling)
Definition: btScaledBvhTriangleMeshShape.cpp:38
btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape
btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape *childShape, const btVector3 &localScaling)
Definition: btScaledBvhTriangleMeshShape.cpp:19
btScaledBvhTriangleMeshShape::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: btScaledBvhTriangleMeshShape.cpp:77
btVector3::getY
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:563
btTransform::getBasis
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btVector3::getX
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:561
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btScaledTriangleCallback::m_localScaling
btVector3 m_localScaling
Definition: btScaledBvhTriangleMeshShape.cpp:34
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btScaledBvhTriangleMeshShape::m_bvhTriMeshShape
btBvhTriangleMeshShape * m_bvhTriMeshShape
Definition: btScaledBvhTriangleMeshShape.h:30
btScaledBvhTriangleMeshShape::m_localScaling
btVector3 m_localScaling
Definition: btScaledBvhTriangleMeshShape.h:28
btVector3::dot3
btVector3 dot3(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2) const
Definition: btVector3.h:719
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:48
btConcaveShape::getMargin
virtual btScalar getMargin() const
Definition: btConcaveShape.h:50
btTriangleMeshShape::getLocalAabbMax
const btVector3 & getLocalAabbMax() const
Definition: btTriangleMeshShape.h:73
btScaledTriangleCallback
Definition: btScaledBvhTriangleMeshShape.cpp:30
btCollisionShape::m_shapeType
int m_shapeType
Definition: btCollisionShape.h:30
btScaledTriangleCallback::processTriangle
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)
Definition: btScaledBvhTriangleMeshShape.cpp:44
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278