Slider Constraints / Using btMatrix.setEulerZYX

Post Reply
Silverlan
Posts: 27
Joined: Thu Oct 30, 2014 9:15 pm

Slider Constraints / Using btMatrix.setEulerZYX

Post by Silverlan »

I'm trying to figure out how to create a slider constraint, but so far none of my attempts have worked properly.

In the fork lift demo from the SDK, the slider constraint for the fork is set up like this:

Code: Select all

btTransform localA;
btTransform localB;
[...]
localA.setIdentity();
localB.setIdentity();
localA.getBasis().setEulerZYX(0, 0, M_PI_2);
localA.setOrigin(btVector3(0.0f, -1.9f, 0.05f));
localB.getBasis().setEulerZYX(0, 0, M_PI_2);
localB.setOrigin(btVector3(0.0, 0.0, -0.1));
m_forkSlider = new btSliderConstraint(*m_liftBody, *m_forkBody, localA, localB, true);
m_forkSlider->setLowerLinLimit(0.1f);
m_forkSlider->setUpperLinLimit(0.1f);
m_forkSlider->setLowerAngLimit(0.0f);
m_forkSlider->setUpperAngLimit(0.0f);
m_dynamicsWorld->addConstraint(m_forkSlider, true);
The parameters to create a new slider constraint are:
btSliderConstraint (btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
In the demo, the slide direction is set up with these two lines:

Code: Select all

localA.getBasis().setEulerZYX(0, 0, M_PI_2);
[...]
localB.getBasis().setEulerZYX(0, 0, M_PI_2);
I'm assuming these are euler angles with z = pitch, y = yaw and x = roll.
In this case the fork is moving upwards and downwards.
Changing it to (M_PI_2, 0, 0) allows it to move left / right, and with (0, M_PI_2, 0) it's forward / backward.

M_PI_2 is a rotation of 90 degrees so that makes sense to me. Problem is, this only seems to work if the angles are aligned on an axis, meaning something like (M_PI_4, M_PI_2, 0) ends up doing the same as (0, M_PI_2, 0), which I don't really understand.

Could someone please enlighten me on how to actually use setEulerZYX, or how to set up the slider constraint for a specific (non-world-axis-aligned) axis?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Slider Constraints / Using btMatrix.setEulerZYX

Post by Basroil »

Silverlan wrote: Could someone please enlighten me on how to actually use setEulerZYX, or how to set up the slider constraint for a specific (non-world-axis-aligned) axis?
Joint axis are not "world-axis-aligned", rather local axis definitions based on bodies that just happen to be world aligned. Hinges always rotate about Z, sliders should move along x (haven't used them, so sliding axis may be different), and all your definitions do is change the direction of the local joint axis. I suggest taking a look at the dynamic control demo to see how to define joints procedurally based on initial angle/distance.
Silverlan
Posts: 27
Joined: Thu Oct 30, 2014 9:15 pm

Re: Slider Constraints / Using btMatrix.setEulerZYX

Post by Silverlan »

Basroil wrote:I suggest taking a look at the dynamic control demo to see how to define joints procedurally based on initial angle/distance.
Which one is that? I don't seem to have a demo with that name.

I noticed there's a slider constraint demo, but they just use identity transforms, so that doesn't help a lot:

Code: Select all

	btTransform trans;
	trans.setIdentity();
	btVector3 worldPos(-20,0,0);
	trans.setOrigin(worldPos);
	btTransform frameInA, frameInB;
	frameInA = btTransform::getIdentity();
	frameInB = btTransform::getIdentity();

	btRigidBody* pRbA1 = localCreateRigidBody(mass, trans, shape);
	pRbA1->setActivationState(DISABLE_DEACTIVATION);

	// add dynamic rigid body B1
	worldPos.setValue(-30,0,0);
	trans.setOrigin(worldPos);
	btRigidBody* pRbB1 = localCreateRigidBody(mass, trans, shape);
	pRbB1->setActivationState(DISABLE_DEACTIVATION);

	// create slider constraint between A1 and B1 and add it to world
	spSlider1 = new btSliderConstraint(*pRbA1, *pRbB1, frameInA, frameInB, true);
	spSlider1->setLowerLinLimit(-15.0F);
	spSlider1->setUpperLinLimit(-5.0F);

	spSlider1->setLowerAngLimit(-SIMD_PI / 3.0F);
	spSlider1->setUpperAngLimit( SIMD_PI / 3.0F);
Post Reply