Welcome to mirror list, hosted at ThFree Co, Russian Federation.

inertia.patch « patches « bullet2 « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 731772dd220c491049c62b84207527bab3cbf828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
From 1b4c1687748bafd3c521f454bfdfc89b3857b65e Mon Sep 17 00:00:00 2001
From: David Vogel <Dadido3@aol.com>
Date: Mon, 30 Mar 2020 19:45:23 +0200
Subject: [PATCH 1/2] Fix inertia and margin calculation for
 btPolyhedralConvexShape

---
 .../CollisionShapes/btPolyhedralConvexShape.cpp    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp b/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
index 521ecfc760..e4bd7bb4d5 100644
--- a/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
+++ b/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
@@ -463,17 +463,17 @@ void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass, btVector3& in
 #ifndef __SPU__
 	//not yet, return box inertia
 
-	btScalar margin = getMargin();
+	//btScalar margin = getMargin();
 
 	btTransform ident;
 	ident.setIdentity();
 	btVector3 aabbMin, aabbMax;
-	getAabb(ident, aabbMin, aabbMax);
+	getAabb(ident, aabbMin, aabbMax);  // This already contains the margin
 	btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
 
-	btScalar lx = btScalar(2.) * (halfExtents.x() + margin);
-	btScalar ly = btScalar(2.) * (halfExtents.y() + margin);
-	btScalar lz = btScalar(2.) * (halfExtents.z() + margin);
+	btScalar lx = btScalar(2.) * (halfExtents.x());
+	btScalar ly = btScalar(2.) * (halfExtents.y());
+	btScalar lz = btScalar(2.) * (halfExtents.z());
 	const btScalar x2 = lx * lx;
 	const btScalar y2 = ly * ly;
 	const btScalar z2 = lz * lz;
@@ -529,8 +529,8 @@ void btPolyhedralConvexAabbCachingShape::recalcLocalAabb()
 
 	for (int i = 0; i < 3; ++i)
 	{
-		m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
-		m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
+		m_localAabbMax[i] = _supporting[i][i];
+		m_localAabbMin[i] = _supporting[i + 3][i];
 	}
 
 #else

From 4b9a201d4c1b8cacbcdd68f9cdb55745caa6adc4 Mon Sep 17 00:00:00 2001
From: David Vogel <Dadido3@aol.com>
Date: Mon, 30 Mar 2020 20:43:55 +0200
Subject: [PATCH 2/2]  Fix margins

- Margin in ineratia calculation of btConeShape is already contained in the AABB
- Remove margin from the cached AABB in btConvexInternalShape, as it is added on getAabb()
---
 src/BulletCollision/CollisionShapes/btConeShape.h      | 10 ++++------
 .../CollisionShapes/btConvexInternalShape.cpp          |  8 ++++----
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/BulletCollision/CollisionShapes/btConeShape.h b/src/BulletCollision/CollisionShapes/btConeShape.h
index 49f26bc4e5..ee6786c807 100644
--- a/src/BulletCollision/CollisionShapes/btConeShape.h
+++ b/src/BulletCollision/CollisionShapes/btConeShape.h
@@ -56,15 +56,13 @@ btConeShape : public btConvexInternalShape
 		btTransform identity;
 		identity.setIdentity();
 		btVector3 aabbMin, aabbMax;
-		getAabb(identity, aabbMin, aabbMax);
 
+		getAabb(identity, aabbMin, aabbMax);  // This already contains the margin
 		btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
 
-		btScalar margin = getMargin();
-
-		btScalar lx = btScalar(2.) * (halfExtents.x() + margin);
-		btScalar ly = btScalar(2.) * (halfExtents.y() + margin);
-		btScalar lz = btScalar(2.) * (halfExtents.z() + margin);
+		btScalar lx = btScalar(2.) * (halfExtents.x());
+		btScalar ly = btScalar(2.) * (halfExtents.y());
+		btScalar lz = btScalar(2.) * (halfExtents.z());
 		const btScalar x2 = lx * lx;
 		const btScalar y2 = ly * ly;
 		const btScalar z2 = lz * lz;
diff --git a/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp b/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
index 4d598b1aa2..b847f8f40f 100644
--- a/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
+++ b/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
@@ -117,8 +117,8 @@ void btConvexInternalAabbCachingShape::recalcLocalAabb()
 
 	for (int i = 0; i < 3; ++i)
 	{
-		m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
-		m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
+		m_localAabbMax[i] = _supporting[i][i];
+		m_localAabbMin[i] = _supporting[i + 3][i];
 	}
 
 #else
@@ -128,10 +128,10 @@ void btConvexInternalAabbCachingShape::recalcLocalAabb()
 		btVector3 vec(btScalar(0.), btScalar(0.), btScalar(0.));
 		vec[i] = btScalar(1.);
 		btVector3 tmp = localGetSupportingVertex(vec);
-		m_localAabbMax[i] = tmp[i] + m_collisionMargin;
+		m_localAabbMax[i] = tmp[i];
 		vec[i] = btScalar(-1.);
 		tmp = localGetSupportingVertex(vec);
-		m_localAabbMin[i] = tmp[i] - m_collisionMargin;
+		m_localAabbMin[i] = tmp[i];
 	}
 #endif
 }