Archived

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

How do I move my mesh w keyboard?

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve loaded a simple mesh model into my program using dx8 and VC6. And now I''m intrigued to give it some movement apart from the normal rotational movements and translation movements using the matrix modules. Is there any easier way to move my mesh along a straight path apart from using direct matrix calculations. I would welcome all forms of suggestions and even code snippets as I am a total newbie :D.

Share this post


Link to post
Share on other sites
You still need to use matrices to describe the transformation to the graphics card.

As to the "moving logic", store the object's general position and orientation as vector(s).
For example, when you determine that a certain key is down, increment or decrement the corresponding component of the vectors.
You could also modify the vectors using any other function.

Before rendering your model, create a matrix from the said vectors, and set it as the world transform.

-Nik

EDIT: clarification

[edited by - Nik02 on November 11, 2003 7:26:43 AM]

Share this post


Link to post
Share on other sites
A model/mesh is typically at the (0,0,0) coordinates. Every object should have a world matrix, this specifies its position and orientation in the scene. You should declare local coordinates x,y,z.
Then translate this to a matrix with eg.
D3DXMatrixTranslation(&pWorldMatrix, x, y, z);   

Then use
g_pDevice->SetTransform(D3DTS_WORLD, &pWorldMatrix);   

Rotations are similar using D3DMatrixRotation.
I think there's no simpler way, this is already very simple.

You can trap keydown and keyup messages, set booleans like forward_pressed to true and false when the 'W' key is pressed or released (assuming you'll use the classic w/a/s/d keys for momement) and then in your render loop do stuff like
if (forwardpressed) {mypos.x += 0.01;}   


This way you can move it around as much as you like.


[edited by - Fidelio66 on November 11, 2003 7:54:32 AM]

[edited by - Fidelio66 on November 11, 2003 7:54:58 AM]

Share this post


Link to post
Share on other sites
He said movement apart from translation/rotation, like animation. So, ParityCheck, I hate to disappoint you, but no, there is no easy way out. You must either create a model out of a series of meshes, then give each mesh it''s own matrix (so that you could rotate, say an arm, individually), use keyframes and tweening, or use bones, all of which are less than desirable methods to implement.

Share this post


Link to post
Share on other sites
Well actually I don''t intend to make much of a complex movement. Actually I want my mesh to just move around a preset path in a straight line. This just involves a simple translation and rotation around the end of the path to point back at the beginning. You know like a bot on patrol. I do understand that the only way to do it is through usage of matrices but I can''t seem to understand the combination of required matrices to get this movement. The movement is as follows:

Bot moves from point (x,y,z) to point (x1,y1,z1) upon reaching point (x1,y1,z1) the bot should rotate around an angle to face point (x2,y2,z2) and then move towards it and upon reaching turn and go back to the origin. I keep getting mixed up with regards to what would be the correct sequece of matrix transformations to accomplish this task. Any suggesstions guys

Share this post


Link to post
Share on other sites