Jump to content
  • Advertisement
Sign in to follow this  
andrew_ww

Moving an object

This topic is 4000 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

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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!