tf.SetRot bug?
#1
I'm beginning to suspect that the quaternion passed to tf.SetRot is an 'unexpected way around'?

Given 3dsmax uses a RHS with Z up, X to the left and Y out of the screen.  Then a rotation that maps the Z axis (0 0 1) to the X axis (1 0 0) I believe should be the quaternion (0 1 0 1).  But if I call tf.SetRot with that rotation it appears to result in the rotation of the Z axis (0 0 1) to the negative X axis (-1 0 0) instead.  Negating the w component to get the rotation (0 1 0 -1) corrects this.

I believe you may be using LHS code rather than RHS in your conversion from a quaternion to matrix.  When I manually convert the quaternions to matrices to set the transform matrix it works fine.  This is the RHS code I use:

static Matrix3 ToMatrix3(Quat q)
{
q = q.normalized;//If needed

Point3 row1 = new Point3(
        1.0f - 2.0f * q.y * q.y - 2.0f * q.z * q.z,
        2.0f * q.x * q.y + 2.0f * q.z * q.w,
        2.0f * q.x * q.z - 2.0f * q.y * q.w
    );

    Point3 row2 = new Point3(
        2.0f * q.x * q.y - 2.0f * q.z * q.w,
        1.0f - 2.0f * q.x * q.x - 2.0f * q.z * q.z,
        2.0f * q.y * q.z + 2.0f * q.x * q.w
    );

    Point3 row3 = new Point3(
        2.0f * q.x * q.z + 2.0f * q.y * q.w,
        2.0f * q.y * q.z - 2.0f * q.x * q.w,
        1.0f - 2.0f * q.x * q.x - 2.0f * q.y * q.y
    );

    Point3 row4 = new Point3(0, 0, 0);

    return new Matrix3(row1, row2, row3, row4);
}
  Reply
#2
Good catch...I'll double check what's going on. I think it might be related to the bug you caught here:

https://forum.tyflow.com/thread-3720.html

Some of the boiler-plate code I copied between functions to move quat values to/from C# had a typo. Not many people (including myself) work with quats directly so that's how it went unnoticed for so long.
  Reply


Forum Jump: