btTransform::get/setFromOpenGL

loefje
Posts: 18
Joined: Thu May 28, 2009 10:43 am

btTransform::get/setFromOpenGL

Post by loefje »

Hi,

I've allowed myself to add a little feature to btTransform.h,
that allows users to later get the OpenGL data they added
through setFromOpenGLMatrix back with a getFrom...
The reason I did this is that when using a mat4 as storage element
within a shader, I want to use all 16 elements and not just the upper
3x3 and rightmost position column. I post it here because it maybe a
useful feature. I added a btScalar m_openGLData[16] and a bool
m_useOpenGLData that is set to false on creation to the members
of btTransform. the default value for the returnOnGet argument to
setFromOpenGLMatrix makes this feature transparent to current usage.

Jochem van der Spek

void setFromOpenGLMatrix(const btScalar *m, bool returnOnGet = false )
{
m_basis.setFromOpenGLSubMatrix(m);
m_origin.setValue(m[12],m[13],m[14]);
for( int i = 0; i < 16; i++ )m_openGLData[ i ] = m[ i ];
m_useOpenGLData = returnOnGet;
}

void getOpenGLMatrix(btScalar *m) const
{
if( m_useOpenGLData ){
for( int i = 0; i < 16; i++ )m[ i ] = m_openGLData[ i ];
}
else{
m_basis.getOpenGLSubMatrix(m);
m[12] = m_origin.x();
m[13] = m_origin.y();
m[14] = m_origin.z();
m[15] = btScalar(1.0);
}
}

...

btScalar m_openGLData[16];
bool m_useOpenGLData;
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: btTransform::get/setFromOpenGL

Post by Erwin Coumans »

Bullet only support rigid transforms, so they can only include translation and pure rotation.
No scaling or sheer etc. is allowed (so elements 3,7,11 should be zero).

If you want to store non-rigid parts of the transform, it is best to use the motion state for that.
Just derive your own version of btDefaultMotionState and add this info.
Hope this helps,
Erwin