Jump to content
  • Advertisement

Archived

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

31337

Accessing values of D3DXMATRIX?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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...

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!