Code: Select all
set
{
entity.Position = value;
// If we are allowing object to be translated when it possesses a joint
if (joint != null)
{
Vector3 jP = joint.AngularJoint.ConnectionA.Position + joint.BallSocketJoint.OffsetA;
Vector3 freeAxis = joint.AngularJoint.WorldFreeAxisA;
game.Space.Remove(joint);
// Anchor must be translated if the entity is moved
// Free axis argument must be in world space
joint = new RevoluteJoint(entity, null, jP, freeAxis);
game.Space.Add(joint);
}
}
Code: Select all
qDiff = Quaternion.Conjugate(entity.Orientation);
joint = value;
Code: Select all
set
{
entity.Orientation = value;
if (joint != null)
{
Vector3 jP = joint.AngularJoint.ConnectionA.Position + joint.BallSocketJoint.OffsetA;
Vector3 freeAxis = joint.AngularJoint.WorldFreeAxisA;
game.Space.Remove(joint);
Quaternion newOrientation = entity.Orientation * qDiff;
// Anchor and free axis must be rotated if the entity is rotated
Matrix m = Matrix.CreateFromQuaternion(newOrientation);
joint = new RevoluteJoint(
entity,
null,
Vector3.Transform(jP, m), // Error
Vector3.TransformNormal(freeAxis, m) // Error
);
game.Space.Add(joint);
}
}
I have tested the code above with a child entity. Its orientation will correctly rotate relative to its parent's orientation so the orientation values are correct.
However, when transforming the normal and anchor point by the same rotation matrix it will not work as intended. How can I apply the same method to the RevoluteJoint class?