Direct3D translations (C++)

Soldato
Joined
23 May 2005
Posts
2,964
Location
Auckland, New Zealand
Hi, I'm new to directX and I'm really struggling with getting to grips with translating objects seperately. I've set up a class that loads objects and draws them and now i'm trying to move them around but it wont seem to work. Theres too much code and relevant fragments to paste here so i've uploaded the entire VS2005 project to here: http://rapidshare.com/files/84011483/meshes.rar.html

(~700k)

If anyone fancies taking a look and pointing out where I'm going wrong I'd be very grateful. Currently there is the DX tiger and a small plane on screen that move together (not seperately!)

Cheers. Joe
 
Without even looking at the code, I assume that you're not using a matrix stack, and the reason why it's not working is because you're not setting two translations? For example, the (very) simplified process of drawing might be the following:

* Set translation matrix for tiger
* Draw tiger
* Set translation matrix for plane
* Draw plane

You should have separate matrices for each, and as long as you follow the above path and don't multiply the matrices together or anything silly like that, they should translate separately.

If i've got this wrong, i'll download the code and have a look.

Edit: had a look anyway. The reason why it's not working is, you're creating a translation matrix for each object and then multiplying it with some global world matrix. So of course, if two objects are multiplying their transform matrices into it, before they are drawn the will both have the same transform.

In object.h, change:

Code:
D3DXMatrixTranslation(&ObjMWorld, ObjPos.x, ObjPos.y, ObjPos.z);
mWorld = ObjMWorld*mWorld;
//Device->SetTransform(D3DTS_WORLD, &ObjMWorld);

to

Code:
D3DXMatrixTranslation(&ObjMWorld, ObjPos.x, ObjPos.y, ObjPos.z);
Device->SetTransform(D3DTS_WORLD, &ObjMWorld);

.. and see what happens. I can't test it as I don't have the SDK on my machine.
 
Last edited:
Back
Top Bottom