Problem with btCompoundShape

AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Problem with btCompoundShape

Post by AlexSilverman »

Hello,

I'm trying to add compound objects into our game, and I'm seeing some odd behavior that I'm not sure how to get around, short of using dynamic mesh objects.

I create a compound object to model a dart, using the following code to create the shape.

Code: Select all

		btCompoundShape * compoundShape = new btCompoundShape();
		btTransform tr;
		tr.setIdentity();

		tr.setOrigin(btVector3(0,0.33567*10,0));
		compoundShape->addChildShape(tr,new btBoxShape(btVector3(0.0207*10,0.0923*10,0.0207*10)));
		tr.setOrigin(btVector3(0.043*10,0.226*10,0));
		compoundShape->addChildShape(tr,new btBoxShape(btVector3(0.07335*10,0.1273*10,0.0127*10)));
		tr.setOrigin(btVector3(-0.043*10,0.226*10,0));
		compoundShape->addChildShape(tr,new btBoxShape(btVector3(-0.07335*10,0.1273*10,0.0127*10)));
		tr.setOrigin(btVector3(0,0.226*10,0.043*10));
		compoundShape->addChildShape(tr,new btBoxShape(btVector3(0.0127*10,0.1273*10,0.07335*10)));
		tr.setOrigin(btVector3(0,0.226*10,-0.043*10));
		compoundShape->addChildShape(tr,new btBoxShape(btVector3(0.0127*10,0.1273*10,-0.07335*10)));
		tr.setOrigin(btVector3(0,0.0996542*10,0));
		compoundShape->addChildShape(tr,new btBoxShape(btVector3(0.0326*10,0.125126*10,0.0326*10)));
		tr.setOrigin(btVector3(0,-0.010882*10,0));
		compoundShape->addChildShape(tr,new btBoxShape(btVector3(0.01246*10,0.0959464*10,0.01246*10)));

I scaled all the numbers by 10 so the dart would be more visible, but in the game they will not be scaled thusly. The objects are organized with one box on top, four boxes for the blades of the dart, another object for the stem, and another object for the needle, with the center of mass being roughly at the center of the needle. What I'm seeing is that the blades of the dart are passing through the ground (modeled as a box) as the dart spins to rest on its side. I added the code above to DemoApplication::shootBox, so that the right mouse button now fires darts, and I can see the same behavior in all demos. Does anyone know a way around this problem? I haven't changed anything in the demos, except inserting the code to make the darts fire instead of boxes.

Thanks. Let me know if you need more info.

- Alex
binofet
Posts: 20
Joined: Fri Jun 15, 2007 5:03 pm

Post by binofet »

The problem is that you are passing negative values in the btBoxShape constructor. The vector that gets passed in that constructor just represents lengths (or half-lengths) on x, y, and z axii. It should assert that they are non-negative as you can't have a length < 0. I tested your compound shape in the shootBox() method and it works as you'd expect if you remove the negative signs. :D

Happy trails,

binofet
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Post by AlexSilverman »

Ah. That should have occurred to me :) I didn't get an assertion on the negative values for some reason, but this makes a lot of sense. Thanks. I'll test it out when I get to work, but I expect everything will be ok.

- Alex
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Post by AlexSilverman »

Ok, so that worked perfectly. Thanks again, and that leads me to another question about the same object. The dart in question is a lawn dart, and they're usually grasped by the end opposite the needle, and thrown into the air, so that the needle leads, and the tail follows it roughly in a line tangent to the curve of the arc.

When I propel the darts (by applying forces) in my game, they maintain the same orientation throughout the time they're in the air. What I would expect is for gravity to act more on the needle (where the center of mass is) and less on the tail, so that if the thing is thrown straight up, it flips its orientation on its way down. Is there a way to get this behavior out of Bullet, or is my only option to fake it and construct the orientation from the current and previous positions of the dart?

Thanks.

- Alex
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Post by bone »

Gravity pulls straight down on everything, it wouldn't change the orientation. What changes the orientation of a lawn dart is the wind resistance of the blades. The aerodynamics forces on the blades are behind the center-of-gravity, stabilizing it so it follows the nose (like a rocket, this is why the blades are there!)
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Post by AlexSilverman »

Oh, right. I forgot all about those real world forces that aren't generally simulated, like wind resistance. Bullet doesn't have anything for that, does it? :) It's doubtful, but I had to ask.

Thanks. Off to experiment with an approximation.

- Alex
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Haha, no there isn't a default wind/friction force field.

But it should be possible to apply an impulse (or force) at the right location and direction (opposite to the linear motion, and counter acting rotation along the axis). Would be fun to see some demo of this!

Thanks,
Erwin
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Post by AlexSilverman »

I was actually thinking of applying some torque proportional to how far from "upright" the falling lawn dart is, but I'll look at the method you mentioned as well. The effect should be much the same I would think.

Thanks.

- Alex