Problems with unstable rotation

Post Reply
nemori
Posts: 2
Joined: Thu Nov 15, 2018 9:14 pm

Problems with unstable rotation

Post by nemori »

Hello,

I'm trying to integrate Bullet Physics in double precision into Unreal Engine for my project and I ran into a strange issue. I set object into motion by applying bunch of torque and then let it spin - it's in space so there's no gravity or anything like that. At speeds of about 2-3 rad/s the simulation starts to quickly accumulate some numeric error (at least that's how it looks like) and my object flips around. I'm not really sure what could I be doing wrong, it's a simple setup, nothing much is happening, and the values aren't big either.

Here's a video to illustrate my problem. Sorry about the quality.

https://www.youtube.com/watch?v=1c9Fc5sjF5Y

Here's the initialization code:

Code: Select all

void UBoxShapeComponent::InitializeComponent()
{
	check(!Shape && !MotionState && !RigidBody);

	Shape = new btBoxShape(btVector3(BoxExtent.X / 100.0, BoxExtent.Y / 100.0, BoxExtent.Z / 100.0));

	auto WorldLoc = GetComponentLocation();
	auto WorldQuat = GetComponentQuat();

	auto Rotation = btQuaternion{ WorldQuat.X, WorldQuat.Y, WorldQuat.Z, WorldQuat.W };
	auto Position = btVector3{ WorldLoc.X, WorldLoc.Y, WorldLoc.Z };
	MotionState = new btDefaultMotionState(btTransform(Rotation, Position));

	btVector3 bodyInertia;
	Shape->calculateLocalInertia(Mass, bodyInertia);

	auto BodyCI = btRigidBody::btRigidBodyConstructionInfo(Mass, MotionState, Shape, bodyInertia);

	RigidBody = new btRigidBody(BodyCI);
	RigidBody->setActivationState(DISABLE_DEACTIVATION);

	Super::InitializeComponent();
}
Here's where I apply torque:

Code: Select all

void UBoxShapeComponent::AddScaledTorqueInDegrees(FVector Torque)
{
	if (Torque.IsNearlyZero()) {
		return;
	}

	check(RigidBody);

	LOG("Angular input %s", *Torque.ToString());

	auto ScaledTorque = btVector3{ Torque.X, Torque.Y, Torque.Z };
	ScaledTorque *= 100.0; // tmp

	RigidBody->applyTorque(ScaledTorque);
}
Any help would be appreciated, because I'm kinda out of ideas :(
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Problems with unstable rotation

Post by drleviathan »

What are the values of BoxExtent?

If the eigenvalues of the inertia tensor have a high, mid, and low value AND you rotate the object around the axis parallel to eigenvector that corresponds to the "mid" eigenvalue then there is a natural instability where the spinning object will flip like that. For example: watch this demo video made on the international space station.
nemori
Posts: 2
Joined: Thu Nov 15, 2018 9:14 pm

Re: Problems with unstable rotation

Post by nemori »

Oh, wow, it kinda makes sense even though I wouldn't have believed it without that video :lol: Pretty crazy.

The extends were 5x3x1.25m and it was rotating along the same axis as the book in the video. Still, wow.

I have to say I'm actually quite impressed that Bullet simulates this correctly, I was trying to compare it to PhysX earlier and that did not, even though it wasn't exactly stable either.

Well, you learn something new every day. Thanks for the help 8)
Post Reply