NxOgre Tutorial 4: Little trouble understanding

KyleKatarn

25-10-2009 21:52:36

Hey

Im trying to suss out triggers and volumes, and I've got a question about the tutorial. How does the program know about mVolume? mVolume has only 2 lines, a declaration and an initialisation, there is no logic that applies to it, all there is is onVolumeEvent, which is only declared,and had logic put into, and yet it isnt called anywhere else in the program. So my question really is how does it know to apply mVolume to the onVolumeEvent, when neither are mentioned together?

betajaen

25-10-2009 22:09:44

The class "BloodyMessTutorial4" inherits NxOgre::Callback, the "this" argument in the mVolume creation code refers to this class. So the Volumet knows what the callback is.

KyleKatarn

25-10-2009 23:37:32

I see, so how would I use it to call a separate volume event function for different volumes? Would I name the volume event function in place of "this"?

spacegaier

26-10-2009 08:35:21

Each NxOgre::Actor has a name. So in the volume callback function you could check it and react according to it.

KyleKatarn

26-10-2009 12:06:57

So does this mean that I can only have one Volume call back function per class which inherits it? What I meant by the first post is that I'm trying to have a different event happen for each specific type of volume, not based on what or who enters it, for example, an automatic door in a shopping mall, which will activate for any object that comes in range, not for a specific actor, can I have separate events using callbacks?

betajaen

26-10-2009 12:44:42

Yes, one callback function per class that inherits it, but you can have as many classes as you want remember.

Using your AutomaticDoor example, this is how I would do it.

class AutomaticDoorCallback : public NxOgre::Callback
{
AutomaticDoorCallback(AutomaticDoor* door) : mDoor(door) {}

void onVolume(...., int collisionEvent)
{
if (collisionEvent & NxOgre::Enums::VolumeCollisionType_OnEnter && mDoor->isClosed())
mDoor->open();
else if (collisionEvent & NxOgre::Enums::VolumeCollisionType_OnExit && mDoor->isOpen())
mDoor->close();
}

AutomaticDoor* mDoor;
};



mDoor = createMyDoor();
mDoorCallback = new AutomaticDoorCallback(mDoor)
mDoorVolume = mScene->createVolume(new NxOgre::Box(4), mDoor->getPosition(), mDoorCallback, NxOgre::Enums::VolumeCollisionType_All);


Of course, if you don't like separate door callbacks like that, there is no reason why you can't have an AutomaticDoor class inheriting Callback, and having then Volume as a member variable then everything is bound together in the AutomaticDoor constructor. So if you want a automatic door, you create one, and it's all neatly created for you.

That's how I would really do it. ;)

KyleKatarn

26-10-2009 13:15:19

Ah, genius. Thanks a tonne, guys. :)

KyleKatarn

02-11-2009 00:22:18

Hey, sorry for the doublepost.

I've got another question reguarding volumes. How can I get the name, ID, or some other form of identification of a player who enters a volume. Say for example, a weapons pickup in a multiplayer game, if my character picks up a new gun, how would I let the program know which player picked up the said weapon?

Thanks