Sign in to follow this  
MooMansun

Calculating WorldView

Recommended Posts

MooMansun    100
Hi, I need to calculate the WorldView/World Matrix to output to a HLSL shader. I am using a First person viewmatrix as the camera. Use this as your example equation: effect.SetValue("worldViewProjection", WorldMatrix * viewMatrix * camera.ProjectionMatrix); How is it done?

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by MooMansun
Will Matrix.Identity return the worldMatrix?

No. The "Identity Matrix" is a special property of any mathematically defined matrix where row==column=1.0 [smile]

Quote:
effect.SetValue("worldViewProjection", WorldMatrix * viewMatrix * camera.ProjectionMatrix);

The above fragment is, as planely read, the world view projection matrix. To be what you describe in your post you'd have to drop the camera.ProjectionMatrix part.

I'm not entirely sure what you're asking though.

You've got a "world view" matrix - that is the World*View matrix? and you want to set this to an HLSL shader? if so, just set the results of World*View to whatever the appropriate constant name is in your HLSL script..??

hth
Jack

Share this post


Link to post
Share on other sites
MooMansun    100
I just want to calculate the 'WorldMatrix' so that I can insert the result into the command.

"effect.SetValue("worldViewProjection", WorldMatrix * viewMatrix * camera.ProjectionMatrix);"

If I have a mesh in memory, how do I calculate its worldMatrix?

Share this post


Link to post
Share on other sites
MooMansun    100
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
jlgosse    130
Although I haven't really started game development yet, I have some advice for you.

Read up on your linear algebra and specifically mathematics involving matrices and vectors. It will be SO much easier on you, I hear.

Share this post


Link to post
Share on other sites
MooMansun    100
I understand the math, that's a pinch. I'm having a problem creating a second matrix to control the World.

The viewMatrices inverse is the world matrix. I need to control both, not one or the other. When I call Matrix.Invert(viewMatrix), it does not return a new Matrix for the worldMatrix, it inverts the viewMatrix.

Now when I try control the viewMatrix, I am controlling what should be the worldMatrix.

I know in other languages I could copy the memory, but I'm using c# at the moment.

Share this post


Link to post
Share on other sites
MooMansun    100
If I were to put it C++ terms. The viewMatrix is a pointer to the Matrix held in memory. When I try to create a Matrix which is a pointer to worldMatrix (inverted viewMatrix), I only end up manipulating the viewMatrix.

Do I need to implement a MatrixStack?
Will this allow me to control both the viewMatrix and the worldMatrix?

Share this post


Link to post
Share on other sites
neneboricua19    634
You've got a few things confused. The inverse of the view matrix is NOT equal to the world matrix. The world matrix is used to position your models throughout the scene. Each object you render will have its own world matrix. The view matrix describes the position and orientation of the camera. This matrix will stay the same for the whole frame.

Again, the world matrix is used to position your models inside the scene. In mathematical terms, the world matrix transforms vertices from model-space to world space. Each object in your scene will have its own world matrix so that you can position it where ever you want when rendering.

neneboricua

Share this post


Link to post
Share on other sites
MooMansun    100
It was near 4 or 5am when I wrote that, not thinking straight.

I posted this elsewhere:

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
MooMansun    100
Great, I'm back were I started. How can I calculate the current worldMatrix without effecting the matrix in memory.

I'm using pure hardware VP and get commands are not an option. Device.Transform.World fails, passing the value to a temp store only gives me an additional pointer....

Lang: c#

Help anyone???

Share this post


Link to post
Share on other sites
neneboricua19    634
The link you posted is to a document that is over 7 years old. There have been over a dozen SDK releases since then! The document is severely out of date.

The part of the docs that you quoted was this:
Quote:
From http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnardir3d/html/d3dlight3.asp
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.

Mwr is a matrix with just the rotation part of the world matrix, and Mwt is a matrix with just the translation part of the world matrix. In no way does this imply that you can get the world matrix by taking the inverse of the view matrix.

Like someone else has already said; you need to have a basic understanding of linear algebra to do this.

Applications should not need to call GetTransform... or whatever, to get the world matrix of an object. Each object in your scene should have its own world matrix. The world matrix is used to transform geometry to different parts of the scene.

