Getting 2d into 1d, making GLM::Mat4

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

Recommended Posts

Hi Guys, I've just hacked this together so I can have a 1D float array of a matrix to pass to
return glm::make_mat4( float* );
I'm getting c2109 - Subscript requires array or pointer, and it's pointing to the kernel of this loop.. please help! by the way, if the logic is wrong, let me know. Thanks! glm::mat4 make1dfrom2d( float *m_in, bool rowMajor ) { float* m_out; m_out = new float[16]; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) if( rowMajor ) m_out[ (i*4) + j ] = m_in[i][j]; // c2109 else m_out[ i + (j*4) ] = m_in[i][j]; // c2109 glm::mat4 gm_out = glm::make_mat4( m_out ); delete m_out; return gm_out; }

Share on other sites

maybe change like so?

float *m_in

=>

float **m_in

or float[4]* or some junk - not sure

Share on other sites

I think you are making things too complicated. Maybe this could help:

// make from one dimensional array
float mymat[16];
glm::mat4 m glm::make_mat4(mymat);

// make from two dimensional array
float mymat[4][4];
glm::mat4 m = glm::make_mat4(&mymat[0][0]);

// if you need to change the ordering
m = glm::transpose(m);