scene::createStateContactPair

Caphalor

09-03-2007 18:02:02

Hi, because it's very uncomfortable to link every body via scene::createContactPair with the other bodies, I looked for a better way and I found createStateContactPair. But the function is empty... :o
Is there another way or must I write this function?

betajaen

09-03-2007 20:00:17

It seems it is. I must of forgot to write it.

The state contact pair would be exactly the same as loop full of createContactPair's, more so as it'd have to check all bodies with specific states.

Caphalor

09-03-2007 21:14:59

Ok. I wrote the function:


// Iterate all through bodies with a state of a, and link them up
// with a state of b.
void scene::createStateContactPair(stateType a, stateType b, bool _both)
{
for (std::map< Ogre::String, nxOgre::body* >::iterator i = mBodies.mCollection.begin();i != mBodies.mCollection.end();++i)
{
if (i->second->isUnderState(a) == true)
{
for (std::map< Ogre::String, nxOgre::body* >::iterator x = mBodies.mCollection.begin();x != mBodies.mCollection.end();++x)
{
if (x->second->isUnderState(b) == true)
{
createContactPair(i->second,x->second);
}
}
}
}
}


It seems to work, now I can continue programming my SpellManager class. :)

What's the use of the _both parameter?

betajaen

09-03-2007 21:37:45

So you can have both contact pairs a <--> b, instead of a -> b. You have the latter in your case.

Caphalor

09-03-2007 21:42:49

So?

// Iterate all through bodies with a state of a, and link them up
// with a state of b.
void scene::createStateContactPair(stateType a, stateType b, bool _both)
{
for (std::map< Ogre::String, nxOgre::body* >::iterator i = mBodies.mCollection.begin();i != mBodies.mCollection.end();++i)
{
if (i->second->isUnderState(a) == true)
{
for (std::map< Ogre::String, nxOgre::body* >::iterator x = mBodies.mCollection.begin();x != mBodies.mCollection.end();++x)
{
if (x->second->isUnderState(b) == true)
{
createContactPair(i->second,x->second);
if (_both == true) createContactPair(x->second, i->second);
}
}
}
}
}


Is there a difference? :?

betajaen

09-03-2007 22:38:35

Not anymore ;)

I'll add it to the SVN if you like.

Caphalor

10-03-2007 11:06:54

That would be great. :)

betajaen

10-03-2007 11:10:36

Done.