applytorque about specific point?

Rob_Theed
Posts: 7
Joined: Thu Jul 29, 2010 10:16 am
Location: Taunton UK

applytorque about specific point?

Post by Rob_Theed »

Hi all,

I have a rigid body composed of a compound collision shape, and I want to apply a torque to the body but only about one of the child shapes of the compound. Does anyone know of a way to apply a torque to the body in this way?

Many thanks.
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: applytorque about specific point?

Post by ola »

Torque in itself cannot be applied to a specific point on a body. This is not a limitation in Bullet but rather just how the concept "torque" is defined.

The rigid body will always rotate around its center of gravity which is fixed in (0,0,0). So to move the center of gravity in Bullet you'll have to translate all your compound child shapes the opposite way instead (meaning, if c.g. should be in (1,0,0), translate all your child shapes with (-1,0,0) to get the result you're after).

Or maybe you want to fix it to some rotation axis by using a hinge constraint.

You can also apply a force with btRigidBody::applyForce(const btVector3& force, const btVector3& rel_pos), which actually does this: (from btRigidBody.h)

Code: Select all

	void	applyForce(const btVector3& force, const btVector3& rel_pos) 
	{
		applyCentralForce(force);
		applyTorque(rel_pos.cross(force*m_linearFactor));
	}

This will cause both translation and rotation.

Cheers,
Ola
Rob_Theed
Posts: 7
Joined: Thu Jul 29, 2010 10:16 am
Location: Taunton UK

Re: applytorque about specific point?

Post by Rob_Theed »

Yeah I understand that you can only apply a torque about the point which is "fixed", i.e its centre of gravity or some other fixed point( like a cam on a shaft) .

I guess what I really need to do is like you said, and generate separate rigid bodies with fixed joints between them, that way I can apply the torque directly to the correct rigid body.

many thanks for your help.
robagar
Posts: 48
Joined: Fri May 21, 2010 1:49 am

Re: applytorque about specific point?

Post by robagar »

Thought I'd just post my code for doing that ...

Code: Select all

  
  btTransform frameInA;
  frameInA.setIdentity();
  frameInA.setOrigin(position_of_B_in_A_local_coordinates);
  
  // attachment point for B is at its center of gravity
  btTransform frameInB;
  frameInB.setIdentity();

  btGeneric6DofConstraint* pConstraint = new btGeneric6DofConstraint(
    pBodyA,
    pBodyB,
    frameInA,
    frameInB, 
    true);
  
  // lock all degrees of freedom
  for(int i=0; i<6; ++i)
    pConstraint->setLimit(i, 0, 0);

  pDynamicsWorld->addConstraint(pConstraint, true);
hth Rob
Rob_Theed
Posts: 7
Joined: Thu Jul 29, 2010 10:16 am
Location: Taunton UK

Re: applytorque about specific point?

Post by Rob_Theed »

Cheers robagar, so Im doing similar to your code there (many thanks btw) and im having real difficulty getting the constraints to actually lock, they seem really soft like a spring im not using the btGeneric6DofSpringConstraint so there should be very little or no "play" in the joints.

Any ideas.

cheers, Rob.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: applytorque about specific point?

Post by Erwin Coumans »

If you want to shift the center of mass, in order to apply a rotation, it is best to use a btCompoundShape, as ola mentioned.

There are various reasons why constraints are not very stiff, big mass ratios is one of them (100 kilo attached to 1 kilogram etc). Again, in your case you might want to try out the btCompoundShape to shift the center of mass, by varying the child transforms.

Thanks,
Erwin
Rob_Theed
Posts: 7
Joined: Thu Jul 29, 2010 10:16 am
Location: Taunton UK

Re: applytorque about specific point?

Post by Rob_Theed »

Ok thanks very much guys. The help is very much appreciated. I'm so impressed with the level of support on this forum, its great.