How to rotate btHingeConstraint by 90 degree in one minute

smallping
Posts: 11
Joined: Fri Oct 19, 2012 3:37 am

How to rotate btHingeConstraint by 90 degree in one minute

Post by smallping »

I am new to Bullet, and I have a question.
I want to rotate my btHingeConstraint by 90 degree in one minute with constant velocity, and then stop. For example, I have rigid body actorBox1, and another rigid body actorBox2, I want to actorBox2 rotate around the edge of actorBox1 with 90 degree in one minute, and then stop there.

Here is my code.

//*************************************************

//In the InitPhysics(), I create the rigid body and btHingeConstraint.

void InitPhysics()
{
......
......

btRigidBody* actorBox1 ; //already create, a box with half extend (1.0,1.0,1.0)
btRigidBody* actorBox2 ; //already create, a box with half extend (1.0,1.0,1.0)
btHingeConstraint* jointBox;

btTransform local1, local2 ;
local1.setIdentity();
local1.setOrigin(btVector3(btScalar(-1.0), btScalar(+1.0), btScalar(0.0))); //rotate point
local2.setIdentity();
local2 = actorBox2->getWorldTransform().inverse() * actorBox1->getWorldTransform() * local1;

jointBox = new btHingeConstraint(*actorBox1, *actorBox2, local1, local2);
jointBox->setLimit(btScalar(0.0), btScalar(+g_dPI/2));
m_world->addConstraint(jointBox, true);

m_world->setInternalTickCallback(motorPreTickCallback,null,true); //setInternalTickCallback function
}

//Then in the motorPreTickCallback function, I write like this

void motorPreTickCallback (btDynamicsWorld *world, btScalar timeStep)
{
jointBox->enableAngularMotor(true, 3.14/2/60, 0.5);
}

Now the Box2 can only rotate around Box1 one time, with 1.5 degree, and then stops. I know there is something wrong in motorPreTickCallback function.
But I do not understand enableAngularMotor very well, and I do not know how to set targetVelocity and maxMotorImpulse.

Can anybody help me?
Thanks
Best regards
papaonn
Posts: 41
Joined: Wed Nov 20, 2013 4:14 pm

Re: How to rotate btHingeConstraint by 90 degree in one minu

Post by papaonn »

Hi i am not very familiar with enableAngular stuffs,

just few guess :

1) did you set up lower and upper limit for angular rotation yet?
because so far i had not seen you have set the limitation for angular rotation.

2) The 2nd argument for enableAngularMotor is the targetVelocity, i am assuming the name stands for where the target velocity will reach at the final destination, since it's constant so it will always stop at the target angular velocity? (not too sure, but you might want to try if you set it to a changing variable would it resolve?)

3) Is the motorPreTickCallback run-time loop working fine? probably do a check by putting a printf("executing loop ..\n") to check for the situation.


Thanks