Hinge Joint with spring (CustomJoint)

stoneCold.net

07-12-2006 22:06:01

I'm currently working on implementing Newton (OgreNewt) into my Game Framework, and now I'm that far that I need a custom joint type for it....as the title of the topic already states, a Hinge Joint with a configurable spring, like the rear axle of a car. That's even exactly I'd need it for. I already created two classes (derived from OgreNewt::CustomJoint) ... "RearAxle" and "FrontAxle" representing the two axle types a usual car features:

RearAxle -----> Hinge Joint + Spring
FrontAxle -----> Universal Joint + Spring

... but I can't really figure out what to do in the submitConstraint() method as the example that comes with OgreNewt is quite sparely. Is there any? documentation or any examples I can see to understand the couple of functions (localToGlobal, addLinearRow, addAngularRow, ...) better?

[edit]: #exclude "OgreNewt::Vehicle" <--- I need a joint solution :wink:
[edit2]: found -->this<-- and will get my head into it, though I would appreciate any comments, thoughts, (pseudo) code snippets, etc. a lot :wink:

many thanks

stoneCold.net

20-12-2006 19:10:58

Up to now I have got this...void RearAxle::submitConstraint()
{
Ogre::Quaternion globalOrient0;
Ogre::Vector3 globalPos0;

Ogre::Quaternion globalOrient1;
Ogre::Vector3 globalPos1;

localToGlobal( mLocalOrient0, mLocalPos0, globalOrient0, globalPos0, 0 );
localToGlobal( mLocalOrient1, mLocalPos1, globalOrient1, globalPos1, 1 );

addLinearRow( globalPos0, globalPos1, globalOrient0 * Ogre::Vector3(Ogre::Vector3::UNIT_X) );
addLinearRow( globalPos0, globalPos1, globalOrient0 * Ogre::Vector3(Ogre::Vector3::UNIT_Z) );

if(InputManager::getSingleton().getKeyboard()->isKeyDown(OIS::KC_K))
{
if(InputManager::getSingleton().getKeyboard()->isKeyDown(OIS::KC_PGUP))
springK += 0.1;
else if(InputManager::getSingleton().getKeyboard()->isKeyDown(OIS::KC_PGDOWN))
springK -= 0.1;
}
if(InputManager::getSingleton().getKeyboard()->isKeyDown(OIS::KC_T))
{
if(InputManager::getSingleton().getKeyboard()->isKeyDown(OIS::KC_PGUP))
springD += 0.1;
else if(InputManager::getSingleton().getKeyboard()->isKeyDown(OIS::KC_PGDOWN))
springD -= 0.1;
}

addLinearRow( globalPos0, globalPos1, globalOrient0 * Ogre::Vector3(Ogre::Vector3::UNIT_Y) );
CustomJoint::setRowSpringDamper(springK, springD);

Ogre::String debug = "K=" + Ogre::StringConverter::toString(springK) + "D=" + Ogre::StringConverter::toString(springD);
Ogre::Root::getSingleton().getAutoCreatedWindow()->setDebugText(debug);
}

I gladly found out that there's the "CustomJoint::setRowSpringDamper" function which makes it very! :) easy to add spring functionallity, though I don't understand very well, how I should use addAngularRow to achieve Hinge / UniversalJoint behaviour, can someone please point me in the right direction. I'd be very thankful for anything.

thanks