[ODE] Fwd: [Opende-svn] SF.net SVN: opende: [1136] trunk/ode/src/ode.cpp

David Walters hidden.asbestos at googlemail.com
Mon Nov 6 10:35:07 MST 2006


Hi, I totally forgot about this patch from a while back:

http://sourceforge.net/tracker/index.php?func=detail&aid=1557801&group_id=24884&atid=382801

It was actually two parts, one which attempted to provide a utility
function to correct body/composite-geom shapes that had offset masses
by adjusting the mass and offsetting the geom:

+void dBodySetOffsetMass (dBodyID b, dMass *mass)
+{
+	dAASSERT (b && mass );
+
+	// The centre of mass must be at the origin.
+	// Adjust attached geoms and centre mass.
+	if ( fabs( mass->c[0] ) > dEpsilon ||
+		 fabs( mass->c[1] ) > dEpsilon ||
+		 fabs( mass->c[2] ) > dEpsilon )
+	{
+		// Adjust all attached geoms to compensate
+		dGeomID geom = b->geom;
+		while ( geom )
+		{
+			// Get current offset
+			const dReal* co = dGeomGetOffsetPosition( geom );
+
+			// Adjust
+			dGeomSetOffsetPosition( geom,
+				co[0] - mass->c[0],
+				co[1] - mass->c[1],
+				co[2] - mass->c[2] );
+
+			// Next attached.
+			geom = geom->body_next;
+		}
+
+		// Zero the mass centre.
+		dMassTranslate( mass, -mass->c[0], -mass->c[1], -mass->c[2] );
+	}
+
+	dBodySetMass( b, mass );
+}


This patch was rejected, and rightly so - if you add a new geom after
this it won't be offset correctly and would just cause a new set of
problems instead of fixing everything.

Caught up in that rejection was the other part of the patch - an
assert - which will warn the user in the case where a mass with an
offset centre is applied to a body. This offset isn't used by ODE at
the moment and will lead to a variety of hard to track down problems
in an API that seemingly allows such behaviour.

I finally go round to adding it:



---------- Forwarded message ----------
From: hidden_asbestos at users.sourceforge.net
<hidden_asbestos at users.sourceforge.net>
Date: 06-Nov-2006 17:03
Subject: [Opende-svn] SF.net SVN: opende: [1136] trunk/ode/src/ode.cpp
To: opende-svn at lists.sourceforge.net


Revision: 1136
          http://svn.sourceforge.net/opende/?rev=1136&view=rev
Author:   hidden_asbestos
Date:     2006-11-06 09:03:01 -0800 (Mon, 06 Nov 2006)

Log Message:
-----------
Added an assert (from patch 1557801) for a very common composite mass
problem encountered by new users - centre of mass must be at the body
origin. (Use dMassTranslate( mass, -mass->c ) to correct it). Note
that at some point in the future, ODE will support offset masses,
until that time it'll save a lot of people time if it asserts about it
(and hopefully may spur on development of offset masses!)

Modified Paths:
--------------
    trunk/ode/src/ode.cpp

Modified: trunk/ode/src/ode.cpp
===================================================================
--- trunk/ode/src/ode.cpp       2006-11-06 10:15:20 UTC (rev 1135)
+++ trunk/ode/src/ode.cpp       2006-11-06 17:03:01 UTC (rev 1136)
@@ -475,6 +475,12 @@
   dAASSERT (b && mass );
   dIASSERT(dMassCheck(mass));

+  // The centre of mass must be at the origin.
+  // Use dMassTranslate( mass, -mass->c[0], -mass->c[1], -mass->c[2]
) to correct it.
+  dUASSERT( fabs( mass->c[0] ) <= dEpsilon &&
+                       fabs( mass->c[1] ) <= dEpsilon &&
+                       fabs( mass->c[2] ) <= dEpsilon, "The centre of
mass must be at the origin." )
+
   memcpy (&b->mass,mass,sizeof(dMass));
   if (dInvertPDMatrix (b->mass.I,b->invI,3)==0) {
     dDEBUGMSG ("inertia must be positive definite!");


This was sent by the SourceForge.net collaborative development
platform, the world's largest Open Source development site.

----------------------------------------------------------------------------


I hope this doesn't cause anyone too many problems, and if anyone is
relying on this offset for some reason that I've overlooked then
please post your complaints here! - I think that this is the right
thing to add at this time with the solver in it's current state.

I'm not saying that offset masses should never be added, in fact I
hope in some way that omission of this often very useful feature
(especially for my colleague who is doing a kind of bowling game) is
highlighted and the functionality is added.

Regards,
David


More information about the ODE mailing list