Simple Way to Selecte Nodes Frome the Screen.
-
- Posts: 66
- Joined: Sat Sep 29, 2012 11:58 am
Simple Way to Selecte Nodes Frome the Screen.
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.
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.
-
- Posts: 66
- Joined: Sat Sep 29, 2012 11:58 am
Re: Simple Way to Selecte Nodes Frome the Screen.
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.
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.
I believe idBitMask argument was invented specially for this kind of cases.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.
-
- Posts: 66
- Joined: Sat Sep 29, 2012 11:58 am
Re: Simple Way to Selecte Nodes Frome the Screen.
ya you are right , but bitMaskiD works until both Man and Tree have different bitmask.
-
- 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.
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.
In the small game which i showed here http://irrlicht.sourceforge.net/forum/v ... 83#p279792 i made next way:vivekSivamRP wrote:ya you are right , but bitMaskiD works until both Man and Tree have different bitmask.
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]);
}
}
Re: Simple Way to Selecte Nodes Frome the Screen.
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.
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.
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!
I'm trying to ask why hex is particularly useful in this case.
Thanks!
Re: Simple Way to Selecte Nodes Frome the Screen.
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.
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.
-
- Posts: 66
- Joined: Sat Sep 29, 2012 11:58 am
Re: Simple Way to Selecte Nodes Frome the Screen.
I understood difference b/w id and bitmask. Lets see the case in my project.hybrid wrote: The two should have different bitmasks, so you can choose which type of scene node should be returned.
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.
-
- 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.
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.
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.
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
Iyan 3D - Make your own 3d animation using your iOS Device
Re: Simple Way to Selecte Nodes Frome the Screen.
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!
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!