From 33ed11d8e6be6065b4683fbd4103555fc32c9431 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 22 Jun 2014 00:47:14 +0200 Subject: [PATCH] Physics: Use capsule shapes for actors if possible (Fixes #1437) --- libs/openengine/bullet/physic.cpp | 11 +++++++++-- libs/openengine/bullet/trace.cpp | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index bc34f2f51..d934639e0 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -29,7 +29,14 @@ namespace Physic mMeshOrientation = Ogre::Quaternion::IDENTITY; } - mShape.reset(new btBoxShape(BtOgre::Convert::toBullet(mHalfExtents))); + // Use capsule shape only if base is square (nonuniform scaling apparently doesn't work on it) + if (std::abs(mHalfExtents.x-mHalfExtents.y)= mHalfExtents.x) + { + mShape.reset(new btCapsuleShapeZ(mHalfExtents.x, mHalfExtents.z*2.f - mHalfExtents.x*2.f)); + } + else + mShape.reset(new btBoxShape(BtOgre::Convert::toBullet(mHalfExtents))); + mShape->setLocalScaling(btVector3(scale,scale,scale)); btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo @@ -102,7 +109,7 @@ namespace Physic Ogre::Vector3 PhysicActor::getHalfExtents() const { - return mHalfExtents; + return mHalfExtents * mScale; } void PhysicActor::setInertialForce(const Ogre::Vector3 &force) diff --git a/libs/openengine/bullet/trace.cpp b/libs/openengine/bullet/trace.cpp index 78fb5a3a7..46db4c6b8 100644 --- a/libs/openengine/bullet/trace.cpp +++ b/libs/openengine/bullet/trace.cpp @@ -107,7 +107,7 @@ void ActorTracer::findGround(const OEngine::Physic::PhysicActor* actor, const Og btVector3 halfExtents(actor->getHalfExtents().x, actor->getHalfExtents().y, actor->getHalfExtents().z); halfExtents[2] = 1.0f; - btBoxShape base(halfExtents); + btCylinderShapeZ base(halfExtents); enginePass->mDynamicsWorld->convexSweepTest(&base, from, to, newTraceCallback); if(newTraceCallback.hasHit())