• Popular Now

• 12
• 12
• 9
• 10
• 13

Archived

This topic is now archived and is closed to further replies.

Accessing values of D3DXMATRIX?

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

Recommended Posts

Hello, I am trying to write functions that will convert D3DXMATRIX''s to my own custom matrix class. My matrix class stores matrices in a floating point array of 16 items where myMatrix[1] is the item in the second row, first column, and myMatrix[4] is the item in the first row and second column. How do I do it? Thanks

Share on other sites
Create a custom assignment operator, something like this:

const MyMatrix &MyMatrix::operator = (const D3DXMATRIX &rhs){  for (int c = 0; c < 4; ++c)    for (int r = 0; r < 4; ++r)      data [c * 4 + r] = rhs (r, c);}

I don''t recall whether D3DXMATRIX is stored in a row-major or column-major fashion. If it is stored in the same way your matrix class is, then just do a memcpy or something...

Share on other sites
For some reason on MSDN it doesn''t seem to indicate how D3DXMATRIX stores the values. What is that rhs business?

Share on other sites
The rhs is just the name of the D3DXMATRIX variable... make it
const MyMatrix &MyMatrix::operator = (const D3DXMATRIX &Bob){  for (int c = 0; c < 4; ++c)    for (int r = 0; r < 4; ++r)      data [c * 4 + r] = Bob (r, c);}

if you want. It''s completely arbitrary.

Share on other sites
You don''t really need to create a D3DXMATRIX operator, all the dx functions use D3DXMATRIX*, so its alot faster to just write a D3DXMATRIX* conversion operator like so,

MyMatrix::operator D3DXMATRIX*(){  return (D3DXMATRIX)this;}

asumming you follow the alignment like D3DX does. You can look at parts of the code by openening up the D3DX headers from your SDK, as alot of its inline.

regards,
-Eric

Share on other sites
Data in D3DXMATRIX''s are in row-major order.

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.

Share on other sites
Row major? Does that mean that the first four items are all in the first row or the first column?

Share on other sites
So how should I work this if my data needs to be transposed to fit into DirectX format?

Share on other sites
You have two choices. You can either store your data in row major form so that there is no need to convert any data for DX to use, or you can transpose your matrix. Transposing a matrix means that all the columns of the source matrix become the rows of the destination matrix.

If your matrix class is only going to be used with DX, then I would say that you should store your matrix in row major format and be done with it. If you need your matrices in column major format for some specific purpose, then ok. But if not, then storing your matrix in column major format would just cause you to incur the overhead of transposing the matrix every time you needed to do something with DX.

neneboricua