Hey,
I am working on an RTS and i am having trouble figureing out where to start with an Entity class. I need the entity to be associated with its scene node at all times for unit Selection/picking. I was thinking about makeing a custom scene node and adding additional functionality to that for an entity class. Thou i am still not sure, At the moment i have an entity class that loads a model and texture then attaches its self to the scene manager but its a bit to seperated for my needs.
Any idea's would be great. Thanks!
Where to start with an RTS Entity Class?
Re: Where to start with an RTS Entity Class?
you should get lots of opinions on this one.
for me, I set the ID of the scenenode (and the name) to a unique identifier.
node->setId(id);
node->setName(stringc(id));
when picking, I get the scenenode, grab it's id, and then convert that to my object class.
this is just one way of doing it, I am sure there are different methods.
for me, I set the ID of the scenenode (and the name) to a unique identifier.
node->setId(id);
node->setName(stringc(id));
when picking, I get the scenenode, grab it's id, and then convert that to my object class.
Code: Select all
void CSObject::setIdRecursive(ISceneNode* node, int id)
{
if (node)
{
// set the data
node->setID(id);
node->setName(intToStringc(id));
// set all the children also
list<ISceneNode*> list = node->getChildren();
core::list<ISceneNode*>::Iterator Iterator;
for (Iterator = list.begin(); Iterator != list.end(); ++Iterator)
{
setIdRecursive((*Iterator),id);
}
}
}
void CSObject::setId(int id)
{
m_Id = id;
if (getPrimarySceneNode()) setIdRecursive(getPrimarySceneNode(), id);
}
Code: Select all
// pick a node using the mouse cursor location
ISceneNode* CSLevel::selectNode(int screenX,int screenY,long objectflags)
{
// attempt to select a node. use the passed in mask
ISceneNode* node = getCollMan()->getSceneNodeFromScreenCoordinatesBB(position2d<s32>(screenX,screenY),objectflags,true);
return node;
}
void CSLevel::setSelectedNode(ISceneNode* node)
{
m_SelectedNode = node;
CSObject* obj = getObjectFromNode(node);
if (obj) setSelectedObject(obj->getId());
}
CSObject* CSLevel::getObjectFromNode(ISceneNode* node)
{
if (!node) return NULL;
int id = atoi(node->getName());
if (id) { CS_LOG2("getobjectfromnode() ",stringc(id)); }
return getFactory()->getObjectPointer(id);
}
this is just one way of doing it, I am sure there are different methods.
-
- Posts: 91
- Joined: Mon Mar 05, 2012 4:51 pm
- Location: Bristol, UK
- Contact:
Re: Where to start with an RTS Entity Class?
You could have an entity class, with a model value and than cycle through finding when class->model == SelectedModel