Moving an object

Started by
0 comments, last by Gage64 16 years, 3 months ago
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.
Advertisement
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.

Example:

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


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.

This topic is closed to new replies.

Advertisement