Jump to content
  • Advertisement

Archived

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

nanobyte

Easiest way to move objects

This topic is 6271 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 have setup a simple class and filled it with six triangles to draw a square. Here is the struct: class MyVertex { public: float x; float y; float z; D3DCOLOR color; }; MyVertex vertices[] = { {0,0,0, D3DCOLOR_RGBA(255,255,255,255), }, {0,.5,0, D3DCOLOR_RGBA(255,255,255,255), }, {1,0,0, D3DCOLOR_RGBA(255,255,255,255), }, {1,.5,0, D3DCOLOR_RGBA(255,255,255,255), }, {0,.5,0, D3DCOLOR_RGBA(255,255,255,255), }, {1,0,0, D3DCOLOR_RGBA(255,255,255,255), } }; My question is after I have rendered this onto the screen, how do I move the object. The above vertices are placed into a vertex buffer and that is whats rendered on the screen. Now, do I have to refill the vertex buffer each time I change a coordinate like this: vertices[1].x = blah . If so, how do I do this? gpDevice->CreateVertexBuffer(6*sizeof(MyVertex), 0, D3DFVF_MyVertex, D3DPOOL_DEFAULT, &gpSquare); VOID* pVertices; gpSquare->Lock(0, sizeof(vertices), (BYTE**)&pVertices, 0); memcpy(pVertices, vertices, sizeof(vertices)); gpSquare->Unlock(); Hope I didn''t confuse anyone more than I''m already confused. If I''m leaving anything out, just tell me. Thanks, Chris Lynch

Share this post


Link to post
Share on other sites
Advertisement
You have to set up a matrix defining the objects orientation in model space and then draw it using that matrix. It's a little confusing at first but to make understanding it easier I'd have to suggest using Drunken Hyena's tutorials at http://www.drunkenhyena.com/docs/d3d_tutorial.phtml
or reading the First Steps to animation by Wolfgang Engel at http://www.directxgraphics.net/tutorials/tutorial2/first_steps_to_animation.html.

Oh yeah I can't forget ol' Microsoft either. Check out the direct x 8 documentation that came with the SDK or go to msdn.microsoft.com or www.microsoft.com/directx

Basically you never directly manipulate an object's vertex buffer to move it. Instead, everytime you need to update it's position (once a frame) redefine a local matrix which is a combination of it's location (translation matix), and it's x, y, z rotation (orientation matrix).

Edited by - infinitycool on July 22, 2001 6:53:14 PM

Share this post


Link to post
Share on other sites
Thanks alot. I read the Drunken Hyena and created the following function to move my square:

int MoveRight() {
D3DXMATRIX temp;
num = num + .005;
my_square.Fill(&square);
D3DXMatrixTranslation(&temp, num, 0.0f, 0.0f);
my_square.SetWorldMatrix(&temp);

return 0;
}

it works perfect!

Thanks

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!