Simple Way to Selecte Nodes Frome the Screen.

A forum to store posts deemed exceptionally wise and useful
Post Reply
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Simple Way to Selecte Nodes Frome the Screen.

Post 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.
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Simple Way to Selecte Nodes Frome the Screen.

Post by zerochen »

vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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.
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Re: Simple Way to Selecte Nodes Frome the Screen.

Post by vivekSivamRP »

ya you are right , but bitMaskiD works until both Man and Tree have different bitmask.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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.
Abraxas)
Posts: 227
Joined: Sun Oct 18, 2009 7:24 am

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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.
Abraxas)
Posts: 227
Joined: Sun Oct 18, 2009 7:24 am

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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!
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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.
vivekSivamRP
Posts: 66
Joined: Sat Sep 29, 2012 11:58 am

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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.
Last edited by vivekSivamRP on Sat May 04, 2013 9:02 am, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Simple Way to Selecte Nodes Frome the Screen.

Post by hybrid »

Yeah, that's why you can do several tests with alternating bitmasks. Of yourse you have to choose the bitmasks properly.
codetiger
Posts: 103
Joined: Wed May 02, 2012 9:24 am
Location: Chennai, India
Contact:

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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. :)
IrrNaCl - Irrlicht Port for Google Chrome Native Client - Demo

Iyan 3D - Make your own 3d animation using your iOS Device
Abraxas)
Posts: 227
Joined: Sun Oct 18, 2009 7:24 am

Re: Simple Way to Selecte Nodes Frome the Screen.

Post 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!
Post Reply