How to manually rotate Bodies ?

Hi

I wonder how one would rotate one body around another body (without using forces).
I have this ragdoll that I’ve been working on last 6 months or so. In a game it would be very handy to be able to
rotate the ragdoll around the ragdolls center, to be able to orient it correctly when the game starts or
when you for some reason would have to “teleport” it to another location.

I know it’s a math question but I have no idea how to solve this and I guess this problem would come up alot
in ODE since you can’t just use a transformgroup like in most scenegraph API’s
Thanks, NewbTon

if you want to rotate body1 around body2 do this (b1,b2 are the Matrices that represent the positions of body1 and body2):

temp = b2.inverse();
b1.mul(temp);
b1.mul(your_rotation_matrix)
b1.mul(b2);

This is only the main idea -how you do the implementation, you’ll have to think about yourself.

Thanks arne. It’s rotating now but they dont change position. Where do I get the position and rotation into one Matrix ?

matrix4f got functions like setRotation(Quat4f) and setTranslation(Vector3f)

I tried using Matrix4f. Still not working.Heres my code. Any idears ?


  Body body1 = getBody();
    Body body2 = inBody.getBody();

    Matrix4f angle = new Matrix4f(inAngle,body1.getPosition(),1f);
    Matrix4f b1 = new Matrix4f(body1.getRotation(),body1.getPosition(),1f);
    Matrix4f b2 = new Matrix4f(body2.getRotation(),body2.getPosition(),1f);
    Matrix4f temp = new Matrix4f(b2);
    temp.invert();
    b1.mul(temp);
    b1.mul(angle);
    b1.mul(b2);

    //
    Vector3f position = new Vector3f();
    Matrix3f rotation = new Matrix3f();
    b1.get(position);
    b1.get(rotation);
    body1.setRotation(rotation);
    body1.setPosition(position);

don’t set a Position in angle. Angle has to be a pure rotation matrix.

Isn’t GeomTransform a sort of TransformGroup ?
I think it would be useful, but I didn’t used it before, so I can’t be sure.

GeomTransform is a Geom inside a Body which contains another Geom (e.g. a Box) When the body collides the Body changes the position and not the GeomTransform. And he wants to changes the Body, because the other way round would be to manipulate the objects itself with the effect of different centers of gravity (always (0|0|0) of the Body and NOT of the geomTransform or whatever). GeomTransforms are useful, when you want to have more complex bounding-structures (e.g. different Geoms inside a Body).

OK. ;D

Well I have to set a position somewhere, since its rotating around a point I guess.
Are you 100 % sure this is working arne ? It’s not working here but then again I dont know what im doing.
I’m really trying HARD to learn how to use matrices but damn…the tuturials advice you to learn trigonemetry first,
the trigonemetry turtorials advice you to learn geometry, the geometry tutorials. advice you to learn algebra.
I don’t know , should I really spent next five years on this ?
Why aint there just some Java library that contains all the functions you will ever need :slight_smile:

You’re setting the position twice - once in angle and once in b1.

Ok - I’m not 100% sure that it works - but it should.

FYI, GeomTransform probably shouldn’t be used for static geometry, only for positioning geometry relitive to its parent Body. The reason I say this is that the less possible points of failture, the easier it is to debug.

You should be able to use the javax.vecmath package to convert the values around. If you don’t know how to use it, it’s probably a good idea to learn. Most 3D API’s either use it, or some variation (the maths is the same).

I am 100% sure that you can manually position Bodies and Geoms. If needed I can dig up my code.

When joints are involved, it’s a little more complex, as you have to also move the attached bodies (or your simulation goes boom). I have solved this problem though.

Cheers,

Will.