applyForce

pokroops
Posts: 2
Joined: Tue Dec 16, 2008 9:46 pm
Location: St.Petersburg, Russia

applyForce

Post by pokroops »

Hi All!
Could anyone please explain btRigidBody::applyForce parameters, please?
Obviously rel_pos should be relative to ceneter of RigidBody mass,
that is, in local coordinates.
But how should be force specified?
Here is the code:

Code: Select all

	
    void applyForce(const btVector3& force, const btVector3& rel_pos) 
    {
        applyCentralForce(force);
        applyTorque(rel_pos.cross(force)*m_angularFactor);
    }
As far as I can see, applyCentralForce 'wants' force in world space,
but then in next line we are crossing it with rel_pos, which is local for sure. Why?

Update:
Actually, the only way for me to get realistic behavior was to modify above code like this:

Code: Select all

	
void applyForce(const btVector3& force, const btVector3& rel_pos) 
    {
        applyCentralForce(force);
        btTransform rotate_with_body;
        rotate_with_body.setIdentity();
        rotate_with_body.setRotation( getCenterOfMassTransform().getRotation() );
        applyTorque(rotate_with_body(rel_pos).cross(force)*m_angularFactor);
    }


Still I'm not too sure I'm doing the right thing so please comment...
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: applyForce

Post by sparkprime »

If I'm reading you right, you've noticed that the relative position is not in local space but is a world space offset from the centre of the body. This surprised me when I found it out but I'm sure there's a good reason for it. At any rate, when you know what's going on it's easy to code for it.
pokroops
Posts: 2
Joined: Tue Dec 16, 2008 9:46 pm
Location: St.Petersburg, Russia

Re: applyForce

Post by pokroops »

Oh yes, now I see.
force = Force direction, in world space.
rel_pos = Distance from COM, in world space.
That's it.
(And of course there's no need to modify applyForce, it can be done outside)
Thanks!