Archived

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

HanSoL0

.x Model Movement

Recommended Posts

HanSoL0    1210
I''m relatively new to DirectX, but I''m trying to put together a 3D game engine. I''m at the point where I can fly the camera around one of my .x models with a joystick and keyboard, but how can I actually translate and rotate the model itself? Thanks in advance! HanSolo Sector 13 Games

Share this post


Link to post
Share on other sites
Pactuul    122
Since I just figured this out my self- i''ll save you some time and post what I learned =) --

create a few matrixs for scaling, rotating, and translating (you don''t have to do this but I prefer to keep the matrixs seperate for me to understand) I also have the "final" matrix after all the operations have been done and then I have a copy matrix so that I can backup the world matrix and switch back to it when I''m done.

D3DXMATRIX final;
D3DXMATRIX copy;
D3DXMATRIX rotation;
D3DXMATRIX scaling;
D3DXMATRIX translate;


//make the copy
d3d_device->GetTransform(D3DTS_WORLD, ©);

D3DXMatrixScaling(&scaling,xfactor,yfactor,zfactor);

//for now I would leave the translating to zero so that you don''t "lose" the model out to la-la land.
D3DXMatrixTranslation(&translate,xposition,yposition,zposition);

//rotate the model along an "axis" vector this can be any vector exp: axis(0,1,0) will rotate it around the y-axis. angle is in radians
D3DXMatrixRotationAxis(&rotation,&axis,angle);

//now it''s important that you multiply all these matrixs in the right order, esp the scaling which should be do last or else your rotations and movements will be scaled and be off.
D3DXMatrixMultiply(&tempmatrix,&rotation,&translate);
D3DXMatrixMultiply(&final,&scaling,&tempmatrix);

//now set our world matrix to the final matrix
d3d_device->SetTransform(D3DTS_WORLD,&final );
//render the mesh or what ever you do to draw it
Mesh->Render(d3d_device);

//reset the world matrix to what it was before
d3d_device->SetTransform(D3DTS_WORLD,© );

Hope this was helpful. Just ask if you have anymore questions.
Pactuul


"The thing I like about friends in my classes is that they can''t access my private members directly."



Share this post


Link to post
Share on other sites
HanSoL0    1210
I tried that, and it seemed to work....sort of. Now I can move my model back and forth, but when I rotate it, it looks like the model is trying to do so, but it only seems to rotate its matrix, not the actual model. The model only jiggles in the axis I''m trying to rotate around. If I rotate (using the arrow keys) and then move the model forward, it moves in the direction it would have moved if the model had actually been rotated. So it seems that only the matrix itself is being rotated, but not the model geometry. Do you know what might cause this? Do I have to do some manual model vertex manipulation?

HanSolo
Sector 13 Games

Share this post


Link to post
Share on other sites
jwalker    122
well .. you could try to lock the vertex buffer
and transform each vertex..

its quite easy to do .
and it will move the model ..

i did that for my engine, the fps is quite good if you
optimise the code properly..



{ Stating the obvious never helped any situation !! }

Share this post


Link to post
Share on other sites
Pactuul    122
you need to probably keep track of the "tempmatrix" because your probably using this in a function and the local variables are constantly being reset to identity and thus it rotates a "little" when you press the key, but the next frame it will reset back to identity. This is the reason for the giggling effect. if your using in it a function a quick fix is to make the tempmatrix a static or global so that it will hold the position and rotation and just add to it each call.

I hope that is a good explantion.

Pactuul


"The thing I like about friends in my classes is that they can''t access my private members directly."



Share this post


Link to post
Share on other sites
HanSoL0    1210
Now I''ve tried EVERYTHING with that "tempmatrix" and absolutely nothing has changed. I made it global, I made it static, I made copies of the main world matrix and reset it when I was done rotating the model.... nothing works.

Perhaps I mis-explained what was happening with the model when I try to rotate it. I don''t think it''s actually "jiggling", it''s more like it moves a *tiny* bit and stops, as if it gets caught on something. If I move it the opposite direction, it moves in the right direction, but again gets "stuck" on something and stops. I can control it (fly it around) but it''s only rotating the model''s matrix, not the actual model itself. It''s like flying an airplane around, but the airplane itself won''t change it''s orientation. Could the main world matrix be rotating itself around with the model?

HanSolo
Sector 13 Games

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
for every .x mesh u want to draw
{

1: Create a rotation matrix
2: Create a translation matrix
3: Multiply the two matrices to get a third matrix
4: Set the world matrix to the third matrix
5: Draw your .x Mesh

}

Share this post


Link to post
Share on other sites
HanSoL0    1210
I did that. There''s still something wrong. I don''t know what it is. The mesh''s matrix is rotated and translated, but the actual orientation of the mesh doesn''t change. I can fly my mesh around (even pitch, yaw, roll) but I don''t see these actual rotations in the mesh, only in the path that it moves around my world. I''m sooo stuck! Please help!!!

HanSolo
Sector 13 Games

Share this post


Link to post
Share on other sites
nlo    130
u need to calculate the object''s direction, those matrix after multiplication only relayed on the world''s X/Y/Z, dont just use the object''s x/y/z to translate, u need a Vector to keep track the object''s direction after u rotate it (x & y axis).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
oh I think I understand what you want to do.
You want to morph the actual mesh.
Not move the mesh around the scene.
Dunno how to do that yet.

Share this post


Link to post
Share on other sites