Cleanup: remove compilation warning in previous commit.
[blender-staging.git] / extern / bullet2 / patches / inertia.patch
1 From 1b4c1687748bafd3c521f454bfdfc89b3857b65e Mon Sep 17 00:00:00 2001
2 From: David Vogel <Dadido3@aol.com>
3 Date: Mon, 30 Mar 2020 19:45:23 +0200
4 Subject: [PATCH 1/2] Fix inertia and margin calculation for
5  btPolyhedralConvexShape
6
7 ---
8  .../CollisionShapes/btPolyhedralConvexShape.cpp    | 14 +++++++-------
9  1 file changed, 7 insertions(+), 7 deletions(-)
10
11 diff --git a/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp b/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
12 index 521ecfc760..e4bd7bb4d5 100644
13 --- a/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
14 +++ b/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
15 @@ -463,17 +463,17 @@ void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass, btVector3& in
16  #ifndef __SPU__
17         //not yet, return box inertia
18  
19 -       btScalar margin = getMargin();
20 +       //btScalar margin = getMargin();
21  
22         btTransform ident;
23         ident.setIdentity();
24         btVector3 aabbMin, aabbMax;
25 -       getAabb(ident, aabbMin, aabbMax);
26 +       getAabb(ident, aabbMin, aabbMax);  // This already contains the margin
27         btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
28  
29 -       btScalar lx = btScalar(2.) * (halfExtents.x() + margin);
30 -       btScalar ly = btScalar(2.) * (halfExtents.y() + margin);
31 -       btScalar lz = btScalar(2.) * (halfExtents.z() + margin);
32 +       btScalar lx = btScalar(2.) * (halfExtents.x());
33 +       btScalar ly = btScalar(2.) * (halfExtents.y());
34 +       btScalar lz = btScalar(2.) * (halfExtents.z());
35         const btScalar x2 = lx * lx;
36         const btScalar y2 = ly * ly;
37         const btScalar z2 = lz * lz;
38 @@ -529,8 +529,8 @@ void btPolyhedralConvexAabbCachingShape::recalcLocalAabb()
39  
40         for (int i = 0; i < 3; ++i)
41         {
42 -               m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
43 -               m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
44 +               m_localAabbMax[i] = _supporting[i][i];
45 +               m_localAabbMin[i] = _supporting[i + 3][i];
46         }
47  
48  #else
49
50 From 4b9a201d4c1b8cacbcdd68f9cdb55745caa6adc4 Mon Sep 17 00:00:00 2001
51 From: David Vogel <Dadido3@aol.com>
52 Date: Mon, 30 Mar 2020 20:43:55 +0200
53 Subject: [PATCH 2/2]  Fix margins
54
55 - Margin in ineratia calculation of btConeShape is already contained in the AABB
56 - Remove margin from the cached AABB in btConvexInternalShape, as it is added on getAabb()
57 ---
58  src/BulletCollision/CollisionShapes/btConeShape.h      | 10 ++++------
59  .../CollisionShapes/btConvexInternalShape.cpp          |  8 ++++----
60  2 files changed, 8 insertions(+), 10 deletions(-)
61
62 diff --git a/src/BulletCollision/CollisionShapes/btConeShape.h b/src/BulletCollision/CollisionShapes/btConeShape.h
63 index 49f26bc4e5..ee6786c807 100644
64 --- a/src/BulletCollision/CollisionShapes/btConeShape.h
65 +++ b/src/BulletCollision/CollisionShapes/btConeShape.h
66 @@ -56,15 +56,13 @@ btConeShape : public btConvexInternalShape
67                 btTransform identity;
68                 identity.setIdentity();
69                 btVector3 aabbMin, aabbMax;
70 -               getAabb(identity, aabbMin, aabbMax);
71  
72 +               getAabb(identity, aabbMin, aabbMax);  // This already contains the margin
73                 btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
74  
75 -               btScalar margin = getMargin();
76 -
77 -               btScalar lx = btScalar(2.) * (halfExtents.x() + margin);
78 -               btScalar ly = btScalar(2.) * (halfExtents.y() + margin);
79 -               btScalar lz = btScalar(2.) * (halfExtents.z() + margin);
80 +               btScalar lx = btScalar(2.) * (halfExtents.x());
81 +               btScalar ly = btScalar(2.) * (halfExtents.y());
82 +               btScalar lz = btScalar(2.) * (halfExtents.z());
83                 const btScalar x2 = lx * lx;
84                 const btScalar y2 = ly * ly;
85                 const btScalar z2 = lz * lz;
86 diff --git a/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp b/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
87 index 4d598b1aa2..b847f8f40f 100644
88 --- a/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
89 +++ b/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
90 @@ -117,8 +117,8 @@ void btConvexInternalAabbCachingShape::recalcLocalAabb()
91  
92         for (int i = 0; i < 3; ++i)
93         {
94 -               m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
95 -               m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
96 +               m_localAabbMax[i] = _supporting[i][i];
97 +               m_localAabbMin[i] = _supporting[i + 3][i];
98         }
99  
100  #else
101 @@ -128,10 +128,10 @@ void btConvexInternalAabbCachingShape::recalcLocalAabb()
102                 btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
103                 vec[i] = btScalar(1.);
104                 btVector3 tmp = localGetSupportingVertex(vec);
105 -               m_localAabbMax[i] = tmp[i] + m_collisionMargin;
106 +               m_localAabbMax[i] = tmp[i];
107                 vec[i] = btScalar(-1.);
108                 tmp = localGetSupportingVertex(vec);
109 -               m_localAabbMin[i] = tmp[i] - m_collisionMargin;
110 +               m_localAabbMin[i] = tmp[i];
111         }
112  #endif
113  }