What is it about this explanation that you don't understand? Perhaps myself and the others that have posted in this thread and your other identical thread (http://www.gamedev.net/community/forums/topic.asp?topic_id=349970) have not been clear? If you're not sure about something ask, but don't just ask the same question multiple times hoping for a different answer when it has already been answered multiple times in the same way by different people.

neneboricua

Share this post


Link to post
Share on other sites
thezbuffer    706
Quote:
Original post by neneboricua19
What is it about this explanation that you don't understand? Perhaps myself and the others that have posted in this thread and your other identical thread (http://www.gamedev.net/community/forums/topic.asp?topic_id=349970) have not been clear? If you're not sure about something ask, but don't just ask the same question multiple times hoping for a different answer when it has already been answered multiple times in the same way by different people.
neneboricua


Not just here - he's at it in the newsgroups too:
Moo's newsgroup argument

Share this post


Link to post
Share on other sites
MooMansun    100
ZBuffer,

The answers provided have not provided a solution to my problem.

They either fail or they just effect the Matrix in memory.

Read a little more carefully.

I need to obtain the worldView Matrix, however, under pure hw vp any matrix operation effects the Matrix in memory.

Is there a way around this?

Share this post


Link to post
Share on other sites
MooMansun    100
Here, I have found someone else who says the worldMatrix is the inverse of the viewMatrix, their name is WitchLord (Moderator)...

Quote:
"I also advice you to take a look at the following matrix structures for the worldmatrix and viewmatrix:

World Matrix
View Matrix

See the similarities? The view matrix is in fact the inverse of the world matrix."

http://www.gamedev.net/community/forums/topic.asp?topic_id=15526&forum_id=10&gforum_id=

Share this post


Link to post
Share on other sites
MooMansun    100
Think of it a different way, since it is just a Matrix, is there any Math operation which would return the inverted values?

Something like Math.Matrix.Invert(Matrix) would be handy...

Share this post


Link to post
Share on other sites
MooMansun    100
neneboricua:
"Applications should not need to call GetTransform... or whatever, to get the world matrix of an object. Each object in your scene should have its own world matrix. The world matrix is used to transform geometry to different parts of the scene."

This I know, however, you need to calculate the world matrix in order to have one. We were attempting to use GetTransform to obtain it.

So, before we end up flaming each other, I will keep it simple and ask one question at a time.

1. How do you calculate the worldMatrix of a loaded mesh?

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by MooMansun
you need to calculate the world matrix in order to have one. We were attempting to use GetTransform to obtain it.

This sounds like an infinite catch-22 loop to me [smile]

Provided you're not running a pure device, then calling GetTransform() where you haven't already set one should return a default. Off the top of my head, I think you'd just end up with the identity matrix.

Quote:
Original post by MooMansun
1. How do you calculate the worldMatrix of a loaded mesh?

Build it using whatever information is available.

Some mesh formats will export, from the modeller, a set of matrices (bone/skeletal meshes are a good example of this) that you can read from the specific file format. If there isn't any information in the file you're loading, then you might want to look at the "level" data - there could be position/rotation/scale information in the level indicating where the current mesh is.

Failing those, Just assume an identity world matrix for the mesh..

An example I have kicking around stores 3 vectors with a mesh - rotation, scaling and translation. I have a copy of these 3 vectors with every instance of the mesh that is loaded. If I choose to move that mesh around at runtime then I alter one (or more) of those 3 vectors.

When it comes to rendering, calls to D3DXMatrixIdentity(), D3DXMatrixMultiply(), D3DXMatrixScaling(), D3DXMatrixTranslation(), D3DXMatrixRotation*() are used to create the world matrix for that mesh. I then SetTransform() this matrix (or apply it to the vshader constant table) and render...

hth
Jack

Share this post


Link to post
Share on other sites
MooMansun    100
Thanks guys,

It is a bit like the chicken and the egg. I am sure it can be done. I am running a pure device, which means any matrix operation effects the Matrix in memory.

Just for tonight, I am abandoning this DX9c thing for 'Team America', I need a good laugh and I'm sure something will come to me...

Again, thanks for all your help, chat later...

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