diff options
author | Daniel Rakos <daniel.rakos@rastergrid.com> | 2019-03-25 22:46:26 +0100 |
---|---|---|
committer | Daniel Rakos <daniel.rakos@rastergrid.com> | 2019-03-27 00:39:47 +0100 |
commit | 6dd65c0d67960b0f0b26a24bd2f10fe8d54aa37a (patch) | |
tree | c9a9a07105ba064ac039ca8ca48c508c2af73b5c /modules/bullet/btRayShape.cpp | |
parent | 81292665d5dcc991d3c9341245b269193329ee22 (diff) |
KinematicBody performance and quality improvements
With this change finally one can use compound collisions (like those created
by Gridmaps) without serious performance issues. The previous KinematicBody
code for Bullet was practically doing a whole bunch of unnecessary
calculations. Gridmaps with fairly large octant sizes (in my case 32) can get
up to 10000x speedup with this change (literally!). I expect the FPS demo to
get a fair speedup as well.
List of fixes and improvements:
- Fixed a general bug in move_and_slide that affects both GodotPhysics and
Bullet, where ray shapes would be ignored unless the stop_on_slope parameter
is disabled. Not sure where that came from, but looking at the 2D physics
code it was obvious there's a difference.
- Enabled the dynamic AABB tree that Bullet uses to allow broadphase collision
tests against individual shapes of compound shapes. This is crucial to get
good performance with Gridmaps and in general improves the performance
whenever a KinematicBody collides with compound collision shapes.
- Added code to the broadphase collision detection code used by the Bullet
module for KinematicBodies to also do broadphase on the sub-shapes of
compound collision shapes. This is possible thanks to the dynamic AABB
tree that was previously disabled and it's the change that provides the
biggest performance boost.
- Now broadphase test is only done once per KinematicBody in Bullet instead of
once per each of its shapes which was completely unnecessary.
- Fixed the way how the ray separation results are populated in Bullet which
was completely broken previously, overwriting previous results and similar
non-sense.
- Fixed ray shapes for good now. Previously the margin set in the editor was
not respected at all, and the KinematicBody code for ray separation was
complete bogus, thus all previous attempts to fix it were mislead.
- Fixed an obvious bug also in GodotPhysics where an out-of-bounds index was
used in the ray result array.
There are a whole set of other problems with the KinematicBody code of Bullet
which cost performance and may cause unexpected behavior, but those are not
addressed in this change (need to keep it "simple").
Not sure whether this fixes any outstanding Github issues but I wouldn't be
surprised.
Diffstat (limited to 'modules/bullet/btRayShape.cpp')
-rw-r--r-- | modules/bullet/btRayShape.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/modules/bullet/btRayShape.cpp b/modules/bullet/btRayShape.cpp index b902d08eca..b60d6ba693 100644 --- a/modules/bullet/btRayShape.cpp +++ b/modules/bullet/btRayShape.cpp @@ -54,6 +54,11 @@ void btRayShape::setLength(btScalar p_length) { reload_cache(); } +void btRayShape::setMargin(btScalar margin) { + btConvexInternalShape::setMargin(margin); + reload_cache(); +} + void btRayShape::setSlipsOnSlope(bool p_slipsOnSlope) { slipsOnSlope = p_slipsOnSlope; @@ -77,10 +82,9 @@ void btRayShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVecto } void btRayShape::getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const { -#define MARGIN_BROADPHASE 0.1 btVector3 localAabbMin(0, 0, 0); - btVector3 localAabbMax(m_shapeAxis * (m_cacheScaledLength + m_collisionMargin)); - btTransformAabb(localAabbMin, localAabbMax, MARGIN_BROADPHASE, t, aabbMin, aabbMax); + btVector3 localAabbMax(m_shapeAxis * m_cacheScaledLength); + btTransformAabb(localAabbMin, localAabbMax, m_collisionMargin, t, aabbMin, aabbMax); } void btRayShape::calculateLocalInertia(btScalar mass, btVector3 &inertia) const { @@ -100,5 +104,5 @@ void btRayShape::reload_cache() { m_cacheScaledLength = m_length * m_localScaling[2]; m_cacheSupportPoint.setIdentity(); - m_cacheSupportPoint.setOrigin(m_shapeAxis * (m_cacheScaledLength + m_collisionMargin)); + m_cacheSupportPoint.setOrigin(m_shapeAxis * m_cacheScaledLength); } |