Small Question (Mesh Positions)

Started by
5 comments, last by Drakex 18 years, 8 months ago
If load several meshes into a world, each with there own matrix (which have been set there position using D3DXMatrixTranslation), how would I recall their position co-ordinates? (If that makes sense). I basically just want to find out the x, y and z of a mesh.
luke88
Advertisement
You can't. You would have to associate a mesh permanently with a matrix, i believe, in your own way.

ace
Ow, damn't. DirectX Retained Mode was so much simpler and straight forward. I wish they never dropped it. Oh well.

I think I've found a way to do it anyway (with my own code).

Thanks for the info.
luke88
Although Ace is usually right I think he misunderstood the question. Otherwise I have. But if you have the matrix of each mesh you can retrieve the position from it: it is the vector on the bottom row of the matrix. The position vector V = (M41, M42, M43).

Greetz,

Illco
Illco is right. Just complementing:

If the mesh initial position is not at the origin (0,0,0), do:

Mesh initial position = (pox,poy,poz)

Mesh current position = (M41,M42,M43)+(pox,poy,poz)


Note: I suppose that no scale transformation is applied to the meshes.
Just another aside to throw into the mix... what's been said will work fine for the original question, but it won't necessarily "scale" when you implement more complex transformations (e.g. rotation and scaling).

If you combine rotation/scaling yet still only extract the M41/M42/M43 elements you'll only get the translation part of the transformation. You'd need to actually translate a coordinate (or decompose the matrix) using D3DX functions to get the full set of original values.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Or, you could wrap it all in a class:

class object{    ID3DXMesh mesh;    D3DXMATRIX mat;    D3DXVECTOR3 position;    D3DXVECTOR3 rotation;    D3DXVECTOR3 scaling;    // pos/rot/scale accessors    // some kind of function to update the matrix based on the PRS    // some kind of function to set the mat and draw the mesh}


Who needs D3DRM when you can make your own? ;)
_______________________________________________________________________Hoo-rah.

This topic is closed to new replies.

Advertisement