[SOLVED] Trigger / to whom to assign?

spacegaier

12-03-2008 21:01:00

I'm trying to work with triggers right now. I've already created one and also a Callback class for it. But there is nothing to see so far. I guess I have to tell the bodies that have to interact with the trigger to do so, but how?

NxOgre::Trigger *trigger = m_pNxScene->createTrigger("trigger", new NxOgre::CubeShape(10,10,10), NxOgre::Pose(Vector3( 0,0,0), Quaternion(Radian(Degree(270)), Vector3(0,1,0))));
myTrigger *mytrigger = new myTrigger();
trigger->setCallback(mytrigger);

class myTrigger : public NxOgre::TriggerCallback::InheritedCallback
{
public :

myTrigger(){ };

void onEnter(NxOgre::Trigger* t, NxOgre::Actor *a)
{
NxOgre::Body * bd = static_cast<NxOgre::Body*>(a);
bd->getEntity()->setMaterialName("DarkGrey");
}

void onLeave(NxOgre::Trigger* t, NxOgre::Actor *a)
{
NxOgre::Body * bd = static_cast<NxOgre::Body*>(a);
bd->getEntity()->setMaterialName("IndianRed");
}

void onInside(NxOgre::Trigger* t, NxOgre::Actor *a)
{
NxOgre::Body * bd = static_cast<NxOgre::Body*>(a);
bd->getEntity()->setMaterialName("RoyalBlue");
}
};

betajaen

12-03-2008 21:18:35

You make them go inside the Trigger Volume. Also double check you have the method names right for that inherited trigger there; check if "On" is not "on".

spacegaier

13-03-2008 14:00:08

Allright, I edited the "O" to "o", but that wasn't the reason why my trigger does not work.

Isn't there anything missing to activate the trigger (I couldn't find anything about in this forum)?

betajaen

13-03-2008 14:06:58

No, that's basically it. You try something more simple and just print out the names of the Actors to the console or log.

But as far as I can tell the function names and arguments exactly match.

spacegaier

13-03-2008 14:31:23

Strange?!? Nothing happens. I've changed my class a bit to test it with logOutputs. The output of the constructor is given out, but the rest not!

class myTrigger : public NxOgre::TriggerCallback::InheritedCallback
{
public :

myTrigger(Ogre::Log *log)
{
m_pLog = log;
m_pLog->logMessage("myTriger Construktor");
};

void onEnter(NxOgre::Trigger* t, NxOgre::Actor *a)
{
NxOgre::Body * bd = static_cast<NxOgre::Body*>(a);
bd->getEntity()->setMaterialName("DarkGrey");
m_pLog->logMessage("++++++++++++++++++++++++ onEnter()");
}

void onLeave(NxOgre::Trigger* t, NxOgre::Actor *a)
{
NxOgre::Body * bd = static_cast<NxOgre::Body*>(a);
bd->getEntity()->setMaterialName("IndianRed");
m_pLog->logMessage("++++++++++++++++++++++++ onLeave()");
}

void onInside(NxOgre::Trigger* t, NxOgre::Actor *a)
{
NxOgre::Body * bd = static_cast<NxOgre::Body*>(a);
bd->getEntity()->setMaterialName("RoyalBlue");
m_pLog->logMessage("++++++++++++++++++++++++ onInside()");
}

private:
Ogre::Log *m_pLog;

};

betajaen

13-03-2008 14:52:24

That is strange, and I'm working with the TriggerSystem right now (Working on a Space theme for Cake) and it's working fine.

Try switching to the FunctionPtr type callback.

spacegaier

13-03-2008 16:08:45

Allright, I found my problem: the Trigger had to be declared as static, otherwise it does not function.

So there is no way, to create a dynamic trigger, isn't it?

betajaen

13-03-2008 16:17:32

I think your wrong there. Triggers aren't static, they're dynamic classes like everything else.

spacegaier

13-03-2008 16:21:32

But that is the only thing I've added:

NxOgre::Trigger *trigger1 = m_pNxScene->createTrigger("trigger1", new NxOgre::CubeShape(goalSize.x, goalSize.y, goalSize.z), NxOgre::Pose(Vector3(-19,goalSize.y/2,0)), "static: yes");
and all worked well.

betajaen

13-03-2008 16:28:42

Ahhh...I thought meant the static type of class in C++. Yes your right triggers must be static in the PhysX sense.