Default get/set WorldTransform inconsistency

User avatar
jarno
Posts: 57
Joined: Tue Mar 16, 2010 1:42 am

Default get/set WorldTransform inconsistency

Post by jarno »

Greetings one and all.

I was using btDefaultMotionState, and as my center of mass wasn't at the origin of the graphics object I gave it a center of mass offset. But that started giving me some weird results with the collision shape and the geometry becoming separated when there was some rotation.

Looking at the code for getWorldTransform and setWorldTransform I notice something weird. getWorldTransform says:

Code: Select all

massTransform = offset^-1 * graphicsTransform
which rearranged by multiplying by offset on the left of both sides and flipping the sides around gives:

Code: Select all

massTransform = offset^-1 * graphicsTransform
offset * massTransform = offset * offset^-1 * graphicsTransform
offset * massTransform = graphicsTransform
graphicsTransform = offset * massTransform
but setWorldTransform says:

Code: Select all

graphicsTransform = massTransform * offset
which are not the same if the transform contains any rotation.

I fixed my problem by implementing my own motion state subclass, but I would like to know if this is a bug in the code or in my understanding.

---JvdL---
KulSeran
Posts: 9
Joined: Thu Dec 10, 2009 10:32 pm

Re: Default get/set WorldTransform inconsistency

Post by KulSeran »

I actually noticed the exact same issue, and also had to fix it using my own implementation of a motion state.

I'd assume it is a bug as well?

We use:
getWorldTransform:
centerOfMassWorldTrans = graphicsWorldTrans * m_centerOfMassOffset.inverse();

setWorldTransform:
graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset;
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Default get/set WorldTransform inconsistency

Post by Erwin Coumans »

There might be an issue, the btDefaultMotionState isn't very well tested.

I created an issue here, to make sure it gets resolved,
Thanks for the feedback!
Erwin
allsey87
Posts: 33
Joined: Fri Oct 26, 2012 1:50 pm

Re: Default get/set WorldTransform inconsistency

Post by allsey87 »

Hi Erwin,

It has been two years since the above posts however there has not been a change in the source code (I'm currently using 2.81).

From my testing and implementation, I agree with the authors of the above posts, however there appears to be no fix or issue on Google code regarding this glitch...

Cheers,

allsey87
allsey87
Posts: 33
Joined: Fri Oct 26, 2012 1:50 pm

Re: Default get/set WorldTransform inconsistency

Post by allsey87 »

This is the diff of what I am now using locally, any comments?

Code: Select all

diff --git a/src/plugins/simulator/physics_engines/dynamics3d/bullet/LinearMath/btDefaultMotionState.h b/src/plugins/simulator/physics_engines/dynamics3d/bullet/LinearMath/btDefaultMotionState.h
index c90b749..cd7e4c0 100644
--- a/src/plugins/simulator/physics_engines/dynamics3d/bullet/LinearMath/btDefaultMotionState.h
+++ b/src/plugins/simulator/physics_engines/dynamics3d/bullet/LinearMath/btDefaultMotionState.h
@@ -25,7 +25,7 @@ ATTRIBUTE_ALIGNED16(struct)	btDefaultMotionState : public btMotionState
 	///synchronizes world transform from user to physics
 	virtual void	getWorldTransform(btTransform& centerOfMassWorldTrans ) const 
 	{
-			centerOfMassWorldTrans = 	m_centerOfMassOffset.inverse() * m_graphicsWorldTrans ;
+			centerOfMassWorldTrans = m_graphicsWorldTrans * m_centerOfMassOffset.inverse();
 	}
 
 	///synchronizes world transform from physics to user
@@ -34,6 +34,11 @@ ATTRIBUTE_ALIGNED16(struct)	btDefaultMotionState : public btMotionState
 	{
 			m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset ;
 	}
+	
+	virtual void reset()
+	{
+	      m_graphicsWorldTrans = m_startWorldTrans;
+	}