Blender  V3.3
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 
17 
19  : m_localScaling(localScaling), m_bvhTriMeshShape(childShape)
20 {
22 }
23 
25 {
26 }
27 
29 {
30  btTriangleCallback* m_originalCallback;
31 
32  btVector3 m_localScaling;
33 
34 public:
35  btScaledTriangleCallback(btTriangleCallback* originalCallback, const btVector3& localScaling)
36  : m_originalCallback(originalCallback),
37  m_localScaling(localScaling)
38  {
39  }
40 
41  virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
42  {
43  btVector3 newTriangle[3];
44  newTriangle[0] = triangle[0] * m_localScaling;
45  newTriangle[1] = triangle[1] * m_localScaling;
46  newTriangle[2] = triangle[2] * m_localScaling;
47  m_originalCallback->processTriangle(&newTriangle[0], partId, triangleIndex);
48  }
49 };
50 
52 {
54 
55  btVector3 invLocalScaling(1.f / m_localScaling.getX(), 1.f / m_localScaling.getY(), 1.f / m_localScaling.getZ());
56  btVector3 scaledAabbMin, scaledAabbMax;
57 
59  scaledAabbMin[0] = m_localScaling.getX() >= 0. ? aabbMin[0] * invLocalScaling[0] : aabbMax[0] * invLocalScaling[0];
60  scaledAabbMin[1] = m_localScaling.getY() >= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
61  scaledAabbMin[2] = m_localScaling.getZ() >= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
62  scaledAabbMin[3] = 0.f;
63 
64  scaledAabbMax[0] = m_localScaling.getX() <= 0. ? aabbMin[0] * invLocalScaling[0] : aabbMax[0] * invLocalScaling[0];
65  scaledAabbMax[1] = m_localScaling.getY() <= 0. ? aabbMin[1] * invLocalScaling[1] : aabbMax[1] * invLocalScaling[1];
66  scaledAabbMax[2] = m_localScaling.getZ() <= 0. ? aabbMin[2] * invLocalScaling[2] : aabbMax[2] * invLocalScaling[2];
67  scaledAabbMax[3] = 0.f;
68 
69  m_bvhTriMeshShape->processAllTriangles(&scaledCallback, scaledAabbMin, scaledAabbMax);
70 }
71 
72 void btScaledBvhTriangleMeshShape::getAabb(const btTransform& trans, btVector3& aabbMin, btVector3& aabbMax) const
73 {
74  btVector3 localAabbMin = m_bvhTriMeshShape->getLocalAabbMin();
75  btVector3 localAabbMax = m_bvhTriMeshShape->getLocalAabbMax();
76 
77  btVector3 tmpLocalAabbMin = localAabbMin * m_localScaling;
78  btVector3 tmpLocalAabbMax = localAabbMax * m_localScaling;
79 
80  localAabbMin[0] = (m_localScaling.getX() >= 0.) ? tmpLocalAabbMin[0] : tmpLocalAabbMax[0];
81  localAabbMin[1] = (m_localScaling.getY() >= 0.) ? tmpLocalAabbMin[1] : tmpLocalAabbMax[1];
82  localAabbMin[2] = (m_localScaling.getZ() >= 0.) ? tmpLocalAabbMin[2] : tmpLocalAabbMax[2];
83  localAabbMax[0] = (m_localScaling.getX() <= 0.) ? tmpLocalAabbMin[0] : tmpLocalAabbMax[0];
84  localAabbMax[1] = (m_localScaling.getY() <= 0.) ? tmpLocalAabbMin[1] : tmpLocalAabbMax[1];
85  localAabbMax[2] = (m_localScaling.getZ() <= 0.) ? tmpLocalAabbMin[2] : tmpLocalAabbMax[2];
86 
87  btVector3 localHalfExtents = btScalar(0.5) * (localAabbMax - localAabbMin);
88  btScalar margin = m_bvhTriMeshShape->getMargin();
89  localHalfExtents += btVector3(margin, margin, margin);
90  btVector3 localCenter = btScalar(0.5) * (localAabbMax + localAabbMin);
91 
92  btMatrix3x3 abs_b = trans.getBasis().absolute();
93 
94  btVector3 center = trans(localCenter);
95 
96  btVector3 extent = localHalfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
97  aabbMin = center - extent;
98  aabbMax = center + extent;
99 }
100 
102 {
103  m_localScaling = scaling;
104 }
105 
107 {
108  return m_localScaling;
109 }
110 
112 {
114  // btAssert(0);
115 }
NSNotificationCenter * center
virtual void setLocalScaling(const btVector3 &scaling)
in case we receive negative scaling
Definition: btBox2dShape.h:120
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
Definition: btConeShape.h:54
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb's default implementation is brute force, expected derived classes to implement a fast dedicat...
@ SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
Definition: btEmptyShape.h:57
btBvhTriangleMeshShape(btStridingMeshInterface *meshInterface, bool useQuantizedAabbCompression, bool buildBvh=true)
virtual const btVector3 & getLocalScaling() const =0
btVector3 m_localScaling
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btBvhTriangleMeshShape * m_bvhTriMeshShape
virtual ~btScaledBvhTriangleMeshShape()
btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape *childShape, const btVector3 &localScaling)
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)
btScaledTriangleCallback(btTriangleCallback *originalCallback, const btVector3 &localScaling)
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)=0
DEGForeachIDComponentCallback callback