Sign in to follow this  
MooMansun

Matrix.Inverse Problem

Recommended Posts

OK, I have found that Matrix.Inverse(viewMatrix) will provide the world matrix. I now have the problem were my controls, linked to the viewmatrix, are messed up. I know that Matrix.Inverse(viewMatrix) is manipulating the matrix directly and causing the problem. How do I create a matrix that controls the inverse without screwin up the viewMatrix?

Share this post


Link to post
Share on other sites
Quote:
Original post by MooMansun
I have found that Matrix.Inverse(viewMatrix) will provide the world matrix.

Not to be rude, but that will return the inverse of the viewMatrix, not the world matrix.

You might want to use Device.GetTransform(TransformType.World) instead.

EDIT: Inverse is a non-const member function, so of course it's going to manipulate the data. If you want to continue your method, you'll have to either create a copy of the matrix and take the inverse of that, or un-inverse (re-inverse) the matrix after you're done with it.

Share this post


Link to post
Share on other sites
Hi there MooMansun,
How are you doing?

The Problem
Matrix.Inverse() returning unsuspected results

The Solution
Matrix.Invert Method.
so matView.Invert() will give you the inverse of the view matrix.
If you want to save the view matrix. Just do Matrix temp = matView; and then just use the temp.Invert(); method and pass temp to whatever method you want to give the inverse of the view matrix.


I hope that helps.
Take care buddy.
PS: It might help if you tell us what you are trying to do.

Share this post


Link to post
Share on other sites
Hi guys,

Sorry its late...

Device.GetTransform(TransformType.World) - This gives an error -2005530516(D3DERR_INVALIDCALL)

Matrix temp = matView - This method just creates another pointer and I end up with the same problem.

I am trying to pass the worldMatrix to a HLSL shader.

Thanks for help btw.

Share this post


Link to post
Share on other sites
Hi there MooMansun,
How are you doing?

The Problem
Passing a matrix to a shader.

The Solution
Normally you wouldn't get the transformation matrix of the world from your device but pass some entities. If you want to get it from your device to send to your shader you will want to make sure that the device has a world transformation matrix set. You can also use Device.Transform.World to get the world transformation matrix.

I would generally just do effect.SetValue("ModelWorldI", Matrix.Invert(Device.Transform.World));
if you want to send the inverse of the world matrix to the shader.

I hope this helps buddy.
Take care.

Share this post


Link to post
Share on other sites
Actually, I just need to be able to calculate the inverse of the current viewMatrix.

Btw, device.Transform.World resulted in the same (D3DERR_INVALIDCALL)

Found this at Microsoft -

Computation of Inverse World Matrix
The world matrix could be represented as:

Mw = Mwr * Mwt, where Mwr is the rotation part and Mwtb is the translation part.

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnardir3d/html/d3dlight3.asp

I think I have seen this formula before...

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