Joints

Pakaffy

30-06-2009 15:07:58

Halp! Again..

So, I am writing a physics manager at the moment, but joints are confusing me a bit (Just cos I can't seem to find any resources that demonstrate the correct assembly of joints in the latest version of NxOgre. I have found many for older versions, howezza!) Basically what i'm after is a way of tacking objects to a vertical wall, such as platforms that tilt back and forth like a ship from the center. I figured revolute or spherical joints would be best for this? How do the local axis and anchors differ from the global anchor and axis from previous versions?

It would be great if someone could help me out a bit :D

- Pakaffy

spacegaier

30-06-2009 16:27:18

Don't really understand what you want to accomplish, but for plattforms you should usually use KinematicActors.

I currently don't have the time to explain the joint thing, but having a look at the NVIDIA PhysX SDK (especially the samples) should help a lot.

Here is also some code that works (I hope I didn't loose anything while copying it here). I used it as a testing case for me. The screenshot below, shows the model I used for this in Blender (this orange thing is just for showing you, where my joint is). In my case, you can move the fore-most part of this "crane" up and down via the keys.

Creation code::
ResourceSystem::getSingleton()->openArchive("media", "file:D:/Visual Studio 2005 Workspace/Projects/NxOgre Demo/NxOgre Demo/bin/release/media");
NxOgre::Mesh* pRootMesh = NxOgre::MeshManager::getSingleton()->load("media:Root.nxs");

NxOgre::TriangleGeometry* tg = new NxOgre::TriangleGeometry(pRootMesh);
NxOgre::TriangleGeometry* tgArm_01 = new NxOgre::TriangleGeometry(NxOgre::MeshManager::getSingleton()->load("media:Arm_01.nxs"));
NxOgre::TriangleGeometry* tgArm_02 = new NxOgre::TriangleGeometry(NxOgre::MeshManager::getSingleton()->load("media:Arm_02.nxs"));

OGRE3DKinematicBody *k = m_pRenderSystem->createKinematicBody(tg, NxOgre::Real3(-10, 0, 0), "Root.mesh");
OGRE3DKinematicBody *pBodyArm_01 = m_pRenderSystem->createKinematicBody(tgArm_01, NxOgre::Real3(-10, 8.5, 2.5), "Arm_01.mesh");

NxOgre::RigidBodyDescription d;
d.mBodyFlags = NxOgre::Enums::BodyFlags_DisableGravity;

pBodyArm_02 = m_pRenderSystem->createBody(tgArm_02, NxOgre::Real3(-10, 9, 4), "Arm_02.mesh", d);

NxOgre::RevoluteJointDescription descr;
descr.mLocalAnchor[0] = Real3(0, 1, 1);
descr.mLocalAnchor[1] = Real3(0, 1, -2);
descr.mLocalAxis[0] = Real3(1, 0, 0);
descr.mLocalAxis[1] = Real3(1, 0, 0);
descr.mLocalNormal[0] = Real3(0, 0, 1);
descr.mLocalNormal[1] = Real3(0, 0, 1);
NxOgre::JointLimitDescription ldescr01;
ldescr01.mRestitution = 0;
ldescr01.mValue = -0.2;
NxOgre::JointLimitDescription ldescr02;
ldescr02.mRestitution = 0;
ldescr02.mValue = 1.5;
Pair<JointLimitDescription> pair;
pair.first = ldescr01;
pair.second = ldescr02;
NxOgre::RevoluteJoint* rj = m_pScene->createRevoluteJoint(pBodyArm_01, pBodyArm_02, descr);
rj->setLimits(pair);

Movement code:
if(OgreFramework::getSingletonPtr()->m_pKeyboard->isKeyDown(OIS::KC_U))
{
pBodyArm_02->addForceAtLocalPos(Real3(0, 20, 0), Real3(0, 0, 2), Enums::ForceMode_Force);
}

if(OgreFramework::getSingletonPtr()->m_pKeyboard->isKeyDown(OIS::KC_J))
{
pBodyArm_02->addForceAtLocalPos(Real3(0, -20, 0), Real3(0, 0, 2), Enums::ForceMode_Force);
}