rotating composite bodies

Hi - How do you rotate composite bodies? I have one that is made up of a number of GeomTransforms, and I’m trying to rotate it around its Z-axis at a particular angular velocity, but I’m having no luck.

I’ve tried using the setAngularVel() method on the body and I’ve also tried using AMotors, but the body just doesn’t rotate.

How about applying a torque about the z-axis?

That doesn’t seem to have any effect either.

Here is the code that I’m using. Does it look right?


    this.sideWalls = new Body(world);
    this.sideWalls.setGravityMode(0);

    this.groundGeomB = new GeomBox((float)this.bounds.getWidth(), 10f, 50f);
    this.groundGeomT = new GeomBox((float)this.bounds.getWidth(), 10f, 50f);
    this.groundGeomL = new GeomBox(10f, (float)this.bounds.getHeight(), 50f);
    this.groundGeomR = new GeomBox(10f, (float)this.bounds.getHeight(), 50f);

    this.groundGeomBE = new GeomTransform("t1");
    this.groundGeomTE = new GeomTransform("t2");
    this.groundGeomLE = new GeomTransform("t3");
    this.groundGeomRE = new GeomTransform("t4");

    this.groundGeomBE.setEncapsulatedGeom(this.groundGeomB);
    this.groundGeomTE.setEncapsulatedGeom(this.groundGeomT);
    this.groundGeomLE.setEncapsulatedGeom(this.groundGeomL);
    this.groundGeomRE.setEncapsulatedGeom(this.groundGeomR);

    this.sideWalls.addGeom(this.groundGeomBE);
    this.sideWalls.addGeom(this.groundGeomTE);
    this.sideWalls.addGeom(this.groundGeomLE);
    this.sideWalls.addGeom(this.groundGeomRE);

    this.groundGeomB.setPosition(0f, (float)(-1 * this.bounds.getHeight()/2 - 5), 0f);
    this.groundGeomT.setPosition(0f, (float)(this.bounds.getHeight() + 5), 0f);
    this.groundGeomL.setPosition((float)(-1 * this.bounds.getWidth()/2 - 5), 0f, 0f);
    this.groundGeomR.setPosition((float)(this.bounds.getWidth()/2 + 5), 0f, 0f);

    this.geomIDs.add(this.groundGeomBE.getNativeAddr());
    this.geomIDs.add(this.groundGeomLE.getNativeAddr());
    this.geomIDs.add(this.groundGeomRE.getNativeAddr());
    this.geomIDs.add(this.groundGeomTE.getNativeAddr());

    this.sideWalls.adjustMass(10f);
    this.sideWalls.setPosition((float)(this.bounds.getWidth()/2 + this.bounds.getX()),
                         (float)(this.bounds.getHeight()/2 + this.bounds.getY()),
                         0f);


    space.addBodyGeoms(this.sideWalls);
    this.sideWalls.setAngularVel(50, 0, 0);
    this.sideWalls.addRelTorque(5000,0,5000);

This looks right… The body should rotate regardless of the geoms attached to it. Are you sure that world.step() or world.quickStep() is being called iteratively?

edit:
Is the Body in contact with any other geoms that are keeping it from turning?

It seems to be fixed now. I had to manually set an inertial tensor and center of mass with setMassParameters. I also changed the ordering around a bit. Not sure why this was necessary though.

Thanks for the help though :stuck_out_tongue:

Ah yes. A Body with transformed geoms does not seem to function correctly (at least correctly determine collisions in my experience) unless initial inertial parameters are set.