Selecting a custom node

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Selecting a custom node

Post by BillyCallahan »

Hola,

Once again I'm stuck...I'm trying to make my custom scene nodes selectable using different methods, such as:

Code: Select all

            
scene::ISceneNode* pNode = 0;
core::line3df collRay;
core::triangle3df collTriangle;
core::vector3df collPoint;
 
collRay = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(receiver.GetMouseState().Position, smgr->getActiveCamera());
pNode = smgr->getSceneCollisionManager()->getSceneNodeAndCollisionPointFromRay(collRay, collPoint, collTriangle, 0, 0);
 
This one always returns Null.

Code: Select all

smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB()
This one would be perfect if my " core::aabbox3d<f32> Box " were not so big that they cover other custom nodes. So, when I click on a node, another one is selected.

Code: Select all

smgr->getSceneCollisionManager()->getCollisionPoint()
I had hope with this one, but I can't set a selector because I don't have any Mesh.


Trust me, I've been through a lot of forums and topics, and the only answers I found were to change my custom node for something else...Which I absolutely don't want !

Billy :)
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Selecting a custom node

Post by Seven »

I setup my objects to have an objecttype variable (you could do with the scenenode ID also)

I then copied the void CSLevel::getPickedNodeBB(int flag, ISceneNode* root, core::line3df& ray, s32 bits, bool noDebugObjects, f32& outbestdistance, ISceneNode*& outbestnode) code and modified it to call a function like

Code: Select all

 
    bool CSLevel::isSelectable(CSObject* obj, int flag)
    {
        if (!obj) return false;
        if (obj->isFlagged(CSO_DEBUGOBJECT)) return false;
        if (obj->isFlagged(flag)) return true;
        else return false;
    }
 
although not exactly what you need, the idea is the same.

set different ID's for your scenenodes so that you can select different 'types'
copy the selection code from the collisionmanager
modify it to select only the object type you are wanting.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Selecting a custom node

Post by Seven »

Code: Select all

 
    //! recursive method for going through all scene nodes
    void CSLevel::getPickedNodeBB(int flag, ISceneNode* root, core::line3df& ray, s32 bits, bool noDebugObjects, f32& outbestdistance, ISceneNode*& outbestnode)
    {
        const ISceneNodeList& children = root->getChildren();
        const core::vector3df rayVector = ray.getVector().normalize();
 
        ISceneNodeList::ConstIterator it = children.begin();
        for (; it != children.end(); ++it)
        {
            ISceneNode* current = *it;
 
            if (current->isVisible())
            {
                // in my instance, i use the scenenodes ID to match it to the Object (CSObject* type) 
                CSObject* obj = getObjectFactory()->getObjectPointer(current->getID());
                // once i have the object, i see if it is selectable based on the flag that the user passed in
                if ((noDebugObjects ? !current->isDebugObject() : true) && (isSelectable(obj, flag)))
                {
                    // get world to object space transform
                    core::matrix4 worldToObject;
                    if (!current->getAbsoluteTransformation().getInverse(worldToObject))
                        continue;
 
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Selecting a custom node

Post by BillyCallahan »

Thanks man, that's a truly good idea!

However, I'm currently selecting the exact same type of objects...
I can not set a filter :?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Selecting a custom node

Post by hendu »

Look up color picking in that case.
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Selecting a custom node

Post by BillyCallahan »

There's a lack of precision with this method, because many objects have the same texture.

I know I'm a pain in the ***...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Selecting a custom node

Post by hendu »

You didn't understand it. You don't use the object's own textures. You assign a different color to each just for the picking.
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Selecting a custom node

Post by BillyCallahan »

Ya sorry, I don't get it.
If I set the object's color, what's the difference with the texture ?
I want all my objects to have the same texture/color...
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Selecting a custom node

Post by Seven »

or select all of the objects in a line, insert them into a list as the line travels through their bounding boxes, and then choose the one that most likely is the one you want. Maybe based on center of the node distance to the camera instead of the bounding box edge distance to the camera.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Selecting a custom node

Post by Seven »

another option, have two scenemanagers.

smgr1 houses all of the actual nodes with huge bounding boxes.
simultaneously, smgr2 houses small cubenodes that are in the same position as the 'real' nodes.
make the ID the same for the matching large / small nodes.
now, do you picking with smgr2 to get the smaller node, then find the larger node with the same id......

smgr1->addSomeSceneNode(ID, position, rotation, scale, other params);
smgr2->addCubeSceneNode(ID, position, rotation, vector3df(20,20,20));

ISceneNode* smallNode = smgr2->pick the node (it only searched though smgr2 nodes)
ISceneNode* largeNode = smgr1->getRoot()->getChild(smallNode->getID());

viola!
BillyCallahan
Posts: 26
Joined: Fri Jun 19, 2015 6:51 am

Re: Selecting a custom node

Post by BillyCallahan »

Hola,

I solved the problem by calculating the vector 'ray', with the node coordinates I can check if the ray goes through the node or not.
If not, I just set the mask to ignore my first node, etc...

Thank you for the ideas,
Billy :)
Post Reply