Skip to content

Incorrect matrix multiplication order in Object3D::updateMatrix #19

@thorlancaster

Description

@thorlancaster

Problem I Observed:

An Object3D (the parent) has children with nonzero position.
When an parent's quaternion is rotated using quaternion.fromEuler(x, y, z), the children rotate WRT their own origin instead of the parent's origin. The children should rotate with respect to the parent's origin when the parent has the rotation applied.

Issue I found:

The multiplication order is wrong in Object3D::updateMatrix(). The multiply() call needs to multiply in the reverse order.

Proposed solution:

  • Change multiply() call in Object3D::updateMatrix() to this.matrix.multiply(this.parent.matrix, true)
  • Implement following change in Matrix4::multiply() parameters:
    /**
    * Multiplies a scalar or {@link Matrix4}.
    * @param t Scalar or Matrix4 to multiply by
    * @param r Reverse multiplication order (pre-multiply). Optional.
    */
    multiply(t: number | Matrix4, r?: boolean): this {...
  • Implement following change in Matrix4::multiply() body:
    const [m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33] = r ? t : this
    const [t00, t01, t02, t03, t10, t11, t12, t13, t20, t21, t22, t23, t30, t31, t32, t33] = r ? this : t

Results:

Transformations are now applied in the correct order. I would have submitted a PR for this but it's a small change and I obtained the library by downloading the raw files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions