Sign in to follow this  

Matrix Inversion XNA

Recommended Posts

I have two functions for setting rendering transformations in my scene graph that are called before every scene node is rendered:

 public virtual void PreRender(Scene scene)
            // push a copy of the top matrix onto the stack
            scene.MatrixStack.Push ();
            // multiply that matrix with the one that
            // is already there and replace it with the result
            scene.MatrixStack.MultMatrix ( this.sceneProps.ParentSpaceMatrix );
            Matrix WorldTrans = scene.MatrixStack.Peek();

            //translate world space into screen space
            Matrix ScreenMat = scene.Camera.TransformToScreen(WorldTrans);

            // now this node is the root of whatever is drawn after it
            scene.Transform *= ScreenMat;

        public virtual void PostRender(Scene scene)
            // Pop the top matrix off of the stack and get us back up the tree
            scene.MatrixStack.Pop ();
            // ***Now here is the trouble spot***
            // I need to undo the transformation I just did in prerender
            // so I invert the matrix
            Matrix TransMat = Matrix.Invert ( scene.Transform );


I would think that finding the inverse of a matrix each time I rendered a scene node would make my game incredibly slow. I have heard that it could be done quickly for transformation matrices by swapping their rows and collumns or something like that. My questions are: Does XNA take advantage of what I just mentioned and make finding the inverse of a transformation matrix speedy? Is this the right way to go about un doing transformations?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this