Default Motion State fix

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

Default Motion State fix

Post by KulSeran »

The default motion state describes a "get" and "set" method, for this to actually work properly as a two-way motion state

Code: Select all

btTransform temp;
motionstate.getWorldTransform( temp );
motionstate.setWorldTransform( temp );
should result in motion state having the exact same internal state.

as it is currently in the svn repository, the code above results in motionstate having the following internal state:
m_graphicsWorldTrans = m_centerOfMassOffset.inverse() * m_graphicsWorldTrans * m_centerOfMassOffset;
this is NOT the same initial state of the system.

my patch changes it to reduce to:
m_graphicsWorldTrans = m_graphicsWorldTrans * m_centerOfMassOffset.inverse() * m_centerOfMassOffset;
which results in the correct reduction to:
m_graphicsWorldTrans = m_graphicsWorldTrans;

Code: Select all

Index: src/LinearMath/btDefaultMotionState.h
===================================================================
--- src/LinearMath/btDefaultMotionState.h	(revision 2116)
+++ src/LinearMath/btDefaultMotionState.h	(working copy)
@@ -21,20 +21,18 @@
 	}
 
 	///synchronizes world transform from user to physics
-	virtual void	getWorldTransform(btTransform& centerOfMassWorldTrans ) const 
+	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
 	///Bullet only calls the update of worldtransform for active objects
 	virtual void	setWorldTransform(const btTransform& centerOfMassWorldTrans)
 	{
-			m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset ;
+		m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset;
 	}
 
-	
-
 };
---- I've had this issue before. When i tried to attach the file i get a "The extension patch is not allowed." or "The extension zip is not allowed." when attempting to add the file to the post.