Is PhySX worth the move? + Another little question.

nikki

18-11-2006 08:28:07

I had been using OgreODE in my game, but after PhySX became free for commercial use and all those new additions betajean has made to NxOgre, and since ode requires some extreme tweaking, I've been thinking about moving to PhySX. Is it worth the move?

I have another question:-
In my GameObject framework, each object has a collide event, making it easy to do something when two objects collide. The GameObjectManager (a collision listener) has a function called registerForCollision, which allows an object to receive this event. The GameObjectManaer registers itself as a collision listener when it is created. Since most of you might have used OgreODE before, the relevant functions are implemented like this:-
//Register the GameObject for collision events
void registerForCollision(GameObject *object, OgreOde::Geometry *geom)
{
geom->setUserObject(object);
geom->setUserData(1021993);
}

//This function is called by OgreODE, since GameObjectManager is a
//collision listener.
bool collision(OgreOde::Contact *contact)
{
OgreOde::Geometry *geom1 = contact->getFirstGeometry();
OgreOde::Geometry *geom2 = contact->getSecondGeometry();
if (geom1->getUserData() == 1021993 && geom2->getUserData() == 1021993)
{
GameObject *obj1 = (GameObject*)(geom1->getUserObject());
GameObject *obj2 = (GameObject*)(geom2->getUserObject());
if (obj1 && obj2)
{
obj1->collide(obj2, geom2, contact);
obj2->collide(obj1, geom1, contact);
}
}
else if (geom1->getUserData() == 1021993 && geom2->getUserData() != 1021993)
{
GameObject *obj1 = (GameObject*)(geom1->getUserObject());
if (obj1)
{
obj1->collide(0, geom2, contact);
}
}
else if (geom1->getUserData() != 1021993 && geom2->getUserData() == 1021993)
{
GameObject *obj2 = (GameObject*)(geom2->getUserObject());
if (obj2)
{
obj2->collide(0, geom1, contact);
}
}
return true;
}

And a GameObject, for example, a Player, implements its collide event like this:-
//Registration called on creation
GlbVar.goMgr->registerForCollision(this, mGeom);

//The collide event
void Player::collide(NGF::GameObject *other, OgreOde::Geometry *otherGeom, OgreOde::Contact *contact)
{
contact->setBouncyness(0);
contact->setFrictionMode(OgreOde::Contact::Flag_FrictionPyramid);
contact->setCoulombFriction(0);
Vector3 hitPos = contact->getPosition();

if (other)
{
//if (other->hasFlag("Crate") && (contact->getPosition().y > (mNode->getPosition().y - 3)))
if (other->hasFlag("LevelObj"))
{
contact->setSoftness(5, 0.0001);
}
if (other->hasFlag("Acid"))
{
die();
}
}
if (contact->getPosition().y < (mNode->getPosition().y - 3))
{
contact->setCoulombFriction(OgreOde::Utility::Infinity);
}
}

Is it possible to do this in NxOgre? If so, is it this easy?

Thanks for the help. :)

betajaen

18-11-2006 09:19:58

Well PhysX doesn't use collision callbacks as much as that.

But for your second part of the code, that can be completely replaced with the states system, with most of that collision and detection code written for you.

You could probably do it in around 5 lines.

nikki

18-11-2006 09:39:28

Cool! Is there any place (online) where I can get to see more of this states feature? Its an NxOgre feature, and not a PhySX one, right? Does NxOgre come with a states demo?

Does NxOgre, in one of its headers, have 'using namespace Ogre'?

betajaen

18-11-2006 09:46:49

It's part of NxOgre, and there are four states tutorials so far with 0.4RC2:

- Introduction; Gravity and No Gravity states
- State Triggers (areas in space that apply a state on entering, and removing it when they leave).
- Custom states, in this case fire!
- And the best one for last; magnetics and gravity fields.

The book has a chapter on states, although the framework has changed a little, it is really worth reading it for that.

No, we don't have "using namespace nxOgre" in it's headers, you'll have to do that yourself. :D

nikki

18-11-2006 09:48:25

Do I need to distribute a copy of the System software when I destrubute my game?

betajaen

18-11-2006 09:52:46

Yep.

nikki

18-11-2006 10:09:31

After having a quick read through you (hilarious) guide, I have seen that what happens when two objects collide will be handled by the stateMachine. How I want it is that each GameObject must handle itself. Does a Body have a UserData member, so that I can set it to a pointer to the GameObject it represents and call the collide function of that GameObject when it collides with another Body?

betajaen

18-11-2006 10:25:31

You'd use a customContactReporter class. We don't have a UserData variable in bodies, as it's un-OO like. You should inherit the body class or store it as a member in your GameObject.

betajaen

18-11-2006 11:04:54

Just for you. I'm adding a 3rd constructor and modifying scene which allows easy inheritance of the body class into your own.