Jump to content
  • Advertisement

Archived

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

executor_2k2

OpenGL Representing matrices in opengl

This topic is 5930 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

Im remaking my matrix class and I was wondering if a union between float array[16] and float mat[4][4] will work ok. Edit: Will mat[0][3] be the fourth element of "array"? Im using C++ btw [edited by - executor_2k2 on June 25, 2002 6:15:30 AM]

Share this post


Link to post
Share on other sites
Advertisement
I just represent mine internally as float[16], and provide various accessors and mutators to provide different views/access points to the data... eg

- an Item(int row, int column) accessor/mutator to allow row/column access
- accessor and mutator for each of the rotational axes and the translation part of the matrix (each a 3-component vector)

It just feels a lot neater and safer than mucking about with unions and allowing free-for-all access to the data in random manners

Share this post


Link to post
Share on other sites
You can grab an array class there. And a multidimensional array class there

Alternatively...


    
class Matrix4f
{
public:
float& operator()( size_t n )
{ return data[n]; };
const float& operator()( size_t n ) const
{ return data[n]; };

float& operator()( size_t x, size_t y )
{ return data[x+4*y]; };
const float& operator()( size_t n ) const
{ return data[x+4*y]; };

private:
float data[16];
};


Will provide mat(n) and mat(x,y) as a substitute to mat[n] or mat[x][y] (which would require the use of a proxy class).

Edit: note that you cannot replace operator() by operator[] since the processing of the comma as parameter separator is specific to operator().

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on June 25, 2002 2:43:55 AM]

Share this post


Link to post
Share on other sites
I could tell you, but then I would have to kill you. But seriously the best way to answer a question like that is to use your debugger. Set the matrix entries to 00, 01, 02, 03, 10, 11, 12, 13, 20, etc and see where they end up in the array.

Share this post


Link to post
Share on other sites
As far as i know the memory layout of array[4][4] is exactly the same as array[16]...the only difference is the way you access it.

Remember its always possible to say *(array + i) and access the memory that way (it doesn''t matter which way it was created)

- Ces

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!