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
[SOLVED] Selection box result
-
- Gnoblar
- Posts: 8
- Joined: Sun Jul 21, 2013 9:17 pm
[SOLVED] Selection box result
Last edited by Warl33k on Mon Mar 02, 2015 5:33 pm, edited 1 time in total.
- spacegaier
- OGRE Team Member
- Posts: 4304
- Joined: Mon Feb 04, 2008 2:02 pm
- Location: Germany
- x 135
- Contact:
Re: Selection box result
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:
References:
http://www.ogre3d.org/docs/api/latest/c ... 8132f2f01f
http://www.ogre3d.org/docs/api/latest/c ... 24e89bf4b6
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...
}
http://www.ogre3d.org/docs/api/latest/c ... 8132f2f01f
http://www.ogre3d.org/docs/api/latest/c ... 24e89bf4b6
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...
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
-
- Gnoblar
- Posts: 8
- Joined: Sun Jul 21, 2013 9:17 pm
Re: Selection box result
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 !
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 !