[Solved] CharacterHitReport question

spacegaier

09-07-2008 21:07:13

Hello,

I'm implementing a CharacterHitReport. If my character hits an item, the item shall change the colour. But how can I identify which item was hit.

I can check via the ActorGroup that is given by the onActor() funtion whether the hit actor is an item (as all items are in the same group), but how can I get now the item to call the cangeItemColour() function?

class CPlayerHitReporter : public NxOgre::CharacterHitReport
{
public:
NxOgre::CharacterHitReport::Response onActor(NxOgre::Character *, NxOgre::Actor *actor, NxOgre::Shape *, NxOgre::ActorGroup *actorGrp, const NxControllerShapeHit &)
{
if(actorGrp->getName() == "ItemGrp")
{
// Change colour here //
}
}

private:

};


PS: Sorry for the bad title, but I don't find a better one.

spacegaier

10-07-2008 09:17:53

I've got it.

The onActor() function tells me the actor involved and I can retrieve its name und compare it with all the names of the items.

betajaen

10-07-2008 09:58:00

Usually, it's faster if you can compared pointers of the two classes. Assuming you have them handy.

spacegaier

10-07-2008 10:35:59

So, you would advice my to get the NxOgre::Actor pointer of my CItem and comnpare it to the NxOgre::Actor pointer given by on Actor()?

If yes, how can I get the NxOgre::Actor of a NxOgre::Body (because that is what my CItem has)? I've only found a function to get the NxActor out of a NxOgre::Body.

betajaen

10-07-2008 11:09:52

Using your code, and "CItem" is cItem:

NxOgre::CharacterHitReport::Response onActor(NxOgre::Character *, NxOgre::Actor *actor, NxOgre::Shape *, NxOgre::ActorGroup *actorGrp, const NxControllerShapeHit &)
{
if(actor == cItem->mActor)
{
}
}

spacegaier

10-07-2008 11:31:25

Huh? That does not function. My CItem class has no actor. There is only a NxOgre::Body. So where should this cItem->mActor come from?

Shall I take the NxActor?

Sorry, but I'm totally confused now.

betajaen

10-07-2008 12:07:49

Ignore the term NxActor; it doesn't apply it. With general usage of NxOgre; you never met the class. So forget the term.

Right, back to topic. The NxOgre::Body is a NxOgre::Actor too. But not the other way around. Just think of a NxOgre::Body as a Actor with some code to tell Ogre to render itself on the screen.

Now; You can still compare the pointers because they are both actors.

if (actor == citem->mBody) {
// do code.
}

spacegaier

10-07-2008 14:19:42

Right, back to topic. The NxOgre::Body is a NxOgre::Actor too. But not the other way around. Just think of a NxOgre::Body as a Actor with some code to tell Ogre to render itself on the screen.

I knew that, however I did not know that this will function

You can still compare the pointers because they are both actors.

Thanks. It works now!!!