tags:

views:

390

answers:

1

I dont really understand the method Matrix.Multiply(Matrix m) in C#.

Let say I have 2 matrices. 1 matrix is in world space and 1 matrix in local space, now I want to transform world space to local space or from local space to world space, what should I do with the Multiply method?

Matrix world = ....

Matrix local = ...

world.Multiply(local) 
// It means world*local or local*world and it will transform world space to 
// local or from local to world space?

Thank in advance.

+3  A: 

You don't want to multiply the matrixes if you want to transform one matrix into the other. You want to find the matrix you need to multiply one by to go from one to the other. Essentially, you want to solve the equation:

W * X = L

Where W is your world matrix and L is your local matrix. You're looking for matrix X. Solving for X:

W * X * 1/L = I 

Where I is the identity matrix and 1/L is the inverse of L So:

X = 1/W * L

Note that matrix multiplication is not commutative, so W * L is not the same, in general, as L * W.

codekaizen
+1 Especially for pointing out that matrix multiplication is not commutative
zebrabox