Questions about constraints
Posted: Fri Feb 19, 2016 6:18 pm
Hi everyone, I'm currently trying to wrap bullet for a personal project and I have a few questions regarding constraints:
1. Are there any major performance differences between the different constraints? I want to make the wrapper as simple as possible and wanted to only use the btGeneric6DofConstraint and lock whatever axes I needed. Is this a good approach? Would I be better off creating cases and utilizing each of the constraints for special cases?
2. How do you stop or slow down a constrained object? I created a swinging box using the btGeneric6DofConstraint and applied a force and the swinging didn't stop (maybe I didn't wait long enough (~10-15 min)). Do I need to manually apply a counter force?
3. My next question is regarding the frameInA and frameInB parameters of the btGeneric6DofConstraint constructor. First I tried using the method in Dof6SpringSetup.cpp in \examples\Constraints
While it works the movement of the object becomes unstable over time.
Next I tried rponomarev's suggestion in this discussion, which solved my problems, but I don't understand the following section very well:
I dont understand how the "parentAxis" and "childAxis" are chosen. From what I gather they are used to create a matrix to transform obj1 and obj2 from world space to joint space. Is this correct? Where do the "parentAxis" and "childAxis" come from?
4. Finally, should I use btGeneric6DofSpring2Constraint instead? I know its more stable, but the documentation says its also slower.
I'd be grateful for any insight.
1. Are there any major performance differences between the different constraints? I want to make the wrapper as simple as possible and wanted to only use the btGeneric6DofConstraint and lock whatever axes I needed. Is this a good approach? Would I be better off creating cases and utilizing each of the constraints for special cases?
2. How do you stop or slow down a constrained object? I created a swinging box using the btGeneric6DofConstraint and applied a force and the swinging didn't stop (maybe I didn't wait long enough (~10-15 min)). Do I need to manually apply a counter force?
3. My next question is regarding the frameInA and frameInB parameters of the btGeneric6DofConstraint constructor. First I tried using the method in Dof6SpringSetup.cpp in \examples\Constraints
Code: Select all
btTransform frameInA, frameInB;
frameInA.setIdentity();
frameInA.getOrigin() = btVector3(0, -5, 0);
frameInB.setIdentity();
frameInB.setOrigin(btVector3(0, 4, 0));
Next I tried rponomarev's suggestion in this discussion, which solved my problems, but I don't understand the following section very well:
Code: Select all
btVector3 parentAxis(1.f, 0.f, 0.f);
btVector3 childAxis(0.f, 0.f, 1.f);
btVector3 anchor(0.f, 2.f, 0.f);
// build frame basis
// 6DOF constraint uses Euler angles and to define limits
// it is assumed that rotational order is :
// Z - first, allowed limits are (-PI,PI);
// new position of Y - second (allowed limits are (-PI/2 + epsilon, PI/2 - epsilon), where epsilon is a small positive number
// used to prevent constraint from instability on poles;
// new position of X, allowed limits are (-PI,PI);
// So to simulate ODE Universal joint we should use parent axis as Z, child axis as Y and limit all other DOFs
// Build the frame in world coordinate system first
btVector3 zAxis = parentAxis.normalize();
btVector3 yAxis = childAxis.normalize();
btVector3 xAxis = yAxis.cross(zAxis); // we want right coordinate system
btTransform frameInW;
frameInW.setIdentity();
frameInW.getBasis().setValue( xAxis[0], yAxis[0], zAxis[0],
xAxis[1], yAxis[1], zAxis[1],
xAxis[2], yAxis[2], zAxis[2]);
frameInW.setOrigin(anchor);
// now get constraint frame in local coordinate systems
btTransform frameInA = pBodyA->getCenterOfMassTransform().inverse() * frameInW;
btTransform frameInB = pBodyB->getCenterOfMassTransform().inverse() * frameInW;
4. Finally, should I use btGeneric6DofSpring2Constraint instead? I know its more stable, but the documentation says its also slower.
I'd be grateful for any insight.