texturing in directx

Started by
12 comments, last by Slyfox 17 years, 11 months ago
You need to multiply your matrices. To translate and rotate your mesh try this:

// Create World MatrixD3DXMATRIX matWorld, matTrans, matRot;D3DXMatrixTranslation(&matTrans, x, y, z); // x, y, z are floatD3DXMatrixRotationY( &matRot, timeGetTime()/1000.0f);D3DXMatrixMultiply(&matWorld, &matTrans, &matRot);g_device->SetTransform(D3DTS_WORLD, &matWorld);// Draw Meshg_mesh->DrawSubset( 0 );


Hope that helps.
Advertisement
Yes this will disable the translation and well done for trying this because you will now understand why.

You have to multiply the matrices together to acheive the combination of translating and rotating. Here's an example:
D3DXMATRIXA16 matWorld, matTrans, matRot;// Make the world matrix an identity, does nothing yetD3DXMatrixIdentity( &matWorld );// Make the translation matrixD3DXMatrixTranslation( x, y, z );// Make the rotation matrix,D3DXMatrixRotationX( float angleInRadians );// There are two ways of multiplying them together to achieve different results// 1) Translate then rotateD3DXMatrixRotation( matWorld, matWorld, matTrans );D3DXMatrixRotation( matWorld, matWorld, matRot );// 2) Rotate then translateD3DXMatrixRotation( matWorld, matWorld, matRot );D3DXMatrixRotation( matWorld, matWorld, matTrans );


The first multiplication gives a rotation of the object around the origin, from wherever you translated it to, the second rotates it on the origin and then moves it out to the translated position thus making it look like the object is rotating on the spot.

Hope that helps some more,

Dave
Quote:

float l_angle = l_time * ( 0 * D3DX_PI) / 5000.0f;



how does multiplying pi by 0 work? If you comment out the translation do you even get a rotating mesh? I haven't tried compiling this but doesn't that deduce to 0/5000?

Therefore the "angle" you are trying to create is undefined or always the y-axis is it not? If so that is useless computation.



EDIT: Quote was screwy.
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
Thanks a lot guys got it all working just right now thanks!!

-btw that 0 was there because that was normally replaced with SpinSpeed which was assigned to a key, i just forgot to switch it back

This topic is closed to new replies.

Advertisement