Attempting to restrict movement and rotation of the constraint in all 3 axis.

I'm able to get the positioning of the rigid bodies correct, however rotations I'm not sure about...

Code: Select all

```
PrimaryNode->_RigidBody->activate();
SecondaryNode->_RigidBody->activate();
btTransform PrimaryFrame, SecondaryFrame;
PrimaryFrame = PrimaryNode->_RigidBody->getWorldTransform();
SecondaryFrame = SecondaryNode->_RigidBody->getWorldTransform();
// ========== Calculate Frame Positions ==========
//
// Get the position of our two nodes
btVector3 PrimaryPos = PrimaryFrame.getOrigin();
btVector3 SecondaryPos = SecondaryFrame.getOrigin();
//
// Get the distance between each node
btScalar Dist = btDistance(PrimaryPos, SecondaryPos);
//
// Calculate the vector pointing towards each node
btVector3 PrimaryDir = (SecondaryPos - PrimaryPos).normalize();
btVector3 SecondaryDir = (PrimaryPos - SecondaryPos).normalize();
//
// Set the origin for our constraints equal to
// the midpoint position between each node
PrimaryFrame.setOrigin(PrimaryDir * (Dist/2));
SecondaryFrame.setOrigin(SecondaryDir * (Dist/2));
//
// ========== Calculate Frame Rotations ==========
//
btQuaternion PrimaryRot = PrimaryFrame.getRotation();
btQuaternion SecondaryRot = SecondaryFrame.getRotation();
//
// not sure what to do :P
SecondaryFrame.setRotation(PrimaryRot - SecondaryRot);
PrimaryFrame.setRotation(SecondaryRot - PrimaryRot);
btGeneric6DofConstraint* Constraint = new btGeneric6DofConstraint(
*PrimaryNode->_RigidBody,
*SecondaryNode->_RigidBody,
PrimaryFrame,
SecondaryFrame,
true
);
Constraint->setAngularLowerLimit(btVector3(0, 0, 0));
Constraint->setAngularUpperLimit(btVector3(0, 0, 0));
Constraint->setLinearLowerLimit(btVector3(0, 0, 0));
Constraint->setLinearUpperLimit(btVector3(0, 0, 0));
_Physics->dynamicsWorld->addConstraint(Constraint, true);
}
```

Not sure what maths needs to be done to adjust rotation of 'PrimaryFrame' and 'SecondaryFrame' so that when the constraint is created, the rigid bodies rotations are unaffected.

https://i.imgur.com/cVBW812.mp4

Upon selecting the first node, then selecting the second node we apply the constraint. Each node should not move or rotate after the constraint is applied. They should appear to be 'welded/parented' together. Unfortunately each nodes rotation goes crazy, applying a random force, and shooting the pair of nodes off into the distance..