Page 1 of 1

Selecting a custom node

Posted: Thu Jul 02, 2015 12:24 pm
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 :)

Re: Selecting a custom node

Posted: Thu Jul 02, 2015 10:59 pm
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.

Re: Selecting a custom node

Posted: Thu Jul 02, 2015 11:04 pm
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;
 

Re: Selecting a custom node

Posted: Fri Jul 03, 2015 7:25 am
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 :?

Re: Selecting a custom node

Posted: Fri Jul 03, 2015 7:40 am
by hendu
Look up color picking in that case.

Re: Selecting a custom node

Posted: Fri Jul 03, 2015 7:52 am
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 ***...

Re: Selecting a custom node

Posted: Fri Jul 03, 2015 9:08 am
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.

Re: Selecting a custom node

Posted: Fri Jul 03, 2015 9:21 am
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...

Re: Selecting a custom node

Posted: Fri Jul 03, 2015 3:34 pm
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.

Re: Selecting a custom node

Posted: Fri Jul 03, 2015 3:39 pm
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!

Re: Selecting a custom node

Posted: Tue Jul 07, 2015 12:47 pm
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 :)