Joint limits and motors

n1000

08-04-2007 04:08:54

I was hoping someone could point me to a code example of setting a limit on a joint as well as a motor to turn the joint some set amount (and hold the position regardless of any forces (like gravity)).

I'm kind of new to physics so I'm not sure where to begin. Thanks.

Alpha_Blend

08-04-2007 21:48:43

Hi to all (it's my first time in the forum..).
I have the same problem in order to implement a motor joint.
As an example, suppose you have two rigid bodies (cylinders) connected
by an hinge joint and that you want to control the rotation of one of these
relatively to the other around the X axis (like a forearm relatively to the arm).

I've tried this way. First I wrote two differents hinge
callback functions, one for bending and one for resting:

static void armBend(OgreNewt::BasicJoints::Hinge* me)
{
Real stop = me->calculateStopAlpha(Degree(90.0));
me->setCallbackAccel(stop);
}

static void armRest(OgreNewt::BasicJoints::Hinge* me)
{
Real stop = me->calculateStopAlpha(Degree(0.0));
me->setCallbackAccel(stop);
}


At the moment of the joint creation, the armRest callback is passed, so the two bodies
are fixed:


................
MyJoint = new OgreNewt::BasicJoints::Hinge(mWorld, childbody, parentbody, pos, Vector3::UNIT_X);
MyJoint->setCallback(armRest);
................


then, a key pressed or released fire the two different callbacks:


bool MyKeyListener::keyPressed(const OIS::KeyEvent &arg)
{
switch(arg.key){
case(OIS::KC_U):
MyJoint->setCallback(armBend);
break;
...
}
}


bool MyKeyListener::keyReleased(const OIS::KeyEvent &arg)
{
switch(arg.key){
case(OIS::KC_U):
MyJoint->setCallback(armRest);
break;
...
}
}


When I press the key all is correct: the forearm bend until 90 degree and stay, but when I release the key
the forearm come back very,very fast and overcome the original position before to stop at 0.0 degree.

Thanks in advance for help....

Alpha_Blend

20-04-2007 11:57:46

Ok, ok not a very exciting topic, but anyway...
I have read somewhere in the forum that joint callbacks use ONLY static functions. This means that I can't use a variable in my callback ???
Example:

MyClass
{
private:
Real MyVar;
static void MyHingeCallback(OgreNewt::BasicJoints::Hinge* me);
....
somewhere in the constructor
MyVar = 10.0;
}

void MyClass::MyHingeCallback(OgreNewt::BasicJoints::Hinge* me)
{
me->setCallbackAccel(MyVar);
}

Vectrex

22-05-2008 20:30:18

hah massively old thread but I may as well answer it :)
"This means that I can't use a variable in my callback ???"
not sure about the static only bit, but when you create your class just set the joint's userData to the class instance
eg joint->setUserData(myClass); // Note myClass NOT MyClass

then in the callback you can just go
(MyClass*)me->getUserData;
or
((MyClass*)me->getUserData)->MyVar;
or
MyClass* myClass = (MyClass*)me->getUserData;
myClass->MyVar;

same idea goes for bodies;