Slider alignment question

SatelliteBiker
Posts: 7
Joined: Wed Jan 20, 2010 2:30 pm

Slider alignment question

Post by SatelliteBiker »

I've now mostly ported a small sim from ODE to bullet. I'm now rewriting the joints/constraints to finish it up, so there's a lot of learning going on. This is with Bullet 2.75.

I wrote a small test program that made an animated windmill: The tower was a simple static shape, and the blade was a dynamic shape, constrained to the top of the tower with a hinge. I tested the various ways to define the blade (in it's local coords), and transforming that to align with the tower's pivot point. That wasn't too difficult, just had to figure it out.

Back to the sim... Right now there are no constraints, so as soon as the sim is unpaused all the dynamic objects fall to the ground as expected. One of these objects is a heavy counter weight, which I need to constrain to the vertical axis. In my sim, the XY plane is the ground plane, and +Z is up. So as I understand it, I should make a coord frame for the counter weight, with its +X axis aligned to the world's +Z. Here's how I'm doing it:

Code: Select all

        // CW to world via slider. (Rotate frame around Y(-90) to align X with world Z.)
        btTransform frame;
        frame.setIdentity();
        frame.setRotation( btQuaternion( btVector3(0, 1, 0), -M_PI/2.0) );
        btSliderConstraint *slider = new btSliderConstraint( *cw_body, frame, false);
        m_world->addConstraint(slider);
I don't know what's happening now, but when the sim starts all of the objects except the counter weight fall as before, and the counterweight object just disappears out of view. I haven't looked at its position/velocity yet, but will later.

As for the above code, is my alignment right? Is that how one constrains an object to the world with a slider with the coord system I'm using?

Any comments appreciated.
SatelliteBiker
Posts: 7
Joined: Wed Jan 20, 2010 2:30 pm

Re: Slider alignment question

Post by SatelliteBiker »

I decided to try something else. I added a massless static body to serve as an "anchoring body" for this vertical slider. My counterweight now falls constrained to the vertical axis as I want.

Again, this is with 2.75. Is this a known issue? I've not tried it with 2.76 yet.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Slider alignment question

Post by Erwin Coumans »

We will have a closer look at your issue on Monday, but in the meanwhile can you please try it with the latest Bullet 2.76 beta?

Perhaps useful: if you deal with the special case of locking motion along one (or more) of the world axis, there is another way using setLinearFactor/setAngularFactor. You can specify for each component (X,Y,Z) to allow motion (1) or disallow motion(0). For example, the Box2dDemo locks motion in the X,Y plane, and only allow rotation along the Z axis:

Code: Select all

body->setLinearFactor(btVector3(1,1,0));
body->setAngularFactor(btVector3(0,0,1));
Thanks,
Erwin
SatelliteBiker
Posts: 7
Joined: Wed Jan 20, 2010 2:30 pm

Re: Slider alignment question

Post by SatelliteBiker »

I was unaware of the linear and angular factors, they look like a simpler solution.

I'll try that, as well as my test cases on 2.76 this week.

Thank you, Erwin.
User avatar
rponomarev
Posts: 56
Joined: Sat Mar 08, 2008 12:37 am

Re: Slider alignment question

Post by rponomarev »

Hello,

I think this is known issue of r2.75
The constructor

Code: Select all

btSliderConstraint::btSliderConstraint(btRigidBody& , const btTransform& , bool )
does not initialize m_frameInA properly, so you have junk there at simulation start time
However constructor

Code: Select all

btSliderConstraint::btSliderConstraint(btRigidBody& , btRigidBody& , const btTransform&, const btTransform& , bool)
should work properly. You could use body B of mass 0 and NULL shape if you want to work with 2.75
This should be fixed in 2.76

Thanks,
Roman