rotating models in direct x

Started by
3 comments, last by unicoder 15 years, 1 month ago
Greetings, I try not to post much, but I have a quick & stupid question. I have been using this matrix translation to rotate a model in a mini engine I'm working on, but I want to be able to rotate specific models (right now the method I am using rotates all models that are loaded.) I am new to DirectX programming (I came from an API that handled most of the technical DX stuff but its performance was very "limiting".) So my question is, how can I just rotate the model in question instead of all models?

// world transform
static float index = 0.0f; index+=0.03f;
D3DXMATRIX matrixTranslate;
D3DXMATRIX matrixRotateY; 

D3DXMatrixTranslation(&matrixTranslate, x, y, z); 
D3DXMatrixRotationY(&matrixRotateY, index);    

d3ddev->SetTransform(D3DTS_WORLD, &(matrixRotateY * matrixTranslate));
If you need more code from me, I can provide it.
Advertisement
You need to set the world transform for each model before drawing that model.
If you set it once it will affect all models drawn after that.
I have functions set up to LoadModel(&model, filename) and DrawModel(&model, x,y,z). The code I provided in the OP is currently in the DrawModel function. Should it just be placed into the LoadModel function?

I want to be able to rotate them as I need to with DirectInput, so I want to be able to assign keys for movement. I guess my new question is how do I set up the rotation so that I can assign a key to it and access it as needed.

I can expand my draw model function to accept transform variables to make each model move differently (thanks for the heads up).

If I make a function to transform a selected model (say move it forwards) do I use it like: Transform(&model, x,y,z) and then redraw the model with a different transform value? or is there a way I can access any givens model transform and change it without having to redraw each time?

Well here is how I do it.My models are loaded and stored in a modelmanager class.
Then I have another entity class which contains a reference to its model representation.
The entity class also has members for the position,scale and rotation of the model.Before drawing the entity the final transformation is calculated and stored in matrix and setTransform is called before drawing the model.

So each entity has a different transformation matrix and sets its before getting drawn.Like :

for(unsigned int i=0; i<entityCount;++i){ setTransform(WORLD,entity->GetFinalMatrix()); drawEntity(entity);}


Something like that would work.You can change the transformations by changing the members of the entity class and it will only affect that entity.

Thank you.

This topic is closed to new replies.

Advertisement