Hi,
I was getting the transform to set the position of already created bodies with the function btTrasform::setFromOpenGLMatrix().
This function calls m_basis.setFromOpenGLSubMatrix(m) and m_origin.setValue(m[12],m[13],m[14]) which is OK.
The problem comes in m_basis.setFromOpenGLSubMatrix(m): It takes each ROW of the final body matrix that are the vectors m_el and assign them the COLUMNS of the m matrix. So it results in a transpose matrix that when the object is created with a rotation it gives completely opposite results.
//This is the original function
void setFromOpenGLSubMatrix(const btScalar *m) {
m_el[0].setValue(m[0],m[4],m[8]);
m_el[1].setValue(m[1],m[5],m[9]);
m_el[2].setValue(m[2],m[6],m[10]);
}
//This is the function I think it's correct
void setFromOpenGLSubMatrix(const btScalar *m) {
m_el[0].setValue(m[0],m[1],m[2]);
m_el[1].setValue(m[4],m[5],m[6]);
m_el[2].setValue(m[8],m[9],m[10]);
}
If this is true, the corresponding function to get the opengl matrix btMatrix3x3::getOpenGLSubMatrix needs to be modified too.
//Original function:
void getOpenGLSubMatrix(btScalar *m) const
{
m[0] = btScalar(m_el[0].x());
m[1] = btScalar(m_el[1].x());
m[2] = btScalar(m_el[2].x());
m[3] = btScalar(0.0);
m[4] = btScalar(m_el[0].y());
m[5] = btScalar(m_el[1].y());
m[6] = btScalar(m_el[2].y());
m[7] = btScalar(0.0);
m[8] = btScalar(m_el[0].z());
m[9] = btScalar(m_el[1].z());
m[10] = btScalar(m_el[2].z());
m[11] = btScalar(0.0);
}
//Function I think is correct
void getOpenGLSubMatrix(btScalar *m) const
{
m[0] = btScalar(m_el[0].x());
m[1] = btScalar(m_el[0].y());
m[2] = btScalar(m_el[0].z());
m[3] = btScalar(0.0);
m[4] = btScalar(m_el[1].x());
m[5] = btScalar(m_el[1].y());
m[6] = btScalar(m_el[1].z());
m[7] = btScalar(0.0);
m[8] = btScalar(m_el[2].x());
m[9] = btScalar(m_el[2].y());
m[10] = btScalar(m_el[2].z());
m[11] = btScalar(0.0);
}
I hope this make sense and can be fixed.
Bea.
btMatrix3x3::setFromOpenGLSubMatrix transpose the matrix
-
- Posts: 2
- Joined: Mon Feb 09, 2009 12:55 pm
-
- Posts: 32
- Joined: Fri Dec 19, 2008 2:51 pm
Re: btMatrix3x3::setFromOpenGLSubMatrix transpose the matrix
Actually, the "transposed" version is correct, since the OpenGL convention of storing matrices is row-major, as opposed to the common column-major.
-
- Posts: 18
- Joined: Thu May 28, 2009 10:43 am
Re: btMatrix3x3::setFromOpenGLSubMatrix transpose the matrix
sorry, but this is not true, see the OpenGL FAQ onDominik wrote: Actually, the "transposed" version is correct, since the OpenGL convention of storing matrices is row-major, as opposed to the common column-major.
http://www.opengl.org/resources/faq/tec ... tions.htm
I (accidentally) started a similar topic here:http://continuousphysics.com/Bullet/php ... 1b1a7d0566
but I'm still confused.
to me, it seems beaelp is right in saying that the
getOpenGLSubMatrix gives back the transpose of an
OpenGL matrix expected by ao glLoadMatrix
J
-
- Posts: 32
- Joined: Fri Dec 19, 2008 2:51 pm
Re: btMatrix3x3::setFromOpenGLSubMatrix transpose the matrix
sorry, mixed up row- and clumn-major... Still, its correct that opengl uses the "transposed" notation as seen from bullet (and most other toolkits)
an OpenGL
is stored as mat[16]={ a e i m b f j n c g k o d h l p }
while most other use the row-major one
an OpenGL
Code: Select all
| a b c d |
| e f g h |
| i j k l|
| m n o p |
while most other use the row-major one