Skip to main content
gamedev.net
🔒 Locked

Rotating Meshes

Started by Roaders Feb 28, 2003 at 3:17 AM 7 replies 500+ views
Original Post
Roaders
Roaders
Hi Guys New to DirectX so please be gentle. I have this code that loads a mesh from a file: LPD3DXMESH g_pMesh D3DXLoadMeshFromX(strFilename, D3DXMESH_MANAGED, g_pd3dDevice, NULL, &pD3DXMtrlBuffer, &g_dwNumMaterials, &g_pMesh ) My question is how do apply a transformation matrix to this to rotate the mesh. The specific example is that this is a model from 3DStudio and it sits on it''s nose not on it''s wheels so I want to rotate the mesh just after it has loaded. I have found loads of mesh functions but none of them seem to apply a matrix to a mesh. Thanks. Giles Roadnight giles.roadnight.name
bergfald
bergfald
You just have to apply a rotation matrix that rotates -90 degrees (-3.14/2 radians) around the X-axis( if I remember correctly).

You may add this in Render, or make the matrix a classmember and make matRot once in RestoreDeviceObjects (which is more efficient):


D3DXMATRIX matRot;
D3DXMatrixRotationX(&matRot, -3.14f/2.0f);

//You may want to multiply additional transformations here

g_pd3dDevice->SetTransform( D3DTS_WORLD, &matRot);
g_pMesh->DrawSubset(0);
..etc..

-MenTaL-
E. Bergfaldhttp://bergfald.stud.hive.no
Roaders
Roaders
What I am doing at teh moment is just applying the rotation whenever I draw the mesh. Is this what you are doing in the code below? looks like it is. I want to rotate it once when the mesh loads then not have to worry about it again.

I think that the code you have given me will actually draw the rotated mesh and not alter that actual mesh as stored in memory. Is this right?

Thanks for the post

Giles Roadnight

giles.roadnight.name
bergfald
bergfald
That''s right.

If you wan''t to make a static rotation to your mesh, you''re better off rotating -90degrees around the X axis in 3ds max before you export.

-MenTaL-
E. Bergfaldhttp://bergfald.stud.hive.no
Hoongming
Hoongming
Hi Bergfald,

I was wondering about this question also and Ive looked at your response. The thing I dont understand is in your answer you are doing a world transformation right? Then wouldnt that imply that everything in that 3D space be rotated together with the mesh?? But what if I have a 3D environment and I just want to apply a transformation to the mesh and not to the entire 3D environment? or are these separate entities? or do they all reside in the same 3D world space?

regards

Hoongming
Zern
Zern
Get the world matrix before you modify it, then simply replace once done:



D3DMATRIX matWorld;

//: Get the world matrix
IDirect3D9::GetTransform(D3DTS_WORLD, &matWorld );

//: Play with transforming/scaling/whatever for the mesh
//: Draw the mes

//: Restore the world matrix
IDirect3D9:SetTransform( D3DTS_WORLD, &matWorld );
tok_junior
tok_junior
That''s one way to do it, but all get''s are slower than they have to be, plus, every mesh usually have it''s own world-matrix anyway. So just set the world-matrix on a per-mesh basis.

--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.
bergfald
bergfald
Hi Hoongming,

tok_junior is right. A specific transformation is applied to the things you render between the point you set that transformation, and until you set anoter transformation. It doesn''t inherit the "old" transformation or anything.

To optimize your code you could render alle your static objects and environment with the same transformation, and then set a unique transformation for each dynamic object(mesh).


-MenTaL-
E. Bergfaldhttp://bergfald.stud.hive.no

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.