Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 mynameisnafe   Members   -  Reputation: 242

Like
0Likes
Like

Posted 06 September 2013 - 02:57 AM

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;
}

Sponsor:

#2 3TATUK2   Members   -  Reputation: 695

Like
0Likes
Like

Posted 06 September 2013 - 03:27 AM

maybe change like so?

 

 float *m_in

 

=>

 

 float **m_in

 

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



#3 Sponji   Members   -  Reputation: 1125

Like
1Likes
Like

Posted 06 September 2013 - 04:32 AM

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);

Derp

#4 BitMaster   Crossbones+   -  Reputation: 3605

Like
0Likes
Like

Posted 06 September 2013 - 07:49 AM

A few side notes:
1) Allocating m_out on the heap is completely unnecessary. new/delete are rather expensive operations you should not use if allocating on the stack works perfectly fine.
2) Setting aside you should not new m_out in the first place, if you do, at least delete[] it. While mixing new[] and delete usually appears to work on MSVC, the standard forbids it and other compilers, like gcc, will blow up in your face.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS