# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Cinema 4D and Bullet PhysicsPosted: Tue Sep 19, 2017 12:09 am

Joined: Tue Feb 19, 2013 10:14 pm
Posts: 6
Since there is quite a bit of confusion about converting Cinema 4D<->Bullet transform matrices (or, generally, how to go convert left-handed<->right-handed coordinate transforms), here is the solution that I use (from source for another project). It is really that simple - use a Similarity Transform.

Code:
// Vector/btVector3
//*---------------------------------------------------------------------------*
btVector3 c4dVector_btVector3(const Vector& c4d_vector)
//*---------------------------------------------------------------------------*
{
return btVector3(c4d_vector.x, c4d_vector.y, c4d_vector.z);
}
//*---------------------------------------------------------------------------*
Vector btVector3_c4dVector(const btVector3& bt_vector)
//*---------------------------------------------------------------------------*
{
return Vector(bt_vector.getX(), bt_vector.getY(), bt_vector.getZ());
}
// Matrix/btTransform
//*---------------------------------------------------------------------------*
Matrix btTransform_c4dMatrix(const btTransform& bt_transform)
//*---------------------------------------------------------------------------*
{
btMatrix3x3 bt_basis =   bt_transform.getBasis();
Matrix   c4d_mat;
c4d_mat.v1 =      btVector3_c4dVector(bt_basis.getRow(0));
c4d_mat.v2 =      btVector3_c4dVector(bt_basis.getRow(1));
c4d_mat.v3 =      btVector3_c4dVector(bt_basis.getRow(2));
c4d_mat.off =      btVector3_c4dVector(bt_transform.getOrigin());
// Apply Similarity Transform from Bullet's R-H/RowMajor matrix (bt_transform)
// - (z-trans and z row-column are negated except for overlap (v3.z))
c4d_mat.v1.z *=      -1.0;
c4d_mat.v2.z *=      -1.0;
c4d_mat.v3.x *=      -1.0;
c4d_mat.v3.y *=      -1.0;
c4d_mat.off.z *=   -1.0;
return c4d_mat;
}
//*---------------------------------------------------------------------------*
btTransform c4dMatrix_btTransform(const Matrix& c4d_matrix)
//*---------------------------------------------------------------------------*
{
// Apply Similarity Transform to create Bullet's R-H/RowMajor matrix (bt_trans)
// - (z-trans and z row-column are negated except for overlap (v3.z))
/*
Matrix   c4d_mat =   Matrix(c4d_matrix);
c4d_mat.v1.z *=      -1.0;
c4d_mat.v2.z *=      -1.0;
c4d_mat.v3.x *=      -1.0;
c4d_mat.v3.y *=      -1.0;
c4d_mat.off.z *=   -1.0;
*/
btMatrix3x3   bt_basis = btMatrix3x3(c4d_matrix.v1.x, c4d_matrix.v1.y, c4d_matrix.v1.z*-1.0, c4d_matrix.v2.x, c4d_matrix.v2.y, c4d_matrix.v2.z*-1.0, c4d_matrix.v3.x*-1.0, c4d_matrix.v3.y*-1.0, c4d_matrix.v3.z);
btTransform   bt_trans;
bt_trans.setOrigin(c4dVector_btVector3(Vector(c4d_matrix.off.x, c4d_matrix.off.y, c4d_matrix.off.z*-1.0)));
bt_trans.setBasis(bt_basis);
return bt_trans;
}

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot] and 13 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities