2 mesh objects movement

Started by
3 comments, last by jagguy2 16 years, 3 months ago
hi, q1)I can move the camera around to user input. What i have is 2 mesh objects on screen. when i hit a button i want 1 of the objects to rotate on its own. How do i specify which object to move because using the rotation command it doesnt specify what object to rotate? D3DXMatrixRotationY(&Rot, rot_y);//i want to say what object q2) where do i find out the size of the world eg how far does the Z-axis extend into the screen or how far can i move to the right of screen?
Advertisement
Do you understand how matrices are used to position and orient the vertices of objects? Traditionally the idea is that for each object you have a world matrix that transforms it from object space (which is where the vertices are originally positioned, usually centered around the point <0,0,0>) to world space (where you actually want it in your scene relative to all other objects).

This transformation usually consists of a translation and a rotation. An easy way to handle this is to use the D3DXMatrix functions to create a matrix for your rotation and a matrix for your translation and then multiply them. This code, for example, would rotate an object 90 degrees about the Y axis and move it to the point <5,0,0>:

D3DXMATRIXA16 matRotation;D3DXMATRIXA16 matTranslation;D3DXMATRIXA16 matWorld;D3DXMatrixRotationY(&matRotation, D3DX_PI/2.0f);D3DXMatrixTranslation(&matTranslation, 5, 0, 0);matWorld = matRotation * matTranslation;


Then once you've created a world matrix for a particular object, you apply it before drawing that object so that it will transform all of the vertices. How you apply it will depend on whether you're using D3D9 or D3D10 and whether you're using shaders or the fixed-function pipeline. But either way the process is like this:

-Set View Matrix-Set Projection Matrix-Set World Matrix for Object 1-Draw Object 1-Set World Matrix for Object 2-Draw Object 2


If any of this seems very new to you or you don't understand how the matrix/vector math works, I definitely suggest you take the time to research the topic and develop a good grasp of it. As you progress to more advanced topics in graphics understanding the fundamental math will become more and more important.

thanks for the reply but sorry to be difficult that wasnt my question exactly.

I know you can simply reposition stationary objects using world view matrix of translations and rotations.

My problem is that I want each object to respond to different keys that move the object (not the camera). Like a cube that spins a if i press a button.

My problem is that i get all objects to move but i just want 1 object, as i make a call to rotation but all objects move.

How can i move just a specific object with user interaction?


 g_pd3dDevice->BeginScene();	setMatrices();	keys();	g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );			for(int i = 0; i < NumSubsets; i++)		{			g_pd3dDevice->SetTexture( 0, g_tex );			g_mesh->DrawSubset( i );		}	setMatrices();		keys();	for(int i = 0; i < NumSubsets2; i++)		{			g_pd3dDevice->SetTexture( 0, g_tex );			g_mesh2->DrawSubset( i );		}	g_pd3dDevice->EndScene();
Right now, you're setting the matrix, then rendering everything. That means that everything rendered with use the same matrix.

You'll need to set a different matrix for your cube.
NextWar: The Quest for Earth available now for Windows Phone 7.
each mesh has it sown matrices and even if i change the code to
setMatrices2();
keys2();

so each mesh has its own matrix this fails.

whenever i do translation or rotation ,I need to stop it else the next object will use the same translation.

if i keep a record of each meshes previous movements then set a worldmatrix as well as user input for another world matrix then this should solve.

This topic is closed to new replies.

Advertisement