Accessing values of D3DXMATRIX?

Started by
10 comments, last by 31337 20 years, 6 months ago
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
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
Advertisement
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...

Kippesoep
For some reason on MSDN it doesn''t seem to indicate how D3DXMATRIX stores the values. What is that rhs business?
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
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.
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
Data in D3DXMATRIX''s are in row-major order.

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
Row major? Does that mean that the first four items are all in the first row or the first column?
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
So how should I work this if my data needs to be transposed to fit into DirectX format?
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
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
The problem is is that the reason why I''m even dealing with my own matrix class is because its for my 3D engine Glaucomy which works with OpenGL too...
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/

This topic is closed to new replies.

Advertisement