Page 1 of 1

Simple Way to Selecte Nodes Frome the Screen.

Posted: Tue Apr 30, 2013 10:11 am
by vivekSivamRP
We always prefer Colision manager class which uses either Bounding Box or Ray castin methods to detects nodes touched from screen. But this fails in accuracy in some cases. Below i made some simple steps

1) Set Unique Colors for each node in the scene

for( i = 0; i< total_Nodes; i++){
nodes->Color = vector3df( i / 255.0 ); // Color Uniforms for each nodes
nodes->setMaterialType(ShaderMaterial); // Shaders for each nodes
}
smgr->drawAll() // draw it once

2) Take Screen Shot every time user touches/clicks on Screen

Iimage Image = driver->createScreenShot();

3) Get Pixel Color of touched/Clicked Position in screen

SColorf PixelColor = image->getPixel( Mouse.X , Mouse.Y);

4) Find match for PixelColor from ur Nodes

if( PixelColor == nodes->Color)
SelectedNode = nodes;

It works well with good accuracy and performance. Don't Forget to Drop the Image atlast.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Thu May 02, 2013 2:59 pm
by zerochen

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Fri May 03, 2013 6:04 am
by vivekSivamRP
This getSceneNodeFromScreenCoordinatesBB() function fails in many cases, because it always use Bounding Box to select a node in screen.

ex :
1) We can't select a Man standing behind/under a Tree.This always picks up the Tree even u click on Man . Because the Bounding Box of tree Covers Man's Bounding Box.

not works accurately.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Fri May 03, 2013 7:00 am
by greenya
vivekSivamRP wrote:We can't select a Man standing behind/under a Tree.This always picks up the Tree even u click on Man . Because the Bounding Box of tree Covers Man's Bounding Box.
I believe idBitMask argument was invented specially for this kind of cases.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Fri May 03, 2013 12:25 pm
by vivekSivamRP
ya you are right , but bitMaskiD works until both Man and Tree have different bitmask.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Fri May 03, 2013 12:46 pm
by hybrid
I think you misunderstood or misspelled here. The two should have different bitmasks, so you can choose which type of scene node should be returned. Make sure that you use a real bitmask and not just some id number scheme here.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Fri May 03, 2013 2:28 pm
by greenya
vivekSivamRP wrote:ya you are right , but bitMaskiD works until both Man and Tree have different bitmask.
In the small game which i showed here http://irrlicht.sourceforge.net/forum/v ... 83#p279792 i made next way:
Every cell has id = 0x10000 + index, every flag and bomb has id 0. Next code shows my mouse click processing:

Code: Select all

        public void MouseClick(int x, int y, bool isRight)
        {
            if (m_state != State.Playing)
                return;
 
            Vector2Di m = new Vector2Di(x, y);
            Line3Df l = m_device.SceneManager.SceneCollisionManager.GetRayFromScreenCoordinates(m);
            SceneNode n = m_device.SceneManager.SceneCollisionManager.GetSceneNodeFromRayBB(l, 0x10000, m_root);
 
            if (n != null && n.ID >= 0x10000)
            {
                int i = n.ID - 0x10000;
 
                if (isRight)
                    flagCell(m_board[i]);
                else
                    revealCell(m_board[i]);
            }
        }
So in short without complexity: set id to 0 to all nodes that must not be pickable and set id to 1 if you want the node to be pickable. When calling GetSceneNodeFromRayBB() pass 1 as idBitMask.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 1:31 am
by Abraxas)
I'm curious, why are you using hex numbers? Is that something you learn when you study programming? Is there an advantage over using decimals?

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 1:52 am
by greenya
In this particular case where i'm using single group (which is 0x10000) it doesn't matter. I could just make non-zero value for all selectable and zero for non-selectable. But if say i need ability to select sometimes only cells, sometimes only flags and sometimes only bombs and all these models arranged together in the scene; then i can assign group of cells (0x10000), group of flags (0x20000) and group of bombs (0x40000) and so on, each group has small distinction - all its members has one special bit set. This way i simply pass that bit (of the group i would like to select ONLY) as idBitMask and it will filter stuff for me automatically.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 3:03 am
by Abraxas)
How is that different from assigning one group to 1000-1999, one from 2000-2999 and so on?

I'm trying to ask why hex is particularly useful in this case.

Thanks!

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 3:11 am
by mongoose7
It's a *mask*. For example, 63 turns on all bits, which is not obvious for larger numbers. When written in hex (a shorthand for binary, the basis of computers) it becomes obvious - 0x3f = 00111111b.

Your range of 1000-1999 turns on random bits. If you use decimal you need ranges like 1024-2047. These ranges are not intuitive, whereas the hex (binary) is quite obvious.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 7:38 am
by vivekSivamRP
hybrid wrote: The two should have different bitmasks, so you can choose which type of scene node should be returned.
I understood difference b/w id and bitmask. Lets see the case in my project.

There is 2 Objects, both comes under same bitmask. And Object_2 is located within the Bounding box of Object_1, but not hidden.

You are supposed to select these two Objects whenever you need them. In this case getSceneNodeFromScreenCoordinatesBB() always selects node which has large Bounding box. if the two have different bitmasks it works, but not for this case.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 8:55 am
by hybrid
Yeah, that's why you can do several tests with alternating bitmasks. Of yourse you have to choose the bitmasks properly.

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 9:23 am
by codetiger
Hi everyone,
Me and VivekSivamRP, are both working on an app where user can select any object in the scene, and move/rotate/scale the object. The objects are totally irrelevant to each other, and user can import obj files. So object of any size can be added. Consider our app like a generic 3D level Editor.

Now bounding box is not an option for us, and we cannot use bit mask. On the other side, we were not able to use ray tracing because we have hardware skinned meshes. So we decided to use the method Vivek has explained in the first post. :)

Re: Simple Way to Selecte Nodes Frome the Screen.

Posted: Sat May 04, 2013 3:23 pm
by Abraxas)
Thanks for the info about BitMasks.

Personally, I always used multiple Meta Triangle Selectors with GetCollisionPoint(), while not the fastest way to do collisions, showed no measurable difference in performance and allowed me to be very precise about things like collisions and torques.

It would be nice if the BB functions could have a triangleselector field that would act like a bitmask too!