class jets
{
public:
static int n_jet;
bool isVisible;
bool isDead;
bool dying;
irr::scene::IMeshSceneNode* jet_mesh;
};
I etrieve a pointer to jet_mesh, from getSceneNodeFromScreenCoordinatesBB.
How can I access the dying parameter from the pointer ?
My project is getting damn close to alpha release...
TIA,
robert
jets* array_of_jets[100];
for (int x=0; x<100; x++)
{
array_of_jets[x] = new jets;
IAnimatedMesh* AnimatedMesh = SMGR->getMesh("myJet.x");
array_of_jets[x]->jet_mesh = SMGR->addIMeshSceneNode(AnimatedMesh);
// set the meshscenenode ID to a known value
array_of_jets[x]->jet_mesh = ->setID(7777 + x);
array_of_jets[x]->isDead = false;
array_of_jets[x]->isDying = false;
}
// get the pointer to the scene node
IMeshSceneNode* selected_node = getSceneNodeFromScreenCoordinatesBB();
// now... convert that to the structure using the ID as the index into the array
jets* a_jet_from_the_array = array_of_jets[7777 - selected_node->getID()];
// and finally, you can see the dead, dying stuff
if (a_jet_from_the_array->isDead)
{
// delete it from the array?
}
in my app, i actually use the setName() and the setID() functions to be able to get a poitner to the object class when selecting a node or a mesh. I use the ID to set the bit pattern for the 'picking' code, and i use the name (just the ID converted to a string) so that I can find the object later by converting the name back into an integer.
void CSObject::LoadAnimatedSceneNode(char* filename)
{
// return to the base directory
RemoveAnimatedSceneNode();
m_AnimatedMesh = SMGR->getMesh(filename);
if (m_AnimatedMesh)
{
m_AnimatedSceneNode = SMGR->addAnimatedMeshSceneNode(m_AnimatedMesh);
if (m_AnimatedSceneNode)
{
m_AnimatedSceneNode->setPosition(core::vector3df(0,0,0));
m_AnimatedSceneNode->setScale(core::vector3df(1,1,1));
m_AnimatedSceneNode->setMaterialFlag(video::EMF_LIGHTING, CS_USE_LIGHT);
m_AnimatedSceneNode->setMaterialFlag(video::EMF_FOG_ENABLE, CS_USE_FOG);
// add shadow
m_AnimatedSceneNode->addShadowVolumeSceneNode();
SMGR->setShadowColor(video::SColor(220,0,0,0));
}
else m_AnimatedMesh->drop();
}
// set the object type for the editor
SetObjectType(GetObjectType());
}
// be careful here. the 'editor' object requires a bit pattern to be set in order to
// distinguish between node types. if you add another node, make sure to set the id of it also
void CSObject::SetObjectType(OBJECT_TYPE ot)
{
m_ObjectType = ot;
if (m_Node)
{
m_Node->setID(ot);
m_Node->setName(IntToString(m_Id));
}
if (m_AnimatedSceneNode)
{
m_AnimatedSceneNode->setID(ot);
m_AnimatedSceneNode->setName(IntToString(m_Id));
}
}
SetSelectedNode(m_CollMan->getSceneNodeFromScreenCoordinatesBB(m_Level->m_App->m_Engine->m_Device->getCursorControl()->getPosition()));
void CSObject_Editor::SetSelectedNode(ISceneNode* node)
{
// remember this number
m_SelectedNode = node;
// convert the node->name to a number
if (m_SelectedNode) SetSelectedObject(atoi(m_SelectedNode->getName()));
else SetSelectedObject(0);
}
It would be SOOOOOOO much easier if we had a void* UserData stuck in the node code, but my spider sense tells me that opening THAT can of worms again is not worth it
Derive from IAnimatedMeshSceneNode (or whatever). Add pointers to your stuff, or direct data, (or whatever). When getting the scene node via above mentioned function, just cast it to your new scene node type. If done properly with all required checks, it should work.
It's a nice method if you have only a few nodes to derive. If you are looking to select any node though, including terrain, particles, lights etc..., then recreating each as a derived node gets a little more time consuming. storing a void* userData would make the task much simpler I think.
Seven wrote:It's a nice method if you have only a few nodes to derive. If you are looking to select any node though, including terrain, particles, lights etc..., then recreating each as a derived node gets a little more time consuming. storing a void* userData would make the task much simpler I think.
class Jet : public irr::scene::IMeshSceneNode
{
public:
bool m_bMyVar;
};
You can then use reinterpret_cast on the pointer returned by getSceneNodeFromScreenCoordinatesBB to convert the pointer to a class Jet and access your member vars...
I agree that the ID allows you to bitmask when picking, and I also agree that you can derive your scenenode from the base and then add variables to your hearts content. but in the example the original poster gave, it looks like he is storing his data outside of the scenenode (in jets) and wanting to access it based upon which scene node was selected, which he cannot do without some manner of knowing which jets structure is holding the scenenode. I guess he could also just scan the list of jets to see if the scene node matches. I would just prefer to store the link in the name field and then decode it to my understanding.
Seven wrote:I agree that the ID allows you to bitmask when picking, and I also agree that you can derive your scenenode from the base and then add variables to your hearts content. but in the example the original poster gave, it looks like he is storing his data outside of the scenenode (in jets) and wanting to access it based upon which scene node was selected, which he cannot do without some manner of knowing which jets structure is holding the scenenode. I guess he could also just scan the list of jets to see if the scene node matches. I would just prefer to store the link in the name field and then decode it to my understanding.
I think dynamic_cast will do exactly what he wants. This will convert the specific object returned by the raycast call to a "jets" pointer. You can then get at the data via jets->isDead, etc. I believe you'll need "class jets : public scene::IMEshSceneNode" though.