3d-matrices icon indicating copy to clipboard operation
3d-matrices copied to clipboard

M* doesn't respect multiplication order with vectors

Open lovrolu opened this issue 6 years ago • 0 comments

It seems that M* always multiplies vectors as if they were on the right-hand side.

The following:

(let ((vec (vec4 1 2 3 4))
      (mat (mat4 '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16))))
  (values (m* vec mat)
          (m* mat vec)))

produces the incorrect results:

(VEC4 30.0 70.0 110.0 150.0)
(VEC4 30.0 70.0 110.0 150.0)

instead of the correct:

(VEC4 90.0 100.0 110.0 120.0)
(VEC4 30.0 70.0 110.0 150.0)

The following, however:

(let ((mat1 (mat4 '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)))
      (mat2 (mat4 '(16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1))))
  (values (m* mat1 mat2)
          (m* mat2 mat1)))

gives the expected results:

(MAT4 #(80.0 70.0 60.0 50.0
        240.0 214.0 188.0 162.0
        400.0 358.0 316.0 274.0
        560.0 502.0 444.0 386.0))

(MAT4 #(386.0 444.0 502.0 560.0
        274.0 316.0 358.0 400.0
        162.0 188.0 214.0 240.0
        50.0 60.0 70.0 80.0))

lovrolu avatar Oct 27 '18 21:10 lovrolu