[ODE] complex geometries

skjold@cistron.nl skjold at cistron.nl
Wed Mar 12 11:27:02 2003


Hi,

Using the boxstack test as an example for this, I wrote a function that performs all the necessary steps to create a compound geom. It simply accepts arrays of geoms and masses, and positions and rotations for each of them.

Note, all parameters are IN - i.e. no values are returned, all parameters should have valid values upon calling this function. Also, the function currently depends on the existance of a MAXCOMPOUNDGEOMS define. This value represents the maximum number of geoms that can be defined. If you want, you can easily change the function to use some smarter dynamic allocation scheme instead.


void compoundGeom(
    dBodyID aBodyID,   // Body associated with the geoms
    dSpaceID aSpaceID, // Space to put the geoms in
    int aNumGeoms,     // Number of geoms to combine
    dGeomID* aGeoms,   // Array of geoms to be combined
    dMass* aMasses,    // Array of masses for the geoms
    dVector3* aPos,    // Array of positions for the geoms
    dMatrix3* aRot     // Arrao of rotations for the geoms
    ) {
    ASSERT(MAXCOMPOUNDGEOMS < aNumGeoms);

    int i; // Used in several for-loops (scope ambiguity issue)
    dGeomID lXgeoms[MAXCOMPOUNDGEOMS]; // @@@NOTE: Hardcoded max number of components!

    // To accumulate the total mass of the compound geom
    dMass lMass;
    dMassSetZero (&lMass);

    // This is the space where the geoms are inserted.
    // If you want to put each compound geom into a new
    // space, you could use the following line:
    // dSpaceID lSpaceID = dSimpleSpaceCreate(aSpaceID);
    dSpaceID lSpaceID = aSpaceID;


    // Time to combine the geoms
    for(i = 0; i < aNumGeoms; i++) {

        // Put the geom into a transform-geometry
        lXgeoms[i] = dCreateGeomTransform(lSimpleSpaceID);
        dGeomTransformSetCleanup(lXgeoms[i], 1);
        dGeomTransformSetGeom(lXgeoms[i], aGeoms[i]);

        // Set the transformation for the geom and its mass
        dGeomSetPosition(aGeoms[i], aPos[i][0],aPos[i][1],aPos[i][2]);
        dMassTranslate(&aMasses[i],aPos[i][0],aPos[i][1],aPos[i][2]);
        dGeomSetRotation(aGeoms[i],aRot[i]);
        dMassRotate(&aMasses[i], aRot[i]);

        // Add to the total mass
        dMassAdd (&lMass,&aMasses[i]);
    }

    // Move all encapsulated objects so that the center of mass is (0,0,0)
    for(i = 0; i < aNumGeoms; i++) {
        dGeomSetPosition (aGeoms[i],
            aPos[i][0] - lMass.c[0],
            aPos[i][1] - lMass.c[1],
            aPos[i][2] - lMass.c[2]);
    }
    dMassTranslate (&lMass,-lMass.c[0],-lMass.c[1],-lMass.c[2]);

    // Attach to the dBody
    for(i = 0; i < aNumGeoms; i++) {
        dGeomSetBody(lXgeoms[i], aBodyID);
    }
    dBodySetMass(aBodyID, &lMass);
}

I hope it's useful.
Greets,
Mark


> dear mailinglist,
> 
> i want to build a more complex geometry made up of several boxes and 
> cylinders. this geometry should be handeld as a single body in my simulation. 
> odes documentation tells me, that the fixed joint is not a good idea and that 
> i should represent the sub-bodies as a single body.
> 
> how do i do that? right now i have several bodies and geometry objects and my 
> construction just falls to pieces.
> 
> thanks for help, c.
> -- 
> -__________________________________________
> Dr. rer. nat. Dipl.-Phys. C. Verbeek
> email: christian.verbeek@ais.fraunhofer.de
> room: C2-214
> http://www.ais.fraunhofer.de/~verbeek
> phone: +49 2241 14 2057
> fax  : +49 2241 14 2384
> 
> _______________________________________________
> ODE mailing list
> ODE@q12.org
> http://q12.org/mailman/listinfo/ode
>