Public Group

# Model space to object space to world space

This topic is 4484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've learnt how to transfer from object space to world space, i.e. have a square mesh that I render on screen in it's correct position. First I set view and projection matrices, then send them to the device by:
//assume matView and matProj have been set...
g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);

Then I tell the location of my object by using a world matrix:
D3DXMATRIXA16 matWorld;
D3DXMatrixIdentity(&matWorld);
D3DXMatrixRotationY(&matWorld, 0.5f);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);

But if I want an animated mesh I might want to move for example a character arm vs a reference point in the mesh rather than calculating movements compared to world coordinates, which would add a third transformation stage - from model space to object space (the others being object to world space and world to view space). How do I achieve that (in code or pseudocode)? I can't find anything in the documentation and am not that good at linear algebra to be able to figure it out for myself in case it has to be done manually and isn't done by D3D functions.

##### Share on other sites
You have to be aware what the API does with the supplied matrices: It concatenates them (or at least could do so) to deal with a single, combined matrix only. And that is just the way you have to do it.

Imagine as a simple example 2 translations:
D3DXMATRIXA16 matTranslation1, matTranslation2;D3DXMatrixTranslation(&matTranslation1, x1, y1, z1);D3DXMatrixTranslation(&matTranslation2, x2, y2, z2);D3DXMatrixMultiply(&matWorld, &matTranslation1, &matTranslation2);

Here the matWorld will in effect denote a translation by (x1+x2, y1+y2, z1+z2).

Mathematically the product
M := T1 * T2
is done. Notice that matrix multiplication isn't cummutative! That is important in most cases. Please see the correspondence of the order of the matrices in the formula and the code snippet above. In D3D the matrix that is located left-most is applied to the most local geometry. Say, if you have a vertex, the applied matrix stuff is this:
v' := v * M = v * T1 * T2
Here you could see that the orignal vector is transformed like first translated by T1 and then by T2. As already stated, make this totally clear to your mind!

Now, you want to rotate the arm. To do so you have to consider that any rotation is done around 0. So you have to temporalily change the origin into the shoulder, then to rotate, and then to undo the temporary translation. That looks like this
M1 := T-1 * R * T
where T denotes the position of the shoulder in the co-ordinate frame of the arm, R is your rotation matrix, and T-1 the inverse of the position.
Additionally, you have to transform the arm so that it is given in world space. That is another matrix depending on how you have organized your model. Since I don't know better, I simply say it is M2. So
M := M1 * M2 = T-1 * R * T * M2
would be the overall transformation.

What could be seen from this stuff is that it is all a question of correctly concatenating a couple of particular transformations.

Btw: In the snippet of the OP you load matWorld with the identity matrix but overwrite it in the next step.

• 9
• 10
• 9
• 48
• 12
• ### Forum Statistics

• Total Topics
631387
• Total Posts
2999712
×