Model View Matrixes etc....

Started by
5 comments, last by Grofit 20 years, 2 months ago
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...
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->ComputeWorldMatrix( &matWorld );<br>  m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );<br>  MeshArray->Render();<br>}<br>  </pre>  <br>You can set the projection matrix &#111;nce during init and not worry about it again.  This is usually done by something like<br>D3DXMatrixPerspectiveFovLH( &m_matProj, D3DX_PI/4.0f, width/height, 1.0f, 100.0f );<br>m_pd3dDevice->SetTransform( D3DTS_PROJ, &m_matProj );<br><br>Hope this helps,<br>neneboricua      <br><br><SPAN CLASS=editedby>[edited by - neneboricua19 on February 6, 2004 3:14:00 PM]</SPAN>
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?
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]
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
Stated somewhat differently:
The WORLD transform transforms your model from Model Space to World Space.

Once set, that transform will be used for all subsequent rendering until you set another World Matrix.

This article might help to sort it all out for you:
http://www.drunkenhyena.com/cgi-bin/view_article.pl?article=14


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
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...
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]
Chris PergrossiMy Realm | "Good Morning, Dave"

This topic is closed to new replies.

Advertisement