Archived

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

Astigot

How to apply a seperate transform to a mesh? (Dx8)

Recommended Posts

I''m probably missing something really obvious here, but how do I apply a transform matrix to just a mesh? And would the mesh still be affected by the world transform? Help much appreciated

Share this post


Link to post
Share on other sites
Depends what you mean by "world transform".

A more complete name for the World Matrix in D3D would be "The matrix which transforms vertices from object/model/mesh space into world space"

Likewise the view matrix would be "the matrix which transforms vertices from world space into camera space" and the projection matrix would be "the matrix which transforms vertices from camera space into screen space and partially applies the effect of perspective to them".

The world matrix sets the position and orientation of your mesh within the 3D world. A plane in a flight sim would have it''s position and rotation in the world set with its "world" matrix.

Share this post


Link to post
Share on other sites
What I mean by the ''world transform'' is something this:
D3DMATRIX matWorld;
D3DXMatrixRotationX(&matWorld, D3DXVECTOR3(1.0f,0.0f,0.5f), timeGetTime()/150.0f);
D3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

Like they use in the D3D tutorials. Now this transforms everything in the world, which is fine. But how do I apply a transform matrix to just one object?

I don''t care about getting the technical terms right, just getting my prog to do what I want it to.

Share this post


Link to post
Share on other sites
Say you have two objects, obj1 and obj2, that you want to render.
Forgive the crude pseudo code... :-)

// the world transform matrix
D3DMATRIX matWorld;

// set the matWorld matrix to be an identity matrix
SetToIdentity(matWorld);
// then perform the required transformation
D3DXMatrixTranslation(&matWorld, D3DXVECTOR3(10,0,0));
// set the world transform
D3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
// render obj1 here.... which will be translated 10 units along the x-axis
RenderObject(obj1);

// set the matWorld matrix to be an identity matrix
SetToIdentity(matWorld);
// then perform the required transformation
D3DXMatrixTranslation(&matWorld, D3DXVECTOR3(0,10,0));
// set the world transform
D3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
// render obj2 here.... which will be translated 10 units along the y-axis
RenderObject(obj2);

This should solve the problem. Note that the rendering of obj2 has no effect on the already transformed and rendered obj1.

Hope this helps.
Cheers,
Sharky




Share this post


Link to post
Share on other sites