Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Grofit

Model View Matrixes etc....

This topic is 5370 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hmm right heres the other one of my problems... im using D3D v9 Ive got a shape class that just makes a cube or pyramid... i then want it to spin... but not spin anything else... so i made its own.... Matrix heres the basics // Being Code D3DXMATRIX Shape_ModelView; D3DXMatrixRotationY(&Shape_ModelView, (float) timeGetTime()/1000.0f); pD3DDevice->SetTransform(D3DTS_???????, &Shape_ModelView); // End code right as you can see above...ive got a shape model view matrix... and i set the rotation to rotate as time passes.. the thing that i dont seem to get to work is the Set Transform function... (pD3DDevice is a pre initilized D3D Device object) ..... Anyway Where the "????????" is thats where our kind of matrix is supposed to be... ive looked in MSDN and it says there are a huge list.. but the only relevent ones i can find are these: View Matrix World Matrix Project Matrix and a load of texture ones... if i use the D3DTS_WORLD then the shape rotates but everything else does as well... which is understandable as im rotating the world... but none of the other matrixes do anything..the shape just vanishes..lol I know in openGL you have to use LoadIdentity() and push and pop matrixes... should i have to do this in this kinda thing... I ultimatly want each 3d model/shape to have its own modelview matrix so i can rotate them indicidually and scale them etc, and translate them... but to do that i need to get individual matrixes working... so any help or example code on how to do this would be great... ive looked on lots of sites but they only really use the world to rotate things because they are basic tutorials and only need to rotate like 1 thing..... anyway ...thanks again...

Share this post


Link to post
Share on other sites
Advertisement
OpenGL uses a MODELVIEW matrix but D3D splits this matrix into two.

In D3D, you have a matrix that positions your model in the world. This matrix is called the model's "world matrix" because it positions the model in the world.

The second matrix D3D uses is the "view matrix". This matrix describes the location and orientation of the camera.

The idea is that every object in your scene has it's own world matrix (again, the world matrix is the matrix that positions objects in the 3D world). Here is some code to explain how you would render your scene. You don't have to implement your code like this. I just show it to you this way so you understand what I mean.

// Update the camera position and set the view matrix. This is
// usually done by...
D3DXMatrixLookAtLH( &m_matView, ....)
m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_matView );

for(int i = 0; i < NUM_MESHES; i++ )
{
D3DXMATRIX matWorld;
ZeroMemory( &matWorld, sizeof(D3DXMATRIX) );
MeshArray[ i ]->ComputeWorldMatrix( &matWorld );
m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
MeshArray[ i ]->Render();
}

You can set the projection matrix once during init and not worry about it again. This is usually done by something like
D3DXMatrixPerspectiveFovLH( &m_matProj, D3DX_PI/4.0f, width/height, 1.0f, 100.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJ, &m_matProj );

Hope this helps,
neneboricua

[edited by - neneboricua19 on February 6, 2004 3:14:00 PM]

Share this post


Link to post
Share on other sites
kinda...

i was originally using the WORLD matrix to rotate it..but it rotated EVERYTHING else in the scene... which was the pain.. i thought View was to deal with the camera...as im using it there... and i thought that Projection was just used to setup the scenes projection which is only used once...

But how do i stop one shapes world matrix interfearing with another shapes matrix... as i have a terrain mesh.. that seems to rotate WITH the shapes rotation... so is there a way to tell it to reset the current matrix so that it will only effect the Shape and nothing else?

Share this post


Link to post
Share on other sites
You are obviously forgetting to set a world matrix for every object in the scene. You need to set a DIFFERENT world matrix for each object to be in its correct position and orientation. How are you positioning objects right now? Are you just creating them with vertices out where you want it? If so, you probably shouldn't do that and should position them around 0,0,0 and use these world matrices to move them where they should be.

[edited by - Erzengeldeslichtes on February 6, 2004 3:32:06 PM]

Share this post


Link to post
Share on other sites
at the moment the shapes got a world matrix and i was in the process of putting a world matrix into terrain when i posted here to see if i was on the right tracks...

i shall go and implement it and get back to you..but i think youve told me enough to be getting on with...thanks...

Share this post


Link to post
Share on other sites
When you SetTransform(), you set the world matrix by which all vertices rendered after the call will be transformed by. Therefore, to 'end' a rotation, simply call SetTransform() with a NULL matrix pointer, which is indicative of the indentity matrix. This will 'cancel' the rotation instead of 'replacing' one rotation with another.

EDIT:
The final function call would be:

pDevice->SetTransform( D3DTS_WORLD, NULL );

to clear the current world matrix.


Chris Pergrossi
My Realm | "Good Morning, Dave"

[edited by - c t o a n on February 7, 2004 5:24:37 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!