Sign in to follow this  

Moving an object

Recommended Posts

Hello, I've created an object (just a square made up of 2 triangles) I can draw it to scene without problem. However I'm having trouble with the logic of moving it. I understand how to move the camera to change view, but in this instance there is other objects in the scene so I don't want to move the camera. Is there a way to simple move something within the scene ? Many Thanks.

Share this post

Link to post
Share on other sites
As you probably know, the world matrix determines the object's position, orientation, size, etc. So to move an object, construct the desired translation matrix, set it as the world matrix and draw the object.


D3DXMatrixTranslation(&mat, xPos, yPos, zPos);
device->SetTransform(D3DTS_WORLD, &mat);

This will draw the object at (xPos, yPos, zPos). Now to move the object, simply update these variables before constructing the matrix and the object will move.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this