[SOLVED] Selection box result

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Warl33k
Gnoblar
Posts: 8
Joined: Sun Jul 21, 2013 9:17 pm

[SOLVED] Selection box result

Post by Warl33k » Sun Mar 01, 2015 5:57 pm

Hello

I'm trying to make a basic RTS unit control but I'm stuck with the selection box. I followed the intermediate tutorial about it, and it work. Problem is the query's result is a list of movableObject, and I can't cast them to my character object.
Is it possible to get a list of character instead of movableobject ? Or how can I cast/convert them ?

ps : my character class inherit from ogre::entity

Thanks for your help
Last edited by Warl33k on Mon Mar 02, 2015 5:33 pm, edited 1 time in total.
0 x

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4293
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: Selection box result

Post by spacegaier » Sun Mar 01, 2015 8:00 pm

Since Ogre doesn't know your custom character class, it of course cannot handle instances of it directly. So all you can get is this list of MovableObjects. As a result you will have to check at runtime if the MovableObject is indeed one of your characters.

Note: The best practice in general is not to inherit from Ogre::Entity, but use composition = your character class should have a member pointer to an Ogre::Entity.

The most elegant way to solve your problem is to attach a pointer to your character class to the MovableObject. See this untested code snippet:

Code: Select all

Character* pC = new Character();
Ogre::Entity* pE = m_pSceneMgr->createEntity();
pE->getUserObjectBindings()->setUserAny("character", pC);

// to later retrieve the character pointer, when iterating over the MovableObject list

Ogre::Any a = pMovableObjectFromSceneManagerList->getUserObjectBindings()->getUserAny("character");
if(!a.isEmpty())
{
    Character* pC = dynamci_cast<Character*>(a);
    // now do stuff...
}
References:
http://www.ogre3d.org/docs/api/latest/c ... 8132f2f01f
http://www.ogre3d.org/docs/api/latest/c ... 24e89bf4b6
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

Warl33k
Gnoblar
Posts: 8
Joined: Sun Jul 21, 2013 9:17 pm

Re: Selection box result

Post by Warl33k » Mon Mar 02, 2015 5:26 pm

Hello,

after trying again and again, It finally work !

Thanks for you help on this, and also thanks for the advice (not inherit class from Ogre::Entity)

You made my day ! :mrgreen:
0 x

Post Reply