Positioning meshes/models

Started by
3 comments, last by blueshogun96 18 years, 7 months ago
Hi there, I have a general CModel class that I am using for loading in .x meshes (models) for my game. It works fine and displays fine, but I don't see any way to actually set the position of the model once all the meshes, materials, and textures are loaded in. By the way, I based my code off of the Tutorials 6 (Meshes) from the DirectX Sample code. Can anyone give me an overview of how to manipulate my mesh once I have it loaded in in terms of moving it around?
Advertisement
You manipulate your mesh in the same way you manipulate any geometry object in your scene: You modify your world matrix before you render the mesh.

Here is a short example:

D3DXMATRIX TranslateU1;

g_pDevice->SetTransform(D3DTS_WORLD, &IdentMatx);
D3DXMatrixTranslation (&TranslateU1,60,-20,40);
g_pDevice->SetTransform(D3DTS_WORLD, &TranslateU1);

m_pMesh->DrawSubset(iCount);



For more details check this thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=344700&whichpage=1?

My project`s facebook page is “DreamLand Page”

Hi there mcguile25,
How are you doing?

The Problem
Moving/placing your mesh in the world

The Solution
Buddy, you can generally have a world matrix for each entity (mesh/object) and just set that ... so when you render you can follow the simple pattern

1) Set the initial world matrix.
eg: D3DXMatrixTranslation(&matWorld, 0.0f, 0.0f, 0.0f);
2) You can then just set it as your render the entity
eg: pDevice->SetTransform(D3DTS_WORLD, &matWorld);
3) Render your mesh (The matrix set will apply to everything rendered after that until a next transformation matrix is set.
eg: Mesh->DrawSubset(0);

See, the thing is ... each entity has some properties.
1) Textures
2) Matrices that place them in the world
3) Materials

It all really depends on your situation.


I hope this helps a bit buddy
Right on, thanks guys. I'm still learning the ins and outs of Direct3D and this is all making sense. Thank you to both of you :)
Hi, I have some more info for you when rendering multiple meshes (and I hope that this isn't too advanced for you). Let's say you are rendering the same model over and over again, you are wasting precious CPU time like that. Instead, try using Dx9 Instancing. What is instancing? Dx9 Instancing is the process of rendering the same model multiple times with only using one draw call. Lets say you have tree.x, using instancing you can use instancing to render tree.x multiple times (i.e. 100, 1000, etc.) without having to do some stupid for loop and and making a million and one IDirect3DDevice9::DrawPrimitive calls. The requirements are DirectX 9.0c and a vs 3.0 compatible video card. The API is layered over IDirect3DDevice9::SetStreamSourceFreq. You will also need a powerful video card to do so (i.e. nVidia GeForce 6 or a high end ATI Radeon card.) because it requires alot of horsepower. My crappy nvidia GeForce FX 5200 doesn't support instancing, so you have to check and see if your video card supports it first. Only use it if you can afford to do so, because it can be "dangerous" if you are GPU bound or if you over-use it. Here is a link to a pdf doc pertaining to the subject. I hope that this is useful to you :)

This topic is closed to new replies.

Advertisement