Matrix multiplication - Scene Graphs

Posted by bgarate on Game Development See other posts from Game Development or by bgarate
Published on 2013-06-25T15:39:41Z Indexed on 2013/06/25 16:30 UTC
Read the original article Hit count: 359

Filed under:
|
|
|

I wrote a MatrixStack class in C# to use in a SceneGraph. So, to get the world matrix for an object I am suposed to use:

WorldMatrix = ParentWorld * LocalTransform

But, in fact, it only works as expected when I do the other way:

WorldMatrix = LocalTransform * ParentWorld

Mi code is:

public class MatrixStack
{
    Stack<Matrix> stack = new Stack<Matrix>();
    Matrix result = Matrix.Identity;

    public void PushMatrix(Matrix matrix)
    {
        stack.Push(matrix);
        result = matrix * result;
    }

    public Matrix PopMatrix()
    {
        result = Matrix.Invert(stack.Peek()) * result;
        return stack.Pop();
    }

    public Matrix Result
    {
        get { return result; }
    }

    public void Clear()
    {
        stack.Clear();
        result = Matrix.Identity;
    }
}

Why it works this way and not the other? Thanks!

© Game Development or respective owner

Related posts about c#

Related posts about math