Scaling the btCapsule, scaling performance

chucksspencer
Posts: 35
Joined: Wed Jun 25, 2008 2:52 pm

Scaling the btCapsule, scaling performance

Post by chucksspencer »

I've noticed some odd behavior when trying to use the setLocalScaling call with the btCapsuleShape.

I tweaked the BasicDemo.cpp to demonstrate - changing the boxes to capsules and setting the scaling in stead of multiplying the capsule's parameters by the SCALING factor. See line 140 of BasicDemo.cpp.

Code: Select all

		//btCollisionShape* colShape = new btCapsuleShape(SCALING*.75, SCALING*1);
		btCollisionShape* colShape = new btCapsuleShape(.75, 1);
		colShape->setLocalScaling(btVector3(SCALING, SCALING, SCALING));
The capsules get the correct radius but their height isn't scaled properly. See capsules1.gif. If I multiply the parameters:

Code: Select all

		btCollisionShape* colShape = new btCapsuleShape(SCALING*.75, SCALING*1);
		//btCollisionShape* colShape = new btCapsuleShape(.75, 1);
		//colShape->setLocalScaling(btVector3(SCALING, SCALING, SCALING));
it works as expected (see capsules2.gif). If I try the scaling with boxes, cylinders or spheres it seems to work fine.

Another thing I noticed while testing this out, if I apply the scaling this way using cylinders:

Code: Select all

		btCollisionShape* colShape = new btCylinderShape(btVector3(1,1,1));
		colShape->setLocalScaling(btVector3(SCALING, SCALING, SCALING));
in stead of multiplying its parameters when constructing it:

Code: Select all

		btCollisionShape* colShape = new btCylinderShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
the resulting demo runs much slower - the stepSimulation time is like 70 ms/fram in stead of around 35 without the setLocalScaling - so about half the speed. Is this expected? Am I using the setLocalScaling method incorrectly?

Thanks in advance for the help! Cheers!

- Chuck
You do not have the required permissions to view the files attached to this post.
chucksspencer
Posts: 35
Joined: Wed Jun 25, 2008 2:52 pm

Re: Scaling the btCapsule, scaling performance

Post by chucksspencer »

I submitted an issue and a patch for this
http://code.google.com/p/bullet/issues/detail?id=230

before the implementation of setLocalScaling for btCapsuleShape just called the method from its parent:

Code: Select all

	virtual void	setLocalScaling(const btVector3& scaling)
	{
		btConvexInternalShape::setLocalScaling(scaling);
	}
I replaced it with a duplicate of the implementation from btBoxShape, which updates the shape margin and implicit dimensions.

Code: Select all

	virtual void	setLocalScaling(const btVector3& scaling)
	{
		btVector3 oldMargin(getMargin(),getMargin(),getMargin());
		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
		btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;

		btConvexInternalShape::setLocalScaling(scaling);

		m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;

	}
the result works as expected.

I think I may have been imagining the performance issue - I can't recreate it now.
theyesfish
Posts: 10
Joined: Sat Apr 11, 2009 7:12 pm

Re: Scaling the btCapsule, scaling performance

Post by theyesfish »

As far as I understand, the capsule's dimensions work like:

Radius = radius
Height = height + radius * 2

Where height would define the height of the *cylinder* of the capsule, not the total height.

But I could be wrong.
chucksspencer
Posts: 35
Joined: Wed Jun 25, 2008 2:52 pm

Re: Scaling the btCapsule, scaling performance

Post by chucksspencer »

theyesfish wrote:As far as I understand, the capsule's dimensions work like:

Radius = radius
Height = height + radius * 2

Where height would define the height of the *cylinder* of the capsule, not the total height.

But I could be wrong.
That is true - I just tweaked the values of the capsules in my example enough to keep them from overlapping when the simulation ran - I didn't expect them to be the exact same size as compared to the cylinders in the other example, I was just comparing the effect that scaling had on them respectively.

Anyway it's a moot point - it appears the problem had already been addressed in the most recent 2.75 trunk.